Big int works
This commit is contained in:
parent
5039f95153
commit
70dbd0253b
14
Makefile
14
Makefile
@ -7,7 +7,9 @@ CC = gcc
|
||||
F = prog.bin
|
||||
|
||||
# Compiler flags
|
||||
CFLAGS = -I ./bigint/build/include -L ./bigint/build/lib -g -Wall -std=c99 -pedantic
|
||||
CFLAGS = -g -Wall -Ibigint/build/include
|
||||
|
||||
LDFLAGS = -g -Wall -Lbigint/build/lib
|
||||
|
||||
# Source file
|
||||
SRC = njvm.c
|
||||
@ -15,9 +17,15 @@ 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:
|
||||
$(CC) $(CFLAGS) -o $(TARGET) $(SRC)
|
||||
all: njvm.o support.o
|
||||
$(CC) $(LDFLAGS) -o $(TARGET) njvm.o support.o -lbigint
|
||||
# Clean up
|
||||
clean:
|
||||
rm -f $(OBJ) $(TARGET)
|
||||
|
||||
3
compile_flags.txt
Normal file
3
compile_flags.txt
Normal file
@ -0,0 +1,3 @@
|
||||
-Ibigint/build/include
|
||||
-Lbigint/build/lib
|
||||
-lbigint
|
||||
9
njvm.c
9
njvm.c
@ -8,7 +8,7 @@
|
||||
#include "codeReader.c"
|
||||
#include "SDA.c"
|
||||
#include "debugMenu.c"
|
||||
|
||||
#include "bigint.h"
|
||||
// Debug
|
||||
int debug = 0;
|
||||
|
||||
@ -28,6 +28,13 @@ 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) {
|
||||
|
||||
10
objref.c
Normal file
10
objref.c
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef OBJREF
|
||||
#define OBJREF
|
||||
|
||||
typedef struct {
|
||||
unsigned int size;
|
||||
unsigned char data[1];
|
||||
} *ObjRef;
|
||||
|
||||
#endif /* ifndef OBJREF
|
||||
#define OBJREF */
|
||||
27
support.c
Normal file
27
support.c
Normal file
@ -0,0 +1,27 @@
|
||||
#include "support.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "objref.c"
|
||||
|
||||
void fatalError(char *msg){
|
||||
printf("Fatal error: %s\n", msg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void * newPrimObject(int dataSize) {
|
||||
ObjRef bigObjRef;
|
||||
|
||||
bigObjRef = malloc(sizeof(unsigned int) +
|
||||
dataSize * sizeof(unsigned char));
|
||||
if (bigObjRef == NULL) {
|
||||
fatalError("newPrimObject() got no memory");
|
||||
}
|
||||
bigObjRef->size = dataSize;
|
||||
return bigObjRef;
|
||||
}
|
||||
|
||||
void * getPrimObjectDataPointer(void * obj){
|
||||
ObjRef oo = ((ObjRef) (obj));
|
||||
return oo->data;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user