Big int works

This commit is contained in:
nils polek 2024-01-18 17:17:07 +00:00
parent 5039f95153
commit 70dbd0253b
9 changed files with 68 additions and 4 deletions

View File

@ -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)

BIN
a.out Executable file

Binary file not shown.

3
compile_flags.txt Normal file
View File

@ -0,0 +1,3 @@
-Ibigint/build/include
-Lbigint/build/lib
-lbigint

9
njvm.c
View File

@ -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) {

BIN
njvm.o Normal file

Binary file not shown.

10
objref.c Normal file
View 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
View 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;
}

BIN
support.o Normal file

Binary file not shown.

9
test.c Normal file
View File

@ -0,0 +1,9 @@
#include <stdio.h>
#include "bigint.h"
int main(int argc, char *argv[])
{
printf("Hallo Welt\n");
bigFromInt(5);
return 0;
}