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
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;
} else if (strcmp(argv[i], "--stack") == 0) {
i++;
// TODO: implement stack size
size = atoi(argv[i]);
} else if (strcmp(argv[i], "--heap") == 0) {
i++;
argVheapSizeKiB = atoi(argv[i]);
} else if (strcmp(argv[i], "--gcpurge") == 0) {
// TODO: implement gcpurge
purgeFlag = true;
} else {
sizeSDA = fromFile(argv[i], program);
run = 1;

BIN
njvm.o

Binary file not shown.

View File

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

View File

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