More integer operations
This commit is contained in:
parent
dcbbd4b1c1
commit
02092b15f3
7
Makefile
7
Makefile
|
@ -2,7 +2,8 @@ OBJS=abCalc.o abCalcExpr.o abCalcExpReal.o abCalcExprInt.o abCalcStack.o \
|
|||
abCalcMode.o abCalcMain.o abCalcOp.o abCalcError.o abCalcOpAdd.o \
|
||||
abCalcOpSubtr.o abCalcOpMult.o abCalcOpDiv.o abCalcOpPower.o \
|
||||
abCalcOpAnd.o abCalcOpOr.o abCalcOpXor.o abCalcOpNot.o \
|
||||
abCalcOpBin.o abCalcOpOct.o abCalcOpDec.o abCalcOpHex.o
|
||||
abCalcOpBin.o abCalcOpOct.o abCalcOpDec.o abCalcOpHex.o abCalcOpStws.o \
|
||||
abCalcOpRcws.o
|
||||
|
||||
NAME=abCalc
|
||||
|
||||
|
@ -20,7 +21,7 @@ abCalcMain.o: abCalc.h abCalcStack.h abCalcExpr.h abCalcOp.h abCalcError.h
|
|||
abCalcOp.o: abCalcOp.h abCalcError.h abCalcExpr.h abCalcStack.h abCalcOpAdd.h \
|
||||
abCalcOpSubtr.h abCalcOpMult.h abCalcOpDiv.h abCalcOpPower.h \
|
||||
abCalcOpAnd.h abCalcOpOr.h abCalcOpXor.h abCalcOpNot.h abCalcOpBin.h \
|
||||
abCalcOpOct.h abCalcOpDec.h abCalcOpHex.h
|
||||
abCalcOpOct.h abCalcOpDec.h abCalcOpHex.h abCalcOpStws.h abCalcOpRcws.h
|
||||
abCalcOpAdd.o: abCalcOp.h abCalcError.h abCalcExpr.h abCalcStack.h abCalcOpAdd.h
|
||||
abCalcOpSubtr.o: abCalcOp.h abCalcError.h abCalcExpr.h abCalcStack.h abCalcOpSubtr.h
|
||||
abCalcOpMult.o: abCalcOp.h abCalcError.h abCalcExpr.h abCalcStack.h abCalcOpMult.h
|
||||
|
@ -34,6 +35,8 @@ abCalcOpBin.o: abCalcOp.h abCalcMode.h abCalcOpBin.h
|
|||
abCalcOpOct.o: abCalcOp.h abCalcMode.h abCalcOpOct.h
|
||||
abCalcOpDec.o: abCalcOp.h abCalcMode.h abCalcOpDec.h
|
||||
abCalcOpHex.o: abCalcOp.h abCalcMode.h abCalcOpHex.h
|
||||
abCalcOpStws.o: abCalcOp.h abCalcMode.h abCalcStack.h abCalcExpr.h abCalcError.h abCalcOpStws.h
|
||||
abCalcOpRcws.o: abCalcOp.h abCalcMode.h abCalcStack.h abCalcExpr.h abCalcOpRcws.h
|
||||
|
||||
|
||||
$(NAME): $(OBJS)
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
#include "abCalcOpOct.h"
|
||||
#include "abCalcOpDec.h"
|
||||
#include "abCalcOpHex.h"
|
||||
#include "abCalcOpStws.h"
|
||||
#include "abCalcOpRcws.h"
|
||||
|
||||
|
||||
#define AB_CALC_MAX_OPS 128
|
||||
|
@ -55,6 +57,8 @@ void abCalcOpInit(void)
|
|||
abCalcOpOctInit();
|
||||
abCalcOpDecInit();
|
||||
abCalcOpHexInit();
|
||||
abCalcOpStwsInit();
|
||||
abCalcOpRcwsInit();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
abCalcOpRcws.c
|
||||
By: Jeremy Rand
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "abCalcOpRcws.h"
|
||||
|
||||
#include "abCalcOp.h"
|
||||
#include "abCalcExpr.h"
|
||||
#include "abCalcStack.h"
|
||||
#include "abCalcMode.h"
|
||||
|
||||
|
||||
#define OP_NAME "RCWS"
|
||||
|
||||
|
||||
static void rcwsExecute(void);
|
||||
|
||||
|
||||
void abCalcOpRcwsInit(void)
|
||||
{
|
||||
abCalcOpRegister(OP_NAME, rcwsExecute);
|
||||
}
|
||||
|
||||
|
||||
void rcwsExecute(void)
|
||||
{
|
||||
abCalcExpr result;
|
||||
|
||||
result.type = abCalcExprTypeReal;
|
||||
result.u.real = abCalcModeGetIntWidth();
|
||||
|
||||
abCalcStackExprPush(&result);
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
abCalcOpRcws.h
|
||||
By: Jeremy Rand
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ABCALCOPRCWS_H
|
||||
#define ABCALCOPRCWS_H
|
||||
|
||||
|
||||
void abCalcOpRcwsInit(void);
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
abCalcOpStws.c
|
||||
By: Jeremy Rand
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "abCalcOpStws.h"
|
||||
|
||||
#include "abCalcOp.h"
|
||||
#include "abCalcExpr.h"
|
||||
#include "abCalcError.h"
|
||||
#include "abCalcStack.h"
|
||||
#include "abCalcMode.h"
|
||||
|
||||
|
||||
#define OP_NAME "STWS"
|
||||
|
||||
|
||||
static void stwsExecute(void);
|
||||
|
||||
|
||||
void abCalcOpStwsInit(void)
|
||||
{
|
||||
abCalcOpRegister(OP_NAME, stwsExecute);
|
||||
}
|
||||
|
||||
|
||||
void stwsExecute(void)
|
||||
{
|
||||
int newWidth;
|
||||
AB_CALC_OP_ONE_ARG(OP_NAME);
|
||||
|
||||
if (expr->type != abCalcExprTypeReal) {
|
||||
abCalcRaiseError(abCalcBadArgTypeError, OP_NAME);
|
||||
return;
|
||||
}
|
||||
|
||||
newWidth = (int)expr->u.real;
|
||||
if ((newWidth < 1) ||
|
||||
(newWidth > AB_CALC_EXPR_MAX_INT_WIDTH)) {
|
||||
abCalcRaiseError(abCalcBadArgValueError, OP_NAME);
|
||||
return;
|
||||
}
|
||||
|
||||
abCalcModeSetIntWidth(newWidth);
|
||||
abCalcStackExprPop(NULL);
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
abCalcOpStws.h
|
||||
By: Jeremy Rand
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ABCALCOPSTWS_H
|
||||
#define ABCALCOPSTWS_H
|
||||
|
||||
|
||||
void abCalcOpStwsInit(void);
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue