39 lines
1.0 KiB
C
39 lines
1.0 KiB
C
//
|
|
// Created by Nils Polek on 23.01.24.
|
|
//
|
|
#ifndef RECORD
|
|
#define RECORD
|
|
#include "stackslot.c"
|
|
#include "instruktion.c"
|
|
ObjRef newRecord(int size){
|
|
ObjRef record;
|
|
unsigned int objSize;
|
|
objSize = sizeof(*record) + (size * sizeof(void *));
|
|
if((record = malloc(objSize)) == NULL){
|
|
perror("malloc");
|
|
}
|
|
record->size = (1 << ((sizeof(int) * 8) - 1));
|
|
record->size = record->size + size;
|
|
for(int i = 0; i < size; i++) {
|
|
GET_REFS_PTR(record)[i] = malloc(8);
|
|
}
|
|
return record;
|
|
}
|
|
int getSize(ObjRef arr){
|
|
return GET_ELEMENT_COUNT(arr);
|
|
}
|
|
ObjRef getField(ObjRef arr, int point){
|
|
if(0 > point || point > getSize(arr)){
|
|
printf("Index %i out of bounds for length %i\n",point, getSize(arr));
|
|
}
|
|
return *(ObjRef *)GET_REFS_PTR(arr)[point]->data;
|
|
}
|
|
void setField(ObjRef arr, int point, ObjRef value){
|
|
if(0 > point || point > getSize(arr)){
|
|
printf("Index %i out of bounds for length %i\n",point, getSize(arr));
|
|
}
|
|
* (ObjRef *)GET_REFS_PTR(arr)[point]->data = value;
|
|
}
|
|
|
|
#endif
|