diff --git a/inc/arith.h b/inc/arith.h index 9d4daf5..9dfeb28 100644 --- a/inc/arith.h +++ b/inc/arith.h @@ -33,8 +33,8 @@ do { \ (dest) = (sour); /* access memory once */ \ switch (SEGMASK & (dest)) { \ - case S_POSITIVE: (dest) = 0xFFFF & (dest); break; \ - case S_NEGATIVE: (dest) = 0xFFFF0000 | (dest); break; \ + case S_POSITIVE: (dest) &= 0xFFFF; break; \ + case S_NEGATIVE: (dest) |= (int)0xFFFF0000; break; \ default: \ /* NOLINTNEXTLINE(bugprone-macro-parentheses) */ \ if (GetTypeNumber(dest) != TYPE_FIXP) goto label; \ @@ -46,8 +46,8 @@ do { \ (dest) = (sour); /* access memory once */ \ switch (SEGMASK & (dest)) { \ - case S_POSITIVE: (dest) = 0xFFFF & (dest); break; \ - case S_NEGATIVE: (dest) = 0xFFFF0000 | (dest); break; \ + case S_POSITIVE: (dest) &= 0xFFFF; break; \ + case S_NEGATIVE: (dest) |= (int)0xFFFF0000; break; \ default: \ switch (GetTypeNumber(dest)) { \ case TYPE_FIXP: (dest) = FIXP_VALUE(dest); break; \ @@ -66,9 +66,9 @@ #define ARITH_SWITCH(arg, result) \ do { \ - switch ((int)(arg) & 0xFFFF0000) { \ + switch ((arg) & (int)0xFFFF0000) { \ case 0: (result) = (S_POSITIVE | (int)(arg)); break; \ - case 0xFFFF0000: (result) = (S_NEGATIVE | (0xFFFF & (int)(arg))); break; \ + case (int)0xFFFF0000: (result) = (S_NEGATIVE | (0xFFFF & (arg))); break; \ default: { \ register LispPTR *wordp; \ /* arg is FIXP, call createcell */ \ @@ -106,9 +106,9 @@ #define N_ARITH_SWITCH(arg) \ do { \ - switch ((arg) & 0xFFFF0000) { \ - case 0: return (S_POSITIVE | (arg)); \ - case 0xFFFF0000: return (S_NEGATIVE | (0xFFFF & (arg))); \ + switch ((arg) & (int)0xFFFF0000) { \ + case 0: return (LispPTR) (S_POSITIVE | (arg)); \ + case (int)0xFFFF0000: return (LispPTR)(S_NEGATIVE | (0xFFFF & (arg))); \ default: { \ register LispPTR *fixpp; \ /* arg is FIXP, call createcell */ \ @@ -134,32 +134,4 @@ ERROR_EXIT(tos); \ } while (0) -#define N_ARITH_BODY_1(a, n, op) \ - do { \ - register int arg1; \ - \ - N_GETNUMBER(a, arg1, do_ufn); \ - \ - arg1 = arg1 op n; \ - \ - N_ARITH_SWITCH(arg1); \ - \ - do_ufn: \ - ERROR_EXIT(a); \ - } while (0) - -#define N_ARITH_BODY_1_UNSIGNED(a, n, op) \ - do { \ - register unsigned int arg1; \ - \ - N_GETNUMBER(a, arg1, do_ufn); \ - \ - arg1 = arg1 op n; \ - \ - N_ARITH_SWITCH(arg1); \ - \ - do_ufn: \ - ERROR_EXIT(a); \ - } while (0) - #endif /* ARITH_H */ diff --git a/inc/arith4defs.h b/inc/arith4defs.h index 61fe20d..e532071 100644 --- a/inc/arith4defs.h +++ b/inc/arith4defs.h @@ -1,8 +1,8 @@ #ifndef ARITH4DEFS_H #define ARITH4DEFS_H 1 -int N_OP_times2(int tosm1, int tos); -int N_OP_itimes2(int tosm1, int tos); -int N_OP_quot(int tosm1, int tos); -int N_OP_iquot(int tosm1, int tos); -int N_OP_iremainder(int tosm1, int tos); +LispPTR N_OP_times2(int tosm1, int tos); +LispPTR N_OP_itimes2(int tosm1, int tos); +LispPTR N_OP_quot(int tosm1, int tos); +LispPTR N_OP_iquot(int tosm1, int tos); +LispPTR N_OP_iremainder(int tosm1, int tos); #endif diff --git a/inc/lispemul.h b/inc/lispemul.h index 99835a9..d4b2cd0 100644 --- a/inc/lispemul.h +++ b/inc/lispemul.h @@ -444,20 +444,21 @@ DOSTACKOVERFLOW(argnum,bytenum) if it needs hardreturn-cleanup /* so that it picks up where it left off after the interrupt. */ /* */ /* Call Interface where neg number indicates an error return */ +/* but the function returns a LispPTR and casts back to int */ /* */ /************************************************************************/ #define ERROR_EXIT(tos) \ do { \ - TopOfStack = tos; \ + TopOfStack = (LispPTR)tos; \ Error_Exit = 1; \ - return (-1); \ + return ((LispPTR)-1); \ } while (0) #define TIMER_EXIT(tos) \ do { \ - TopOfStack = tos; \ + TopOfStack = (LispPTR)tos; \ Error_Exit = 1; \ - return (-2); \ + return ((LispPTR)-2); \ } while (0) #define WARN(message, operation) \ diff --git a/src/arith4.c b/src/arith4.c index 730539d..73ac655 100644 --- a/src/arith4.c +++ b/src/arith4.c @@ -43,7 +43,7 @@ */ /**********************************************************************/ -int N_OP_times2(int tosm1, int tos) { +LispPTR N_OP_times2(int tosm1, int tos) { int arg1, arg2; int result; @@ -72,7 +72,7 @@ doufn: } /* end N_OP_times2 */ -int N_OP_itimes2(int tosm1, int tos) { +LispPTR N_OP_itimes2(int tosm1, int tos) { int arg1, arg2; int result; @@ -107,7 +107,7 @@ doufn: */ /**********************************************************************/ -int N_OP_quot(int tosm1, int tos) { +LispPTR N_OP_quot(int tosm1, int tos) { int arg1, arg2; int result; @@ -125,7 +125,7 @@ doufn: } /* end N_OP_quot */ -int N_OP_iquot(int tosm1, int tos) { +LispPTR N_OP_iquot(int tosm1, int tos) { register int arg1, arg2; register int result; @@ -149,7 +149,7 @@ doufn: */ /**********************************************************************/ -int N_OP_iremainder(int tosm1, int tos) { +LispPTR N_OP_iremainder(int tosm1, int tos) { register int arg1, arg2; register int result; diff --git a/src/shift.c b/src/shift.c index 9f3166f..9485851 100644 --- a/src/shift.c +++ b/src/shift.c @@ -32,28 +32,65 @@ N_OP_llsh1 entry LLSH1 OPCODE[0340] return(a << 1) ************************************************************/ -LispPTR N_OP_llsh1(int a) { N_ARITH_BODY_1_UNSIGNED(a, 1, <<); } +LispPTR N_OP_llsh1(int a) { + int arg1; + + N_GETNUMBER(a, arg1, du_ufn); + arg1 <<= 1; + N_ARITH_SWITCH(arg1); + + du_ufn: + ERROR_EXIT(a); +} /************************************************************ N_OP_llsh8 entry LLSH8 OPCODE[0341] return(a << 8) ************************************************************/ -LispPTR N_OP_llsh8(int a) { N_ARITH_BODY_1_UNSIGNED(a, 8, <<); } +LispPTR N_OP_llsh8(int a) { + int arg1; + + N_GETNUMBER(a, arg1, du_ufn); + arg1 <<= 8; + N_ARITH_SWITCH(arg1); + + du_ufn: + ERROR_EXIT(a); +} /************************************************************ N_OP_lrsh1 entry LRSH1 OPCODE[0342] return(a >> 1) ************************************************************/ -LispPTR N_OP_lrsh1(int a) { N_ARITH_BODY_1_UNSIGNED(a, 1, >>); } +LispPTR N_OP_lrsh1(int a) { + int arg1; + + N_GETNUMBER(a, arg1, du_ufn); + arg1 = (unsigned)arg1 >> 1; + N_ARITH_SWITCH(arg1); + + du_ufn: + ERROR_EXIT(a); + +} /************************************************************ N_OP_lrsh8 entry LRSH8 OPCODE[0343] return(a >> 8) ************************************************************/ -LispPTR N_OP_lrsh8(int a) { N_ARITH_BODY_1_UNSIGNED(a, 8, >>); } +LispPTR N_OP_lrsh8(int a) { + int arg1; + + N_GETNUMBER(a, arg1, du_ufn); + arg1 = (unsigned)arg1 >> 8; + N_ARITH_SWITCH(arg1); + + du_ufn: + ERROR_EXIT(a); +} /************************************************************ N_OP_lsh