Compare commits
No commits in common. "38f06b15758f3fca699e34e568dfa4f115b3f762" and "8c45b02769356b9445a32ffe1de43d40638be084" have entirely different histories.
38f06b1575
...
8c45b02769
2
GC.c
2
GC.c
@ -21,7 +21,7 @@ struct sda sda;
|
||||
|
||||
// Stack
|
||||
struct stack stack;
|
||||
#define SIZE 64
|
||||
#define SIZE 100000
|
||||
|
||||
//Register
|
||||
struct stack reg;
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
27
njvm.c
27
njvm.c
@ -229,42 +229,42 @@ void execute(struct program program) {
|
||||
push(stack, stackSlotWithObjRef(tempObj));
|
||||
break;
|
||||
case POPR:
|
||||
if (debug == 1) printf("popr\n");
|
||||
if (debug == 1) printf("popr");
|
||||
push(reg, pop(stack));
|
||||
break;
|
||||
case PUSHR:
|
||||
if (debug == 1) printf("pushr\n");
|
||||
if (debug == 1) printf("pushr");
|
||||
push(stack, pop(reg));
|
||||
break;
|
||||
case NEW:
|
||||
if (debug == 1) printf("new\t%i\n", SIGN_EXTEND(IMMEDIATE(program.program[i])));
|
||||
if (debug == 1) printf("new");
|
||||
push(stack, stackSlotWithObjRef(newRecord(SIGN_EXTEND(IMMEDIATE(program.program[i])))));
|
||||
break;
|
||||
case GETF:
|
||||
if (debug == 1) printf("getf\n");
|
||||
if (debug == 1) printf("getf");
|
||||
tempObj = pop(stack).u.objRef;
|
||||
push(stack, stackSlotWithObjRef(getField(tempObj,SIGN_EXTEND(IMMEDIATE(program.program[i])))));
|
||||
break;
|
||||
case PUTF:
|
||||
if (debug == 1) printf("putf\t%i\n", SIGN_EXTEND(IMMEDIATE(program.program[i])));
|
||||
if (debug == 1) printf("putf");
|
||||
tempObj = pop(stack).u.objRef;
|
||||
tempObj2 = pop(stack).u.objRef;
|
||||
setField(tempObj2, SIGN_EXTEND(IMMEDIATE(program.program[i])),tempObj);
|
||||
break;
|
||||
case NEWA:
|
||||
if(debug == 1) printf("newa\n");
|
||||
if(debug == 1) printf("newa");
|
||||
bip.op1 = pop(stack).u.objRef;
|
||||
push(stack, stackSlotWithObjRef(newRecord(bigToInt())));
|
||||
break;
|
||||
case GETFA:
|
||||
if(debug == 1) printf("getfa\n");
|
||||
if(debug == 1) printf("getfa");
|
||||
bip.op1 = pop(stack).u.objRef;
|
||||
tempInt = bigToInt();
|
||||
tempObj = pop(stack).u.objRef;
|
||||
push(stack, stackSlotWithObjRef(getField(tempObj,bigToInt())));
|
||||
break;
|
||||
case PUTFA:
|
||||
if (debug == 1) printf("putfa\n");
|
||||
if (debug == 1) printf("putfa");
|
||||
tempObj = pop(stack).u.objRef; // Value
|
||||
tempObj2 = pop(stack).u.objRef; // Index
|
||||
bip.op1 = tempObj2;
|
||||
@ -272,24 +272,24 @@ void execute(struct program program) {
|
||||
setField(pop(stack).u.objRef, tempInt,tempObj);
|
||||
break;
|
||||
case GETSZ:
|
||||
if (debug == 1) printf("getsz\n");
|
||||
if (debug == 1) printf("getsz");
|
||||
tempObj = pop(stack).u.objRef;
|
||||
if(IS_PRIMITIVE(tempObj)) bigFromInt(-1);
|
||||
else bigFromInt(GET_ELEMENT_COUNT(tempObj));
|
||||
push(stack, stackSlotWithObjRef(bip.res));
|
||||
break;
|
||||
case PUSHN:
|
||||
if (debug == 1) printf("pushn\n");
|
||||
if (debug == 1) printf("pushn");
|
||||
push(stack, stackSlotWithObjRef(NULL));
|
||||
break;
|
||||
case REFEQ:
|
||||
if (debug == 1) printf("refeq\n");
|
||||
if (debug == 1) printf("refeq");
|
||||
if(pop(stack).u.objRef == pop(stack).u.objRef) bigFromInt(true);
|
||||
else bigFromInt(false);
|
||||
push(stack, stackSlotWithObjRef(bip.res));
|
||||
break;
|
||||
case REFNE:
|
||||
if (debug == 1) printf("refeq\n");
|
||||
if (debug == 1) printf("refeq");
|
||||
if(pop(stack).u.objRef != pop(stack).u.objRef) bigFromInt(true);
|
||||
else bigFromInt(false);
|
||||
push(stack, stackSlotWithObjRef(bip.res));
|
||||
@ -312,9 +312,6 @@ int main(int argc, char *argv[]) {
|
||||
stack.size = &size;
|
||||
stack.current = ¤t;
|
||||
stack.stack = malloc(SIZE * 1024);
|
||||
if (stack.stack == NULL) {
|
||||
perror("malloc");
|
||||
}
|
||||
|
||||
// Initialize the registery
|
||||
int rSize = 100000;
|
||||
|
||||
9
record.c
9
record.c
@ -29,18 +29,17 @@ ObjRef getField(ObjRef arr, int point){
|
||||
return *(ObjRef *)GET_REFS_PTR(arr)[point]->data;
|
||||
}
|
||||
void setField(ObjRef arr, int point, ObjRef value){
|
||||
if(0 > point || point >= getSize(arr)){
|
||||
if(0 > point || point > getSize(arr)){
|
||||
printf("Index %i out of bounds for length %i\n",point, getSize(arr));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if(IS_PRIMITIVE(arr)) perror("Record is a primitive");
|
||||
if(IS_PRIMITIVE(value)){
|
||||
// printf("Size of value is %i\n", value->size);
|
||||
int size = value->size;
|
||||
if((GET_REFS_PTR(arr)[point] = malloc(size)) == NULL) perror("malloc");
|
||||
GET_REFS_PTR(arr)[point] = malloc(size);
|
||||
GET_REFS_PTR(arr)[point]->size = size;
|
||||
}else{
|
||||
int size = sizeof(*value) + (GET_ELEMENT_COUNT(value) * sizeof(void *));
|
||||
if((GET_REFS_PTR(arr)[point] = malloc(size)) == NULL) perror("malloc");
|
||||
GET_REFS_PTR(arr)[point] = malloc(size);
|
||||
GET_REFS_PTR(arr)[point] ->size = size;
|
||||
}
|
||||
* (ObjRef *)GET_REFS_PTR(arr)[point]->data = value;
|
||||
|
||||
@ -48,7 +48,6 @@ void setValIntObj(ObjRef iref, int val) {
|
||||
StackSlot stackSlotWithObjRef(ObjRef val) {
|
||||
StackSlot *stackSlot;
|
||||
stackSlot = malloc(sizeof(StackSlot));
|
||||
if(stackSlot == NULL) perror("malloc");
|
||||
stackSlot->isObjRef = true;
|
||||
stackSlot->u.objRef = val;
|
||||
return *stackSlot;
|
||||
@ -57,7 +56,6 @@ StackSlot stackSlotWithObjRef(ObjRef val) {
|
||||
StackSlot stackSlotWitchNumber(int val) {
|
||||
StackSlot *stackSlot;
|
||||
stackSlot = malloc(sizeof(StackSlot));
|
||||
if(stackSlot == NULL) perror("malloc");
|
||||
stackSlot->isObjRef = false;
|
||||
stackSlot->u.number = val;
|
||||
return *stackSlot;
|
||||
|
||||
Binary file not shown.
@ -1,18 +0,0 @@
|
||||
new 3
|
||||
popg 0
|
||||
|
||||
pushg 0
|
||||
pushc 10
|
||||
putf 0
|
||||
pushg 0
|
||||
pushc 11
|
||||
putf 1
|
||||
|
||||
pushg 0
|
||||
getf 0
|
||||
pushg 0
|
||||
getf 1
|
||||
add
|
||||
wrint
|
||||
halt
|
||||
// Sollte 10 + 11 ergeben
|
||||
Loading…
x
Reference in New Issue
Block a user