1
0
mirror of https://github.com/Interlisp/maiko.git synced 2026-01-19 01:17:36 +00:00

some cleanups in the arithmetic operations code (#427)

* arithmetic opcode implementations should return LispPTR rather than int

* all callers of ERROR_EXIT() have return type LispPTR, therefore ERROR_EXIT should too

* N_[I]GETNUMBER, [N_]ARITH_SWITCH need (int) casts for some large constants that would otherwise be unsigned

* Expand use of macro N_ARITH_BODY_1_UNSIGNED and correct types

* Remove unused macros N_ARITH_BODY_1 and N_ARITH_BODY_1_UNSIGNED

* Cast to correct type for storing to TopOfStack, and return type of TIMER_EXIT()
This commit is contained in:
Nick Briggs 2022-07-20 10:28:21 -07:00 committed by GitHub
parent 77957d421a
commit 9a10f63fe6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 65 additions and 55 deletions

View File

@ -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 */

View File

@ -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

View File

@ -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) \

View File

@ -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;

View File

@ -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