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
|
F = prog.bin
|
||||||
|
|
||||||
# Compiler flags
|
# 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
|
# Source file
|
||||||
SRC = njvm.c
|
SRC = njvm.c
|
||||||
@ -15,9 +17,15 @@ SRC = njvm.c
|
|||||||
# Executable name
|
# Executable name
|
||||||
TARGET = njvm
|
TARGET = njvm
|
||||||
|
|
||||||
|
njvm.o:
|
||||||
|
$(CC) $(CFLAGS) -o njvm.o -c njvm.c
|
||||||
|
|
||||||
|
support.o:
|
||||||
|
$(CC) $(CFLAGS) -o support.o -c support.c
|
||||||
|
|
||||||
# Default target
|
# Default target
|
||||||
all:
|
all: njvm.o support.o
|
||||||
$(CC) $(CFLAGS) -o $(TARGET) $(SRC)
|
$(CC) $(LDFLAGS) -o $(TARGET) njvm.o support.o -lbigint
|
||||||
# Clean up
|
# Clean up
|
||||||
clean:
|
clean:
|
||||||
rm -f $(OBJ) $(TARGET)
|
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 "codeReader.c"
|
||||||
#include "SDA.c"
|
#include "SDA.c"
|
||||||
#include "debugMenu.c"
|
#include "debugMenu.c"
|
||||||
|
#include "bigint.h"
|
||||||
// Debug
|
// Debug
|
||||||
int debug = 0;
|
int debug = 0;
|
||||||
|
|
||||||
@ -28,6 +28,13 @@ unsigned fp;
|
|||||||
|
|
||||||
void version(void) {
|
void version(void) {
|
||||||
printf("Ninja Virtual Machine version %i (compiled %s, %s)\n", 0, __DATE__, __TIME__);
|
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) {
|
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