diff --git a/.gitignore b/.gitignore index 339d536..f5625f9 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ njvm njvm.dSYM njvm.exe njvm2 +test diff --git a/Makefile b/Makefile index 71dc1c1..c61fe07 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ build: gcc -g -Wall -Lbigint/build/lib -o njvm njvm.o support.o -lbigint run: build - ./njvm programs/prog1.bin + ./njvm prog.bin debug: build - ./njvm --debug prog.bin \ No newline at end of file + ./njvm --debug prog.bin diff --git a/Makefile3 b/Makefile3 new file mode 100644 index 0000000..f56f609 --- /dev/null +++ b/Makefile3 @@ -0,0 +1,43 @@ +# Makefile for a simple C program + +# Compiler +CC = gcc + +# program to Run +F = prog.bin + +# Compiler flags +CFLAGS = -g -Wall -Ibigint/build/include + +LDFLAGS = -g -Wall -Lbigint/build/lib + +# Source file +SRC = njvm.c + +# Executable name +TARGET = njvm + +njvm.o: + $(CC) $(CFLAGS) -o njvm.o -c njvm.c + +support.o: + $(CC) $(CFLAGS) -o support.o -c support.c + +# Default target +all: njvm.o support.o + $(CC) $(LDFLAGS) -o $(TARGET) njvm.o support.o -lbigint +# Clean up +clean: + rm -f $(OBJ) $(TARGET) + +debug: all + ./$(TARGET) --debug $(F) + +run: all + ./$(TARGET) $(F) + +nja: ./nja/nja$(V) + ./nja/nja$(V) $(IN) $(OUT) + +njc: ./njc/njc$(V) + ./njc/njc$(V) $(IN) $(OUT) diff --git a/consts.c b/consts.c index e8bd70a..ce16cb4 100644 --- a/consts.c +++ b/consts.c @@ -1,6 +1,6 @@ #ifndef CONSTS #define CONSTS -#define VERSION 6; +#define VERSION 6 #endif /* ifndef CONSTS #define CONSTS diff --git a/debugMenu.c b/debugMenu.c index 037ae1e..e8ef35c 100644 --- a/debugMenu.c +++ b/debugMenu.c @@ -34,10 +34,10 @@ void breakpoint(){ //todo } -void debugMenu(int fp, struct stack stack, int* debug){ +void debugMenu(int fp, struct stack stack, int* debug, int point){ char input[20]; while (true) { - printf("DEBUG: inspect, list, breakpoint, run, step, quit?"); + printf("DEBUG(%i): inspect, list, breakpoint, run, step, quit?",point); fgets(input, 20, stdin); printf("%s",input); if(input[0] == 'i') {inspect(stack,fp);} diff --git a/njvm.c b/njvm.c index 79c7a2c..21ac61b 100644 --- a/njvm.c +++ b/njvm.c @@ -29,13 +29,6 @@ unsigned fp; void version(void) { printf("Ninja Virtual Machine version %i (compiled %s, %s)\n", 0, __DATE__, __TIME__); - bigFromInt(9); - bip.op1 = bip.res; - bigFromInt(10); - bip.op2 = bip.res; - bigAdd(); - bip.op1 = bip.res; - bigPrint(stdout); } void help(void) { @@ -48,7 +41,7 @@ void execute(struct program program) { StackSlot tempSlot; ObjRef tempObj; for (i = 0; i < *program.size; ++i) { - if (debug == 1) debugMenu(fp, stack, &debug); + if (debug == 1) debugMenu(fp, stack, &debug, i); switch (program.program[i] >> 24) { case HALT: if (debug == 1) printf("halt\n"); @@ -148,8 +141,8 @@ void execute(struct program program) { if (debug == 1) printf("ne: %i != %i\n", peek(stack, 2), peek(stack, 1)); bip.op2 = pop(stack).u.objRef; bip.op1 = pop(stack).u.objRef; - if (bigCmp() != 0) push(stack, stackSlotWithObjRef(getIntObj(true))); - else push(stack, stackSlotWithObjRef(getIntObj(false))); + bigFromInt(bigCmp() != 0); + push(stack,stackSlotWithObjRef(bip.res)); break; case EQ: if (debug == 1) printf("eq: %i == %i\n", peek(stack, 2), peek(stack, 1)); @@ -191,6 +184,7 @@ void execute(struct program program) { if (debug == 1) printf("pop: %i\n", peek(stack, 1)); bip.op1 = pop(stack).u.objRef; int b = bigToInt(); + printf("%i , %i",b, false); if (b == false) { i = SIGN_EXTEND(IMMEDIATE(program.program[i])) - 1; if (debug == 1) printf("new i: %i\n", i); diff --git a/njvm.o b/njvm.o index 293f4ac..44becfa 100644 Binary files a/njvm.o and b/njvm.o differ diff --git a/njvm6 b/njvm6 new file mode 100755 index 0000000..319168e Binary files /dev/null and b/njvm6 differ diff --git a/prog.bin b/prog.bin index 9a783d0..666df3c 100644 Binary files a/prog.bin and b/prog.bin differ diff --git a/support.o b/support.o index 83da1f6..b9bac9c 100644 Binary files a/support.o and b/support.o differ diff --git a/test.c b/test.c deleted file mode 100644 index 986bde7..0000000 --- a/test.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include "bigint.h" - -int main(int argc, char *argv[]) -{ - printf("Hallo Welt\n"); - bigFromInt(5); - return 0; -}