This commit is contained in:
nilspolek 2024-01-28 17:56:12 +01:00
parent 8a0917f1b6
commit ba9d0b77b9
12 changed files with 9 additions and 7 deletions

View File

@ -9,4 +9,4 @@ run: build
./njvm prog.bin ./njvm prog.bin
debug: build debug: build
./njvm --debug prog.bin ./njvm --debug --heap 100000 --stack 1000 prog.bin

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

4
njvm.c
View File

@ -541,12 +541,12 @@ int main(int argc, char *argv[]) {
return 0; return 0;
} else if (strcmp(argv[i], "--stack") == 0) { } else if (strcmp(argv[i], "--stack") == 0) {
i++; i++;
// TODO: implement stack size size = atoi(argv[i]);
} else if (strcmp(argv[i], "--heap") == 0) { } else if (strcmp(argv[i], "--heap") == 0) {
i++; i++;
argVheapSizeKiB = atoi(argv[i]); argVheapSizeKiB = atoi(argv[i]);
} else if (strcmp(argv[i], "--gcpurge") == 0) { } else if (strcmp(argv[i], "--gcpurge") == 0) {
// TODO: implement gcpurge purgeFlag = true;
} else { } else {
sizeSDA = fromFile(argv[i], program); sizeSDA = fromFile(argv[i], program);
run = 1; run = 1;

BIN
njvm.o

Binary file not shown.

View File

@ -8,11 +8,12 @@
#include "njvm.h" #include "njvm.h"
ObjRef newRecord(int size){ ObjRef newRecord(int size){
printf("Size: %i\n", size);
ObjRef record; ObjRef record;
unsigned int objSize; unsigned int objSize;
objSize = sizeof(*record) + (size * sizeof(void *)); objSize = sizeof(*record) + (size * sizeof(void *));
if((record = alloc(objSize)) == NULL){ if((record = alloc(objSize)) == NULL){
perror("malloc"); perror("alloc");
} }
record->size = MSB; record->size = MSB;
record->size = record->size + size; record->size = record->size + size;
@ -49,7 +50,7 @@ void setField(ObjRef arr, int point, ObjRef value){
else else
size = sizeof(*value) + (GET_ELEMENT_COUNT(value) * sizeof(void *)); size = sizeof(*value) + (GET_ELEMENT_COUNT(value) * sizeof(void *));
} }
if((GET_REFS_PTR(arr)[point] = malloc(size)) == NULL) perror("malloc"); if((GET_REFS_PTR(arr)[point] = alloc(size)) == NULL) perror("alloc");
GET_REFS_PTR(arr)[point] ->size = size; GET_REFS_PTR(arr)[point] ->size = size;
* (ObjRef *)GET_REFS_PTR(arr)[point]->data = value; * (ObjRef *)GET_REFS_PTR(arr)[point]->data = value;
} }

View File

@ -4,6 +4,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "objref.c" #include "objref.c"
#include "njvm.h"
typedef int Object; typedef int Object;
@ -19,8 +20,8 @@ typedef struct {
ObjRef getIntObj(int val) { ObjRef getIntObj(int val) {
ObjRef intObject; ObjRef intObject;
unsigned int objSize = sizeof(ObjRef) + sizeof(int); unsigned int objSize = sizeof(ObjRef) + sizeof(int);
if ((intObject = malloc(objSize)) == NULL) { if ((intObject = alloc(objSize)) == NULL) {
perror("malloc"); perror("alloc");
} }
*(int *) intObject->data = val; *(int *) intObject->data = val;
intObject->size = objSize; intObject->size = objSize;