diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..622cd64 Binary files /dev/null and b/.DS_Store differ diff --git a/Make.engine b/Make.engine index 9087324..c600a78 100644 --- a/Make.engine +++ b/Make.engine @@ -12,7 +12,7 @@ OPS_OBJS=ops/abCOp.o ops/abCOpAdd.o ops/abCOpSubtr.o ops/abCOpMult.o \ ops/abCOpDiv.o ops/abCOpPower.o ops/abCOpAnd.o ops/abCOpOr.o ops/abCOpXor.o \ ops/abCOpNot.o ops/abCOpBin.o ops/abCOpOct.o ops/abCOpDec.o ops/abCOpHex.o \ ops/abCOpStws.o ops/abCOpRcws.o ops/abCOpSl.o ops/abCOpRl.o ops/abCOpSr.o \ - ops/abCOpRr.o ops/abCOpAsr.o + ops/abCOpRr.o ops/abCOpAsr.o ops/abCOpInv.o ops/abCOpChs.o ops/abCOpDrop.o SHELL_OBJS=abCMain.o $(CALC_OBJS) $(EXPR_OBJS) $(OPS_OBJS) @@ -20,7 +20,7 @@ NDA_OBJS=abCalcNDA.o $(CALC_OBJS) $(EXPR_OBJS) $(OPS_OBJS) NDA_RES=abCalcNDA.r abCMain.o: abCalc.h abCStack.h expr/abCExpr.h ops/abCOp.h abCError.h -abCalcNDA.o: abCalcNDA.defs abCalc.h +abCalcNDA.o: abCalcNDA.defs abCalc.h abCStack.h abCError.h expr/abCExpr.h ops/abCOp.h abCalcNDA.r: abCalcNDA.defs abCalc.o: abCalc.h expr/abCExpr.h abCMode.h expr/abCExpReal.h expr/abCExprInt.h \ @@ -58,4 +58,7 @@ ops/abCOpRl.o: ops/abCOp.h abCMode.h abCError.h abCStack.h expr/abCExpr.h expr/a ops/abCOpSr.o: ops/abCOp.h abCError.h abCStack.h expr/abCExpr.h expr/abCExprInt.h ops/abCOpSr.h ops/abCOpRr.o: ops/abCOp.h abCMode.h abCError.h abCStack.h expr/abCExpr.h expr/abCExprInt.h ops/abCOpRr.h ops/abCOpAsr.o: ops/abCOp.h abCMode.h abCError.h abCStack.h expr/abCExpr.h expr/abCExprInt.h ops/abCOpAsr.h +ops/abCOpInv.o: ops/abCOp.h abCError.h abCStack.h expr/abCExpr.h expr/abCExpReal.h ops/abCOpInv.h +ops/abCOpChs.o: ops/abCOp.h abCError.h abCStack.h expr/abCExpr.h expr/abCExpReal.h ops/abCOpChs.h +ops/abCOpDrop.o: ops/abCOp.h abCError.h abCStack.h expr/abCExpr.h ops/abCOpDrop.h diff --git a/abCError.c b/abCError.c index f45b248..35b5f21 100644 --- a/abCError.c +++ b/abCError.c @@ -15,7 +15,7 @@ static char *gErrorStrings[abCalcErrorTypeMax]; static abCalcErrorType gCurrErrorType = abCalcNoError; static char *gCurrErrorOpName = NULL; -static char gErrorBuffer[128]; +char gErrorBuffer[128]; void abCalcErrorInit(void) diff --git a/abCStack.c b/abCStack.c index 197d7a9..619b60d 100644 --- a/abCStack.c +++ b/abCStack.c @@ -4,6 +4,7 @@ */ +#include #include #include @@ -11,10 +12,7 @@ #include "abCError.h" -#define AB_CALC_STACK_DEPTH 128 - - -static abCalcExpr gStack[AB_CALC_STACK_DEPTH]; +abCalcExpr gStack[AB_CALC_STACK_DEPTH]; static int gStackNumItems = 0; @@ -75,3 +73,21 @@ abCalcExpr *abCalcStackExprAt(int depth) return result; } + + +char *abCalcStackExprStringAt(int depth, char *buffer) +{ + static char tmpBuffer[AB_CALC_EXPR_STRING_MAX]; + + if (buffer == NULL) + return NULL; + + sprintf(buffer, "%3d: ", depth + 1); + if (depth < gStackNumItems) { + if (abCalcFormatExpr(&(gStack[gStackNumItems - 1 - depth]), tmpBuffer) != NULL) { + strcat(buffer, tmpBuffer); + } + } + + return buffer; +} diff --git a/abCStack.h b/abCStack.h index b7afa0a..080aeb1 100644 --- a/abCStack.h +++ b/abCStack.h @@ -11,6 +11,9 @@ #include "expr/abCExpr.h" +#define AB_CALC_STACK_DEPTH 128 + + void abCalcStackInit(void); abCalcExpr *abCalcStackExprPush(abCalcExpr *expr); @@ -19,6 +22,8 @@ abCalcExpr *abCalcStackExprPop(abCalcExpr *expr); abCalcExpr *abCalcStackExprAt(int depth); +char *abCalcStackExprStringAt(int depth, char *buffer); + int abCalcStackNumItems(void); diff --git a/abCalcNDA.c b/abCalcNDA.c index 3e483db..0ae9ce4 100644 --- a/abCalcNDA.c +++ b/abCalcNDA.c @@ -5,6 +5,7 @@ #pragma nda NDAOpen NDAClose NDAAction NDAInit 0 0xFFFF " abCalc\\H**" +#pragma stacksize 4096 #include @@ -17,23 +18,62 @@ #include #include #include +#include + +#include +#include #include "abCalcNDA.defs" #include "abCalc.h" +#include "abCStack.h" +#include "abCError.h" + +#include "expr/abCExpr.h" + +#include "ops/abCOp.h" + + +void UpdateStack(Boolean draw); + + +typedef struct listElement { + char *memPtr; + Byte memFlag; +} listElement; static BOOLEAN gCalcActive = FALSE; static GrafPortPtr gCalcWinPtr = NULL; static unsigned int gUserId; static unsigned int gResourceId; +listElement *gOpList = NULL; +listElement gStackList[AB_CALC_STACK_DEPTH]; +abCalcExpr gNDAExpr; void NDAClose(void) { + int i; + int numOps; + if (gCalcActive) { CloseWindow(gCalcWinPtr); gCalcWinPtr = NULL; gCalcActive = FALSE; + + numOps = abCalcOpNumOps(); + for (i = 0; i < numOps; i++) { + free(gOpList[i].memPtr); + } + free(gOpList); + gOpList = NULL; + + for (i = 0; i < AB_CALC_STACK_DEPTH; i++) { + if (gStackList[i].memPtr != NULL) { + free(gStackList[i].memPtr); + gStackList[i].memPtr = NULL; + } + } } CloseResourceFile(gResourceId); ResourceShutDown(); @@ -42,10 +82,16 @@ void NDAClose(void) void NDAInit(int code) { + int i; + if (code) { gCalcActive = FALSE; gUserId = MMStartUp(); abCalcInit(); + + for (i = 0; i < AB_CALC_STACK_DEPTH; i++) { + gStackList[i].memPtr = NULL; + } } else if (gCalcActive) { NDAClose(); } @@ -69,6 +115,9 @@ GrafPortPtr NDAOpen(void) unsigned int oldLevel; SysPrefsRecGS prefsDCB; unsigned int oldPrefs; + int numOps; + int i; + Handle opListCtl; if (gCalcActive) return NULL; @@ -98,6 +147,19 @@ GrafPortPtr NDAOpen(void) ShowWindow(gCalcWinPtr); SelectWindow(gCalcWinPtr); + if (gOpList == NULL) { + numOps = abCalcOpNumOps(); + gOpList = malloc(sizeof(*gOpList) * numOps); + for (i = 0; i < numOps; i++) { + gOpList[i].memPtr = abCalcOpNth(i)->name; + gOpList[i].memFlag = 0; + } + } + opListCtl = (Handle)GetCtlHandleFromID(gCalcWinPtr, abCalcOpList); + NewList2(NULL, 1, (Ref)gOpList, 0, numOps, opListCtl); + + UpdateStack(FALSE); + gCalcActive = TRUE; prefsDCB.preferences = oldPrefs; @@ -112,6 +174,150 @@ GrafPortPtr NDAOpen(void) } +void UpdateStack(BOOLEAN draw) +{ + Handle stackListCtl; + int i; + int numOnStack = abCalcStackNumItems(); + int numToDisplay = numOnStack; + + if (numToDisplay < 4) { + numToDisplay = 4; + } + + stackListCtl = (Handle)GetCtlHandleFromID(gCalcWinPtr, abCalcStackList); + + for (i = numToDisplay - 1; i >= 0; i--) { + if (gStackList[i].memPtr == NULL) { + gStackList[i].memPtr = malloc(AB_CALC_EXPR_STRING_MAX + 8); + } + abCalcStackExprStringAt(i, gStackList[i].memPtr); + gStackList[i].memFlag = 0; + } + + NewList2(NULL, 1, (Ref)gStackList, 0, numToDisplay, stackListCtl); + + if (draw) + DrawMember2(0, stackListCtl); +} + + +void DoCalcStuff(char *cmd) +{ + abCalcOp *op = abCalcOpLookup(cmd); + + if (op != NULL) { + op->execute(); + } else if (abCalcParseExpr(&gNDAExpr, cmd) != NULL) { + abCalcStackExprPush(&gNDAExpr); + } else { + abCalcRaiseError(abCalcSyntaxError, NULL); + } + + UpdateStack(TRUE); +} + + +void HandleControl(EventRecord *event) +{ + static Str255 strBuf; + CtlRecHndl entryBox = GetCtlHandleFromID(gCalcWinPtr, abCalcEntryBox); + + switch (event->wmTaskData4) { + case abCalcBtn0: + break; + + case abCalcBtn1: + break; + + case abCalcBtn2: + break; + + case abCalcBtn3: + break; + + case abCalcBtn4: + break; + + case abCalcBtn5: + break; + + case abCalcBtn6: + break; + + case abCalcBtn7: + break; + + case abCalcBtn8: + break; + + case abCalcBtn9: + break; + + case abCalcBtnEnter: + GetLETextByID(gCalcWinPtr, abCalcEntryBox, &strBuf); + strBuf.text[strBuf.textLength] = '\0'; + DoCalcStuff(strBuf.text); + strBuf.textLength = 0; + SetLETextByID(gCalcWinPtr, abCalcEntryBox, &strBuf); + break; + + case abCalcBtnDot: + break; + + case abCalcBtnNum: + break; + + case abCalcBtnAdd: + DoCalcStuff("+"); + break; + + case abCalcBtnSub: + DoCalcStuff("-"); + break; + + case abCalcBtnMult: + DoCalcStuff("*"); + break; + + case abCalcBtnDiv: + DoCalcStuff("/"); + break; + + case abCalcBtnPow: + DoCalcStuff("^"); + break; + + case abCalcBtnA: + break; + + case abCalcBtnB: + break; + + case abCalcBtnC: + break; + + case abCalcBtnD: + break; + + case abCalcBtnE: + break; + + case abCalcBtnF: + break; + + case abCalcEntryBox: + break; + + case abCalcStackList: + break; + + case abCalcOpList: + break; + } +} + + BOOLEAN NDAAction(EventRecord *sysEvent, int code) { int event; @@ -133,6 +339,7 @@ BOOLEAN NDAAction(EventRecord *sysEvent, int code) break; case wInControl: + HandleControl(&localEvent); break; } } diff --git a/abCalcNDA.rez b/abCalcNDA.rez index 61afb62..f40bd98 100644 --- a/abCalcNDA.rez +++ b/abCalcNDA.rez @@ -218,10 +218,12 @@ resource rControlTemplate (abCalcBtnEnter) { abCalcBtnEnter, {abCalcBtnRow4, abCalcBtnCol0, abCalcBtnRow4+abCalcBtnHeight, abCalcBtnCol2+abCalcBtnWidth}, SimpleButtonControl {{ - $0002, + $0003, $3002, 0, - abCalcBtnEnterStr + abCalcBtnEnterStr, + 0, + {"\n","",0,0} }}; }; resource rPString (abCalcBtnEnterStr, noCrossBank) { "Enter" }; @@ -360,14 +362,14 @@ resource rPString (abCalcBtnFStr, noCrossBank) { "F" }; resource rControlTemplate (abCalcStackList) { abCalcStackList, /* control ID */ - {abCalcBtnSpaceY, abCalcBtnSpaceX, abCalcBtnRow7-abCalcBtnSpaceX, abCalcBtnCol3+abCalcBtnWidth-23}, /* control rect */ + {1, abCalcBtnSpaceX, 41, abCalcWinWidth-abCalcBtnSpaceX}, /* control rect */ ListControl {{ $0000, /* flags */ $1400, /* more flags */ 0, /* refcon */ 0, /* list size */ 4, /* List View */ - $0000, /* List Type */ + $0007, /* List Type */ 0, /* List Start */ 10, /* ListMemHeight */ 5, /* List Mem Size */ @@ -378,14 +380,14 @@ resource rControlTemplate (abCalcStackList) { resource rControlTemplate (abCalcOpList) { abCalcOpList, /* control ID */ - {abCalcBtnSpaceY, abCalcOpCol, abCalcWinHeight-abCalcBtnSpaceY, abCalcWinWidth-abCalcBtnSpaceX-23}, /* control rect */ + {abCalcBtnRow7, abCalcOpCol, abCalcWinHeight-8, abCalcWinWidth-abCalcBtnSpaceX}, /* control rect */ ListControl {{ $0000, /* flags */ $1400, /* more flags */ 0, /* refcon */ 0, /* list size */ 4, /* List View */ - $0000, /* List Type */ + $0007, /* List Type */ 0, /* List Start */ 10, /* ListMemHeight */ 5, /* List Mem Size */ @@ -401,7 +403,7 @@ resource rControlTemplate (abCalcEntryBox) { $0000, /* flags */ $7000, /* more flags */ 0, /* refcon */ - 20, /* Max size */ + 34, /* Max size */ 0 /* text Ref */ }}; }; diff --git a/expr/abCExpReal.c b/expr/abCExpReal.c index d6cf157..77d9bc5 100644 --- a/expr/abCExpReal.c +++ b/expr/abCExpReal.c @@ -16,7 +16,7 @@ static abCalcExpr *abCalcExprRealParse(abCalcExpr *expr, char *buffer); static char *abCalcExprRealFormat(abCalcExpr *expr, char *buffer); -static abCalcExprCallbacks gCallbacks = { +static abCalcExprCallbacks gRealCallbacks = { abCalcExprRealParse, abCalcExprRealFormat }; @@ -24,7 +24,7 @@ static abCalcExprCallbacks gCallbacks = { void abCalcExprRealInit(void) { - abCalcRegisterExprType(abCalcExprTypeReal, &gCallbacks); + abCalcRegisterExprType(abCalcExprTypeReal, &gRealCallbacks); } @@ -104,7 +104,7 @@ char *abCalcExprRealFormat(abCalcExpr *expr, char *buffer) { abCalcRealType exp; abCalcRealType value; - char format[16]; + static char format[16]; int numDecDigits; int periodPos = -1; int zerosStart = -1; diff --git a/expr/abCExprInt.c b/expr/abCExprInt.c index c0cadbb..7570138 100644 --- a/expr/abCExprInt.c +++ b/expr/abCExprInt.c @@ -17,7 +17,7 @@ static abCalcExpr *abCalcExprIntParse(abCalcExpr *expr, char *buffer); static char *abCalcExprIntFormat(abCalcExpr *expr, char *buffer); -static abCalcExprCallbacks gCallbacks = { +static abCalcExprCallbacks gIntCallbacks = { abCalcExprIntParse, abCalcExprIntFormat }; @@ -25,7 +25,7 @@ static abCalcExprCallbacks gCallbacks = { void abCalcExprIntInit(void) { - abCalcRegisterExprType(abCalcExprTypeInt, &gCallbacks); + abCalcRegisterExprType(abCalcExprTypeInt, &gIntCallbacks); } diff --git a/ops/abCOp.c b/ops/abCOp.c index 0299dcb..de863f9 100644 --- a/ops/abCOp.c +++ b/ops/abCOp.c @@ -6,6 +6,7 @@ #include #include +#include #include "abCError.h" #include "abCStack.h" @@ -19,6 +20,8 @@ #include "ops/abCOpMult.h" #include "ops/abCOpDiv.h" #include "ops/abCOpPower.h" +#include "ops/abCOpInv.h" +#include "ops/abCOpChs.h" #include "ops/abCOpAnd.h" #include "ops/abCOpOr.h" @@ -41,7 +44,7 @@ #define AB_CALC_MAX_OPS 128 -static abCalcOp gOps[AB_CALC_MAX_OPS]; +abCalcOp gOps[AB_CALC_MAX_OPS]; static int gNumOps = 0; @@ -54,6 +57,10 @@ void abCalcOpInit(void) abCalcOpMultInit(); abCalcOpDivInit(); abCalcOpPowerInit(); + abCalcOpInvInit(); + abCalcOpChsInit(); + + abCalcOpDropInit(); abCalcOpAndInit(); abCalcOpOrInit(); @@ -105,3 +112,17 @@ abCalcOp *abCalcOpLookup(char *name) } +abCalcOp *abCalcOpNth(int n) +{ + if ((n < 0) || + (n >= gNumOps)) + return NULL; + + return &gOps[n]; +} + + +int abCalcOpNumOps(void) +{ + return gNumOps; +} diff --git a/ops/abCOp.h b/ops/abCOp.h index 8396451..e970000 100644 --- a/ops/abCOp.h +++ b/ops/abCOp.h @@ -37,5 +37,8 @@ void abCalcOpRegister(char *name, void (*execute)(void)); abCalcOp *abCalcOpLookup(char *name); +abCalcOp *abCalcOpNth(int n); + +int abCalcOpNumOps(void); #endif diff --git a/ops/abCOpAdd.c b/ops/abCOpAdd.c index 4be5ec7..30469cd 100644 --- a/ops/abCOpAdd.c +++ b/ops/abCOpAdd.c @@ -18,7 +18,7 @@ #include "ops/abCOpAdd.h" -#define OP_NAME "+" +#define ADD_NAME "+" static void addExecute(void); @@ -26,7 +26,7 @@ static void addExecute(void); void abCalcOpAddInit(void) { - abCalcOpRegister(OP_NAME, addExecute); + abCalcOpRegister(ADD_NAME, addExecute); } @@ -35,19 +35,19 @@ void addExecute(void) abCalcExpr result; char expr1Real = 0; char expr2Real = 0; - AB_CALC_OP_TWO_ARGS(OP_NAME); + AB_CALC_OP_TWO_ARGS(ADD_NAME); if (expr1->type == abCalcExprTypeReal) { expr1Real = 1; } else if (expr1->type != abCalcExprTypeInt) { - abCalcRaiseError(abCalcBadArgTypeError, OP_NAME); + abCalcRaiseError(abCalcBadArgTypeError, ADD_NAME); return; } if (expr2->type == abCalcExprTypeReal) { expr2Real = 1; } else if (expr2->type != abCalcExprTypeInt) { - abCalcRaiseError(abCalcBadArgTypeError, OP_NAME); + abCalcRaiseError(abCalcBadArgTypeError, ADD_NAME); return; } diff --git a/ops/abCOpAnd.c b/ops/abCOpAnd.c index f92632a..c4a92c0 100644 --- a/ops/abCOpAnd.c +++ b/ops/abCOpAnd.c @@ -16,7 +16,7 @@ #include "ops/abCOpAnd.h" -#define OP_NAME "AND" +#define AND_NAME "AND" static void andExecute(void); @@ -24,22 +24,22 @@ static void andExecute(void); void abCalcOpAndInit(void) { - abCalcOpRegister(OP_NAME, andExecute); + abCalcOpRegister(AND_NAME, andExecute); } void andExecute(void) { abCalcExpr result; - AB_CALC_OP_TWO_ARGS(OP_NAME); + AB_CALC_OP_TWO_ARGS(AND_NAME); if (expr1->type != abCalcExprTypeInt) { - abCalcRaiseError(abCalcBadArgTypeError, OP_NAME); + abCalcRaiseError(abCalcBadArgTypeError, AND_NAME); return; } if (expr2->type != abCalcExprTypeInt) { - abCalcRaiseError(abCalcBadArgTypeError, OP_NAME); + abCalcRaiseError(abCalcBadArgTypeError, AND_NAME); return; } diff --git a/ops/abCOpAsr.c b/ops/abCOpAsr.c index 736164c..7e961ab 100644 --- a/ops/abCOpAsr.c +++ b/ops/abCOpAsr.c @@ -17,7 +17,7 @@ #include "ops/abCOpAsr.h" -#define OP_NAME "ASR" +#define ASR_NAME "ASR" static void asrExecute(void); @@ -25,7 +25,7 @@ static void asrExecute(void); void abCalcOpAsrInit(void) { - abCalcOpRegister(OP_NAME, asrExecute); + abCalcOpRegister(ASR_NAME, asrExecute); } @@ -34,10 +34,10 @@ void asrExecute(void) abCalcExpr result; int width; abCalcIntType upperBit; - AB_CALC_OP_ONE_ARG(OP_NAME); + AB_CALC_OP_ONE_ARG(ASR_NAME); if (expr->type != abCalcExprTypeInt) { - abCalcRaiseError(abCalcBadArgTypeError, OP_NAME); + abCalcRaiseError(abCalcBadArgTypeError, ASR_NAME); return; } diff --git a/ops/abCOpBin.c b/ops/abCOpBin.c index 142d6e1..073d2b2 100644 --- a/ops/abCOpBin.c +++ b/ops/abCOpBin.c @@ -12,7 +12,7 @@ #include "ops/abCOpBin.h" -#define OP_NAME "BIN" +#define BIN_NAME "BIN" static void binExecute(void); @@ -20,7 +20,7 @@ static void binExecute(void); void abCalcOpBinInit(void) { - abCalcOpRegister(OP_NAME, binExecute); + abCalcOpRegister(BIN_NAME, binExecute); } diff --git a/ops/abCOpChs.c b/ops/abCOpChs.c new file mode 100644 index 0000000..b9ebd11 --- /dev/null +++ b/ops/abCOpChs.c @@ -0,0 +1,46 @@ +/* + abCOpChs.c + By: Jeremy Rand + */ + + +#include +#include + +#include "abCError.h" +#include "abCStack.h" + +#include "expr/abCExpr.h" +#include "expr/abCExpReal.h" + +#include "ops/abCOp.h" +#include "ops/abCOpChs.h" + + +#define CHS_NAME "CHS" + + +static void chsExecute(void); + + +void abCalcOpChsInit(void) +{ + abCalcOpRegister(CHS_NAME, chsExecute); +} + + +void chsExecute(void) +{ + abCalcExpr result; + AB_CALC_OP_ONE_ARG(CHS_NAME); + + if (expr->type != abCalcExprTypeReal) { + abCalcRaiseError(abCalcBadArgTypeError, CHS_NAME); + return; + } + + abCalcExprRealSet(&result, -1.0 * expr->u.real); + + abCalcStackExprPop(NULL); + abCalcStackExprPush(&result); +} diff --git a/ops/abCOpChs.h b/ops/abCOpChs.h new file mode 100644 index 0000000..af58822 --- /dev/null +++ b/ops/abCOpChs.h @@ -0,0 +1,14 @@ +/* + abCOpChs.h + By: Jeremy Rand + */ + + +#ifndef ABCOPCHS_H +#define ABCOPCHS_H + + +void abCalcOpChsInit(void); + + +#endif diff --git a/ops/abCOpDec.c b/ops/abCOpDec.c index 018547d..809e86c 100644 --- a/ops/abCOpDec.c +++ b/ops/abCOpDec.c @@ -12,7 +12,7 @@ #include "ops/abCOpDec.h" -#define OP_NAME "DEC" +#define DEC_NAME "DEC" static void decExecute(void); @@ -20,7 +20,7 @@ static void decExecute(void); void abCalcOpDecInit(void) { - abCalcOpRegister(OP_NAME, decExecute); + abCalcOpRegister(DEC_NAME, decExecute); } diff --git a/ops/abCOpDiv.c b/ops/abCOpDiv.c index f3d1a70..df04601 100644 --- a/ops/abCOpDiv.c +++ b/ops/abCOpDiv.c @@ -17,7 +17,7 @@ #include "ops/abCOpDiv.h" -#define OP_NAME "/" +#define DIV_NAME "/" static void divExecute(void); @@ -25,7 +25,7 @@ static void divExecute(void); void abCalcOpDivInit(void) { - abCalcOpRegister(OP_NAME, divExecute); + abCalcOpRegister(DIV_NAME, divExecute); } @@ -34,28 +34,28 @@ void divExecute(void) abCalcExpr result; char expr1Real = 0; char expr2Real = 0; - AB_CALC_OP_TWO_ARGS(OP_NAME); + AB_CALC_OP_TWO_ARGS(DIV_NAME); if (expr1->type == abCalcExprTypeReal) { expr1Real = 1; if (expr1->u.real == 0.0) { - abCalcRaiseError(abCalcInfiniteResultError, OP_NAME); + abCalcRaiseError(abCalcInfiniteResultError, DIV_NAME); return; } } else if (expr1->type == abCalcExprTypeInt) { if (expr1->u.integer == 0l) { - abCalcRaiseError(abCalcInfiniteResultError, OP_NAME); + abCalcRaiseError(abCalcInfiniteResultError, DIV_NAME); return; } } else { - abCalcRaiseError(abCalcBadArgTypeError, OP_NAME); + abCalcRaiseError(abCalcBadArgTypeError, DIV_NAME); return; } if (expr2->type == abCalcExprTypeReal) { expr2Real = 1; } else if (expr2->type != abCalcExprTypeInt) { - abCalcRaiseError(abCalcBadArgTypeError, OP_NAME); + abCalcRaiseError(abCalcBadArgTypeError, DIV_NAME); return; } diff --git a/ops/abCOpDrop.c b/ops/abCOpDrop.c new file mode 100644 index 0000000..3eb44fa --- /dev/null +++ b/ops/abCOpDrop.c @@ -0,0 +1,36 @@ +/* + abCOpDrop.c + By: Jeremy Rand + */ + + +#include +#include + +#include "abCError.h" +#include "abCStack.h" + +#include "expr/abCExpr.h" + +#include "ops/abCOp.h" +#include "ops/abCOpDrop.h" + + +#define DROP_NAME "DROP" + + +static void dropExecute(void); + + +void abCalcOpDropInit(void) +{ + abCalcOpRegister(DROP_NAME, dropExecute); +} + + +void dropExecute(void) +{ + AB_CALC_OP_ONE_ARG(DROP_NAME); + + abCalcStackExprPop(NULL); +} diff --git a/ops/abCOpDrop.h b/ops/abCOpDrop.h new file mode 100644 index 0000000..b0927c0 --- /dev/null +++ b/ops/abCOpDrop.h @@ -0,0 +1,14 @@ +/* + abCOpDrop.h + By: Jeremy Rand + */ + + +#ifndef ABCOPDROP_H +#define ABCOPDROP_H + + +void abCalcOpDropInit(void); + + +#endif diff --git a/ops/abCOpHex.c b/ops/abCOpHex.c index 9343cb4..12973b0 100644 --- a/ops/abCOpHex.c +++ b/ops/abCOpHex.c @@ -12,7 +12,7 @@ #include "ops/abCOpHex.h" -#define OP_NAME "HEX" +#define HEX_NAME "HEX" static void hexExecute(void); @@ -20,7 +20,7 @@ static void hexExecute(void); void abCalcOpHexInit(void) { - abCalcOpRegister(OP_NAME, hexExecute); + abCalcOpRegister(HEX_NAME, hexExecute); } diff --git a/ops/abCOpInv.c b/ops/abCOpInv.c new file mode 100644 index 0000000..771fd53 --- /dev/null +++ b/ops/abCOpInv.c @@ -0,0 +1,51 @@ +/* + abCOpInv.c + By: Jeremy Rand + */ + + +#include +#include + +#include "abCError.h" +#include "abCStack.h" + +#include "expr/abCExpr.h" +#include "expr/abCExpReal.h" + +#include "ops/abCOp.h" +#include "ops/abCOpInv.h" + + +#define INV_NAME "INV" + + +static void invExecute(void); + + +void abCalcOpInvInit(void) +{ + abCalcOpRegister(INV_NAME, invExecute); +} + + +void invExecute(void) +{ + abCalcExpr result; + AB_CALC_OP_ONE_ARG(INV_NAME); + + if (expr->type != abCalcExprTypeReal) { + abCalcRaiseError(abCalcBadArgTypeError, INV_NAME); + return; + } + + if (expr->u.real == 0.0) { + abCalcRaiseError(abCalcInfiniteResultError, INV_NAME); + return; + } + + abCalcExprRealSet(&result, 1.0 / expr->u.real); + + abCalcStackExprPop(NULL); + abCalcStackExprPush(&result); +} diff --git a/ops/abCOpInv.h b/ops/abCOpInv.h new file mode 100644 index 0000000..eab8c87 --- /dev/null +++ b/ops/abCOpInv.h @@ -0,0 +1,14 @@ +/* + abCOpInv.h + By: Jeremy Rand + */ + + +#ifndef ABCOPINV_H +#define ABCOPINV_H + + +void abCalcOpInvInit(void); + + +#endif diff --git a/ops/abCOpMult.c b/ops/abCOpMult.c index c5729b3..b097188 100644 --- a/ops/abCOpMult.c +++ b/ops/abCOpMult.c @@ -17,7 +17,7 @@ #include "ops/abCOpMult.h" -#define OP_NAME "*" +#define MUL_NAME "*" static void multExecute(void); @@ -25,7 +25,7 @@ static void multExecute(void); void abCalcOpMultInit(void) { - abCalcOpRegister(OP_NAME, multExecute); + abCalcOpRegister(MUL_NAME, multExecute); } @@ -34,19 +34,19 @@ void multExecute(void) abCalcExpr result; char expr1Real = 0; char expr2Real = 0; - AB_CALC_OP_TWO_ARGS(OP_NAME); + AB_CALC_OP_TWO_ARGS(MUL_NAME); if (expr1->type == abCalcExprTypeReal) { expr1Real = 1; } else if (expr1->type != abCalcExprTypeInt) { - abCalcRaiseError(abCalcBadArgTypeError, OP_NAME); + abCalcRaiseError(abCalcBadArgTypeError, MUL_NAME); return; } if (expr2->type == abCalcExprTypeReal) { expr2Real = 1; } else if (expr2->type != abCalcExprTypeInt) { - abCalcRaiseError(abCalcBadArgTypeError, OP_NAME); + abCalcRaiseError(abCalcBadArgTypeError, MUL_NAME); return; } diff --git a/ops/abCOpNot.c b/ops/abCOpNot.c index df0d929..e321fc8 100644 --- a/ops/abCOpNot.c +++ b/ops/abCOpNot.c @@ -16,7 +16,7 @@ #include "ops/abCOpNot.h" -#define OP_NAME "NOT" +#define NOT_NAME "NOT" static void notExecute(void); @@ -24,17 +24,17 @@ static void notExecute(void); void abCalcOpNotInit(void) { - abCalcOpRegister(OP_NAME, notExecute); + abCalcOpRegister(NOT_NAME, notExecute); } void notExecute(void) { abCalcExpr result; - AB_CALC_OP_ONE_ARG(OP_NAME); + AB_CALC_OP_ONE_ARG(NOT_NAME); if (expr->type != abCalcExprTypeInt) { - abCalcRaiseError(abCalcBadArgTypeError, OP_NAME); + abCalcRaiseError(abCalcBadArgTypeError, NOT_NAME); return; } diff --git a/ops/abCOpOct.c b/ops/abCOpOct.c index 475c6b7..1a50f72 100644 --- a/ops/abCOpOct.c +++ b/ops/abCOpOct.c @@ -12,7 +12,7 @@ #include "ops/abCOpOct.h" -#define OP_NAME "OCT" +#define OCT_NAME "OCT" static void octExecute(void); @@ -20,7 +20,7 @@ static void octExecute(void); void abCalcOpOctInit(void) { - abCalcOpRegister(OP_NAME, octExecute); + abCalcOpRegister(OCT_NAME, octExecute); } diff --git a/ops/abCOpOr.c b/ops/abCOpOr.c index 4a413d9..ac2316e 100644 --- a/ops/abCOpOr.c +++ b/ops/abCOpOr.c @@ -16,7 +16,7 @@ #include "ops/abCOpOr.h" -#define OP_NAME "OR" +#define OR_NAME "OR" static void orExecute(void); @@ -24,22 +24,22 @@ static void orExecute(void); void abCalcOpOrInit(void) { - abCalcOpRegister(OP_NAME, orExecute); + abCalcOpRegister(OR_NAME, orExecute); } void orExecute(void) { abCalcExpr result; - AB_CALC_OP_TWO_ARGS(OP_NAME); + AB_CALC_OP_TWO_ARGS(OR_NAME); if (expr1->type != abCalcExprTypeInt) { - abCalcRaiseError(abCalcBadArgTypeError, OP_NAME); + abCalcRaiseError(abCalcBadArgTypeError, OR_NAME); return; } if (expr2->type != abCalcExprTypeInt) { - abCalcRaiseError(abCalcBadArgTypeError, OP_NAME); + abCalcRaiseError(abCalcBadArgTypeError, OR_NAME); return; } diff --git a/ops/abCOpPower.c b/ops/abCOpPower.c index 19f63a6..69f76f8 100644 --- a/ops/abCOpPower.c +++ b/ops/abCOpPower.c @@ -17,7 +17,7 @@ #include "ops/abCOpPower.h" -#define OP_NAME "^" +#define POWER_NAME "^" static void powerExecute(void); @@ -25,7 +25,7 @@ static void powerExecute(void); void abCalcOpPowerInit(void) { - abCalcOpRegister(OP_NAME, powerExecute); + abCalcOpRegister(POWER_NAME, powerExecute); } @@ -33,21 +33,21 @@ void powerExecute(void) { abCalcExpr result; double integral; - AB_CALC_OP_TWO_ARGS(OP_NAME); + AB_CALC_OP_TWO_ARGS(POWER_NAME); if (expr1->type != abCalcExprTypeReal) { - abCalcRaiseError(abCalcBadArgTypeError, OP_NAME); + abCalcRaiseError(abCalcBadArgTypeError, POWER_NAME); return; } if (expr2->type != abCalcExprTypeReal) { - abCalcRaiseError(abCalcBadArgTypeError, OP_NAME); + abCalcRaiseError(abCalcBadArgTypeError, POWER_NAME); return; } if (expr2->u.real == 0.0) { if (expr1->u.real < 0.0) { - abCalcRaiseError(abCalcInfiniteResultError, OP_NAME); + abCalcRaiseError(abCalcInfiniteResultError, POWER_NAME); return; } if (expr1->u.real == 0.0) { @@ -59,7 +59,7 @@ void powerExecute(void) if (expr2->u.real < 0.0) { modf(expr1->u.real, &integral); if (expr1->u.real != integral) { - abCalcRaiseError(abCalcComplexResultError, OP_NAME); + abCalcRaiseError(abCalcComplexResultError, POWER_NAME); return; } } diff --git a/ops/abCOpRcws.c b/ops/abCOpRcws.c index e3d3902..222d9d4 100644 --- a/ops/abCOpRcws.c +++ b/ops/abCOpRcws.c @@ -16,7 +16,7 @@ #include "ops/abCOpRcws.h" -#define OP_NAME "RCWS" +#define RCWS_NAME "RCWS" static void rcwsExecute(void); @@ -24,7 +24,7 @@ static void rcwsExecute(void); void abCalcOpRcwsInit(void) { - abCalcOpRegister(OP_NAME, rcwsExecute); + abCalcOpRegister(RCWS_NAME, rcwsExecute); } diff --git a/ops/abCOpRl.c b/ops/abCOpRl.c index 9a0ac99..a7670b8 100644 --- a/ops/abCOpRl.c +++ b/ops/abCOpRl.c @@ -17,7 +17,7 @@ #include "ops/abCOpRl.h" -#define OP_NAME "RL" +#define RL_NAME "RL" static void rlExecute(void); @@ -25,7 +25,7 @@ static void rlExecute(void); void abCalcOpRlInit(void) { - abCalcOpRegister(OP_NAME, rlExecute); + abCalcOpRegister(RL_NAME, rlExecute); } @@ -34,10 +34,10 @@ void rlExecute(void) abCalcExpr result; int width; int topBit; - AB_CALC_OP_ONE_ARG(OP_NAME); + AB_CALC_OP_ONE_ARG(RL_NAME); if (expr->type != abCalcExprTypeInt) { - abCalcRaiseError(abCalcBadArgTypeError, OP_NAME); + abCalcRaiseError(abCalcBadArgTypeError, RL_NAME); return; } diff --git a/ops/abCOpRr.c b/ops/abCOpRr.c index e8bd541..41cd173 100644 --- a/ops/abCOpRr.c +++ b/ops/abCOpRr.c @@ -17,7 +17,7 @@ #include "ops/abCOpRr.h" -#define OP_NAME "RR" +#define RR_NAME "RR" static void rrExecute(void); @@ -25,7 +25,7 @@ static void rrExecute(void); void abCalcOpRrInit(void) { - abCalcOpRegister(OP_NAME, rrExecute); + abCalcOpRegister(RR_NAME, rrExecute); } @@ -34,10 +34,10 @@ void rrExecute(void) abCalcExpr result; int width; abCalcIntType bottomBit; - AB_CALC_OP_ONE_ARG(OP_NAME); + AB_CALC_OP_ONE_ARG(RR_NAME); if (expr->type != abCalcExprTypeInt) { - abCalcRaiseError(abCalcBadArgTypeError, OP_NAME); + abCalcRaiseError(abCalcBadArgTypeError, RR_NAME); return; } diff --git a/ops/abCOpSl.c b/ops/abCOpSl.c index c78feb3..0834e09 100644 --- a/ops/abCOpSl.c +++ b/ops/abCOpSl.c @@ -16,7 +16,7 @@ #include "ops/abCOpSl.h" -#define OP_NAME "SL" +#define SL_NAME "SL" static void slExecute(void); @@ -24,17 +24,17 @@ static void slExecute(void); void abCalcOpSlInit(void) { - abCalcOpRegister(OP_NAME, slExecute); + abCalcOpRegister(SL_NAME, slExecute); } void slExecute(void) { abCalcExpr result; - AB_CALC_OP_ONE_ARG(OP_NAME); + AB_CALC_OP_ONE_ARG(SL_NAME); if (expr->type != abCalcExprTypeInt) { - abCalcRaiseError(abCalcBadArgTypeError, OP_NAME); + abCalcRaiseError(abCalcBadArgTypeError, SL_NAME); return; } diff --git a/ops/abCOpSr.c b/ops/abCOpSr.c index b132580..b58cfbd 100644 --- a/ops/abCOpSr.c +++ b/ops/abCOpSr.c @@ -16,7 +16,7 @@ #include "ops/abCOpSr.h" -#define OP_NAME "SR" +#define SR_NAME "SR" static void srExecute(void); @@ -24,17 +24,17 @@ static void srExecute(void); void abCalcOpSrInit(void) { - abCalcOpRegister(OP_NAME, srExecute); + abCalcOpRegister(SR_NAME, srExecute); } void srExecute(void) { abCalcExpr result; - AB_CALC_OP_ONE_ARG(OP_NAME); + AB_CALC_OP_ONE_ARG(SR_NAME); if (expr->type != abCalcExprTypeInt) { - abCalcRaiseError(abCalcBadArgTypeError, OP_NAME); + abCalcRaiseError(abCalcBadArgTypeError, SR_NAME); return; } diff --git a/ops/abCOpStws.c b/ops/abCOpStws.c index 6cd3bf1..040f068 100644 --- a/ops/abCOpStws.c +++ b/ops/abCOpStws.c @@ -16,7 +16,7 @@ #include "ops/abCOpStws.h" -#define OP_NAME "STWS" +#define STWS_NAME "STWS" static void stwsExecute(void); @@ -24,24 +24,24 @@ static void stwsExecute(void); void abCalcOpStwsInit(void) { - abCalcOpRegister(OP_NAME, stwsExecute); + abCalcOpRegister(STWS_NAME, stwsExecute); } void stwsExecute(void) { int newWidth; - AB_CALC_OP_ONE_ARG(OP_NAME); + AB_CALC_OP_ONE_ARG(STWS_NAME); if (expr->type != abCalcExprTypeReal) { - abCalcRaiseError(abCalcBadArgTypeError, OP_NAME); + abCalcRaiseError(abCalcBadArgTypeError, STWS_NAME); return; } newWidth = (int)expr->u.real; if ((newWidth < 1) || (newWidth > AB_CALC_EXPR_MAX_INT_WIDTH)) { - abCalcRaiseError(abCalcBadArgValueError, OP_NAME); + abCalcRaiseError(abCalcBadArgValueError, STWS_NAME); return; } diff --git a/ops/abCOpSubtr.c b/ops/abCOpSubtr.c index b4ad8e0..34610b8 100644 --- a/ops/abCOpSubtr.c +++ b/ops/abCOpSubtr.c @@ -17,7 +17,7 @@ #include "ops/abCOpSubtr.h" -#define OP_NAME "-" +#define SUB_NAME "-" static void subtrExecute(void); @@ -25,7 +25,7 @@ static void subtrExecute(void); void abCalcOpSubtrInit(void) { - abCalcOpRegister(OP_NAME, subtrExecute); + abCalcOpRegister(SUB_NAME, subtrExecute); } @@ -34,19 +34,19 @@ void subtrExecute(void) abCalcExpr result; char expr1Real = 0; char expr2Real = 0; - AB_CALC_OP_TWO_ARGS(OP_NAME); + AB_CALC_OP_TWO_ARGS(SUB_NAME); if (expr1->type == abCalcExprTypeReal) { expr1Real = 1; } else if (expr1->type != abCalcExprTypeInt) { - abCalcRaiseError(abCalcBadArgTypeError, OP_NAME); + abCalcRaiseError(abCalcBadArgTypeError, SUB_NAME); return; } if (expr2->type == abCalcExprTypeReal) { expr2Real = 1; } else if (expr2->type != abCalcExprTypeInt) { - abCalcRaiseError(abCalcBadArgTypeError, OP_NAME); + abCalcRaiseError(abCalcBadArgTypeError, SUB_NAME); return; } diff --git a/ops/abCOpXor.c b/ops/abCOpXor.c index 3c6b9b6..412dd26 100644 --- a/ops/abCOpXor.c +++ b/ops/abCOpXor.c @@ -16,7 +16,7 @@ #include "ops/abCOpXor.h" -#define OP_NAME "XOR" +#define XOR_NAME "XOR" static void xorExecute(void); @@ -24,22 +24,22 @@ static void xorExecute(void); void abCalcOpXorInit(void) { - abCalcOpRegister(OP_NAME, xorExecute); + abCalcOpRegister(XOR_NAME, xorExecute); } void xorExecute(void) { abCalcExpr result; - AB_CALC_OP_TWO_ARGS(OP_NAME); + AB_CALC_OP_TWO_ARGS(XOR_NAME); if (expr1->type != abCalcExprTypeInt) { - abCalcRaiseError(abCalcBadArgTypeError, OP_NAME); + abCalcRaiseError(abCalcBadArgTypeError, XOR_NAME); return; } if (expr2->type != abCalcExprTypeInt) { - abCalcRaiseError(abCalcBadArgTypeError, OP_NAME); + abCalcRaiseError(abCalcBadArgTypeError, XOR_NAME); return; }