Revert "update"
This reverts commit dbafdbeea5ec44865047cbcce23d20d0855093ea.
This commit is contained in:
parent
dbafdbeea5
commit
5039f95153
2
Makefile
2
Makefile
@ -7,7 +7,7 @@ CC = gcc
|
|||||||
F = prog.bin
|
F = prog.bin
|
||||||
|
|
||||||
# Compiler flags
|
# Compiler flags
|
||||||
CFLAGS = -I ./bigint -L ./bigint -g -Wall -std=c99 -pedantic -v -lbigint -lm
|
CFLAGS = -I ./bigint/build/include -L ./bigint/build/lib -g -Wall -std=c99 -pedantic
|
||||||
|
|
||||||
# Source file
|
# Source file
|
||||||
SRC = njvm.c
|
SRC = njvm.c
|
||||||
|
|||||||
22
bigint/Makefile
Normal file
22
bigint/Makefile
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#
|
||||||
|
# Makefile for big integer library and test
|
||||||
|
#
|
||||||
|
|
||||||
|
DIRS = src tst
|
||||||
|
|
||||||
|
all:
|
||||||
|
for i in $(DIRS) ; do \
|
||||||
|
$(MAKE) -C $$i install ; \
|
||||||
|
done
|
||||||
|
|
||||||
|
clean:
|
||||||
|
for i in $(DIRS) ; do \
|
||||||
|
$(MAKE) -C $$i clean ; \
|
||||||
|
done
|
||||||
|
rm -rf ./build
|
||||||
|
rm -f *~
|
||||||
|
|
||||||
|
dist: clean
|
||||||
|
(cd .. ; \
|
||||||
|
tar -cvf bigint.tar bigint ; \
|
||||||
|
gzip -f bigint.tar)
|
||||||
BIN
bigint/bigint.o
BIN
bigint/bigint.o
Binary file not shown.
BIN
bigint/build/bin/testbip
Executable file
BIN
bigint/build/bin/testbip
Executable file
Binary file not shown.
BIN
bigint/build/lib/libbigint.a
Normal file
BIN
bigint/build/lib/libbigint.a
Normal file
Binary file not shown.
Binary file not shown.
26
bigint/src/Makefile
Normal file
26
bigint/src/Makefile
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#
|
||||||
|
# Makefile for big integer library
|
||||||
|
#
|
||||||
|
|
||||||
|
BUILD = ../build
|
||||||
|
|
||||||
|
CC = gcc
|
||||||
|
CFLAGS = -g -Wall
|
||||||
|
|
||||||
|
all: support.h bigint.h libbigint.a
|
||||||
|
|
||||||
|
install: all
|
||||||
|
mkdir -p $(BUILD)/include
|
||||||
|
cp support.h $(BUILD)/include
|
||||||
|
cp bigint.h $(BUILD)/include
|
||||||
|
mkdir -p $(BUILD)/lib
|
||||||
|
cp libbigint.a $(BUILD)/lib
|
||||||
|
|
||||||
|
libbigint.a: bigint.o
|
||||||
|
ar -crs libbigint.a bigint.o
|
||||||
|
|
||||||
|
bigint.o: bigint.c bigint.h support.h
|
||||||
|
$(CC) $(CFLAGS) -o bigint.o -c bigint.c
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *~ bigint.o libbigint.a
|
||||||
60
bigint/src/bigint.h
Normal file
60
bigint/src/bigint.h
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* bigint.h -- big integer library
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef _BIGINT_H_
|
||||||
|
#define _BIGINT_H_
|
||||||
|
|
||||||
|
|
||||||
|
/* object representation */
|
||||||
|
typedef void* BigObjRef;
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int nd; /* number of digits; array may be bigger */
|
||||||
|
/* nd = 0 exactly when number = 0 */
|
||||||
|
unsigned char sign; /* one of BIG_NEGATIVE or BIG_POSITIVE */
|
||||||
|
/* zero always has BIG_POSITIVE here */
|
||||||
|
unsigned char digits[1]; /* the digits proper; number base is 256 */
|
||||||
|
/* LS digit first; MS digit is not zero */
|
||||||
|
} Big;
|
||||||
|
|
||||||
|
#include "support.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* big integer processor registers */
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
BigObjRef op1; /* first (or single) operand */
|
||||||
|
BigObjRef op2; /* second operand (if present) */
|
||||||
|
BigObjRef res; /* result of operation */
|
||||||
|
BigObjRef rem; /* remainder in case of division */
|
||||||
|
} BIP;
|
||||||
|
|
||||||
|
extern BIP bip; /* registers of the processor */
|
||||||
|
|
||||||
|
|
||||||
|
/* big integer processor functions */
|
||||||
|
|
||||||
|
int bigSgn(void); /* sign */
|
||||||
|
int bigCmp(void); /* comparison */
|
||||||
|
void bigNeg(void); /* negation */
|
||||||
|
void bigAdd(void); /* addition */
|
||||||
|
void bigSub(void); /* subtraction */
|
||||||
|
void bigMul(void); /* multiplication */
|
||||||
|
void bigDiv(void); /* division */
|
||||||
|
|
||||||
|
void bigFromInt(int n); /* conversion int --> big */
|
||||||
|
int bigToInt(void); /* conversion big --> int */
|
||||||
|
|
||||||
|
void bigRead(FILE *in); /* read a big integer */
|
||||||
|
void bigPrint(FILE *out); /* print a big integer */
|
||||||
|
|
||||||
|
void bigDump(FILE *out, BigObjRef bigObjRef); /* dump a big integer object */
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* _BIGINT_H_ */
|
||||||
BIN
bigint/src/bigint.o
Normal file
BIN
bigint/src/bigint.o
Normal file
Binary file not shown.
BIN
bigint/src/libbigint.a
Normal file
BIN
bigint/src/libbigint.a
Normal file
Binary file not shown.
15
bigint/src/support.h
Normal file
15
bigint/src/support.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
/*
|
||||||
|
* support.h -- object representation and support functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef _SUPPORT_H_
|
||||||
|
#define _SUPPORT_H_
|
||||||
|
|
||||||
|
/* support functions */
|
||||||
|
|
||||||
|
void fatalError(char *msg); /* print a message and exit */
|
||||||
|
void * newPrimObject(int dataSize); /* create a new primitive object */
|
||||||
|
void * getPrimObjectDataPointer(void * primObject);
|
||||||
|
|
||||||
|
#endif /* _SUPPORT_H_ */
|
||||||
28
bigint/tst/Makefile
Normal file
28
bigint/tst/Makefile
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#
|
||||||
|
# Makefile for big integer test
|
||||||
|
#
|
||||||
|
|
||||||
|
BUILD = ../build
|
||||||
|
|
||||||
|
CC = gcc
|
||||||
|
CFLAGS = -g -Wall -I$(BUILD)/include
|
||||||
|
LDFLAGS = -g -Wall -L$(BUILD)/lib
|
||||||
|
LDLIBS = -lbigint
|
||||||
|
|
||||||
|
all: testbip
|
||||||
|
|
||||||
|
install: all
|
||||||
|
mkdir -p $(BUILD)/bin
|
||||||
|
cp testbip $(BUILD)/bin
|
||||||
|
|
||||||
|
testbip: testbip.o support.o
|
||||||
|
$(CC) $(LDFLAGS) -o testbip testbip.o support.o $(LDLIBS)
|
||||||
|
|
||||||
|
testbip.o: testbip.c
|
||||||
|
$(CC) $(CFLAGS) -o testbip.o -c testbip.c
|
||||||
|
|
||||||
|
support.o: support.c
|
||||||
|
$(CC) $(CFLAGS) -o support.o -c support.c
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *~ testbip.o support.o testbip
|
||||||
55
bigint/tst/support.c
Normal file
55
bigint/tst/support.c
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* support.c -- support functions for big integer library
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "support.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
unsigned int size; /* byte count of payload data */
|
||||||
|
unsigned char data[1]; /* payload data, size as needed */
|
||||||
|
} *ObjRef;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This routine is called in case a fatal error has occurred.
|
||||||
|
* It should print the error message and terminate the program.
|
||||||
|
*/
|
||||||
|
void fatalError(char *msg) {
|
||||||
|
printf("Fatal error: %s\n", msg);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This function is called whenever a new primitive object with
|
||||||
|
* a certain amount of internal memory is needed. It should return
|
||||||
|
* an object reference to a regular object, which contains a freely
|
||||||
|
* usable memory area of at least the requested size (measured in
|
||||||
|
* bytes). The memory area need not be initialized in any way.
|
||||||
|
*
|
||||||
|
* Note that this function may move all objects in memory at will
|
||||||
|
* (due to, e.g., garbage collection), as long as the pointers in
|
||||||
|
* the global "bip" structure point to the correct objects when
|
||||||
|
* the function returns.
|
||||||
|
*/
|
||||||
|
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
bigint/tst/support.o
Normal file
BIN
bigint/tst/support.o
Normal file
Binary file not shown.
BIN
bigint/tst/testbip
Executable file
BIN
bigint/tst/testbip
Executable file
Binary file not shown.
1253
bigint/tst/testbip.c
Normal file
1253
bigint/tst/testbip.c
Normal file
File diff suppressed because it is too large
Load Diff
BIN
bigint/tst/testbip.o
Normal file
BIN
bigint/tst/testbip.o
Normal file
Binary file not shown.
5
njvm.c
5
njvm.c
@ -8,8 +8,6 @@
|
|||||||
#include "codeReader.c"
|
#include "codeReader.c"
|
||||||
#include "SDA.c"
|
#include "SDA.c"
|
||||||
#include "debugMenu.c"
|
#include "debugMenu.c"
|
||||||
#include "bigint.h"
|
|
||||||
#include "support.h"
|
|
||||||
|
|
||||||
// Debug
|
// Debug
|
||||||
int debug = 0;
|
int debug = 0;
|
||||||
@ -51,8 +49,7 @@ void execute(struct program program) {
|
|||||||
goto end;
|
goto end;
|
||||||
case PUSHC:
|
case PUSHC:
|
||||||
if (debug == 1) printf("pushc: %i\n", IMMEDIATE(program.program[i]));
|
if (debug == 1) printf("pushc: %i\n", IMMEDIATE(program.program[i]));
|
||||||
bigFromInt(IMMEDIATE(program.program[i]));
|
push(stack, stackSlotWithObjRef(getIntObj(SIGN_EXTEND(IMMEDIATE(program.program[i])))));
|
||||||
push(stack, stackSlotWithObjRef(bip.res));
|
|
||||||
break;
|
break;
|
||||||
case ADD:
|
case ADD:
|
||||||
if (debug == 1) printf("add: %i + %i\n",peek(stack, 2),peek(stack, 1));
|
if (debug == 1) printf("add: %i + %i\n",peek(stack, 2),peek(stack, 1));
|
||||||
|
|||||||
6
stack.c
6
stack.c
@ -44,9 +44,9 @@ ObjRefContainer getRefs(struct stack stack){
|
|||||||
}
|
}
|
||||||
continer.size = counter;
|
continer.size = counter;
|
||||||
ObjRef *list = (ObjRef *)malloc(counter * sizeof(ObjRef));
|
ObjRef *list = (ObjRef *)malloc(counter * sizeof(ObjRef));
|
||||||
for (int j = 0; j<= *stack.current; j++)
|
for (int i = 0; i<= *stack.current; i++)
|
||||||
if(stack.stack[j].isObjRef == true)
|
if(stack.stack[i].isObjRef == true)
|
||||||
list[counter--] = stack.stack[j].u.objRef;
|
list[counter--] = stack.stack[i].u.objRef;
|
||||||
continer.refs = list;
|
continer.refs = list;
|
||||||
return continer;
|
return continer;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user