njvm/support.c
2024-01-27 19:59:01 +01:00

29 lines
599 B
C

#include "support.h"
#include <stdio.h>
#include <stdlib.h>
#include "objref.c"
void fatalError(char *msg){
printf("Fatal error: %s\n", msg);
exit(1);
}
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 = sizeof(unsigned int) + dataSize * sizeof(unsigned char);
return bigObjRef;
}
void * getPrimObjectDataPointer(void * obj){
ObjRef oo = ((ObjRef) (obj));
return oo->data;
}