fixed some mistakes
This commit is contained in:
parent
e8b4062331
commit
c174108e09
8
njvm.c
8
njvm.c
@ -243,16 +243,16 @@ void execute(struct program program) {
|
|||||||
break;
|
break;
|
||||||
case NEW:
|
case NEW:
|
||||||
if (debug == 1) printf("new");
|
if (debug == 1) printf("new");
|
||||||
push(stack, newRecord(SIGN_EXTEND(IMMEDIATE(program.program[i]))))
|
push(stack, stackSlotWithObjRef(newRecord(SIGN_EXTEND(IMMEDIATE(program.program[i])))));
|
||||||
break;
|
break;
|
||||||
case GETF:
|
case GETF:
|
||||||
if (debug == 1) printf("getf");
|
if (debug == 1) printf("getf");
|
||||||
push(stack, getField(pop(stack), SIGN_EXTEND(IMMEDIATE(program.program[i]))))
|
push(stack, stackSlotWithObjRef(getField(pop(stack).u.objRef,SIGN_EXTEND(IMMEDIATE(program.program[i])))));
|
||||||
break;
|
break;
|
||||||
case PUTF:
|
case PUTF:
|
||||||
if (debug == 1) printf("putf");
|
if (debug == 1) printf("putf");
|
||||||
tempObj = pop(stack)
|
tempObj = pop(stack).u.objRef;
|
||||||
setField(pop(stack), SIGN_EXTEND(IMMEDIATE(program.program[i])),tempObj)
|
setField(pop(stack).u.objRef, SIGN_EXTEND(IMMEDIATE(program.program[i])),tempObj);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
17
record.c
17
record.c
@ -7,19 +7,22 @@
|
|||||||
#include "instruktion.c"
|
#include "instruktion.c"
|
||||||
ObjRef newRecord(int size){
|
ObjRef newRecord(int size){
|
||||||
ObjRef record;
|
ObjRef record;
|
||||||
if((record = malloc(*record + size * sizeof(void *)))== NULL){
|
unsigned int objSize;
|
||||||
perror("malloc")
|
objSize = sizeof(*record) + (size * sizeof(void *));
|
||||||
|
if((record = malloc(objSize))== NULL){
|
||||||
|
perror("malloc");
|
||||||
}
|
}
|
||||||
record->size = MSB & size;
|
record->size = MSB & size;
|
||||||
for(int i = 0; i < size; i++) {
|
for(int i = 0; i < size; i++) {
|
||||||
GET_REFS_PTR(record)[i] = malloc(8)
|
GET_REFS_PTR(record)[i] = malloc(8);
|
||||||
}
|
}
|
||||||
|
return record;
|
||||||
}
|
}
|
||||||
ObjRef getField(ObjRef array, int point){
|
ObjRef getField(ObjRef arr, int point){
|
||||||
return *(ObjRef *)GET_REFS_PTR(array)[point]->data
|
return *(ObjRef *)GET_REFS_PTR(arr)[point]->data;
|
||||||
}
|
}
|
||||||
setField(ObjRef array, int point, ObjRef value){
|
void setField(ObjRef arr, int point, ObjRef value){
|
||||||
(ObjRef *)GET_REFS_PTR(array)[point]->data = value
|
* (ObjRef *)GET_REFS_PTR(arr)[point]->data = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Loading…
x
Reference in New Issue
Block a user