This commit is contained in:
Elias Bennour 2024-01-28 20:41:04 +01:00
parent f4b1ce03c5
commit f0c7f31655
9 changed files with 19 additions and 7 deletions

View File

@ -5,7 +5,8 @@ set(CMAKE_C_STANDARD 99)
add_compile_options(-g -Wall -pedantic) add_compile_options(-g -Wall -pedantic)
add_executable(njvm njvm.c) add_executable(njvm njvm.c
njvm.h)
# Include directories for njvm executable # Include directories for njvm executable
target_include_directories(njvm PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/bigint/build/include) target_include_directories(njvm PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/bigint/build/include)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

12
njvm.c
View File

@ -417,23 +417,23 @@ void garbageCollector() {
gcCount++; gcCount++;
} }
ObjRef alloc(unsigned int size) { ObjRef alloc(unsigned int objectSize) {
if (freeHeapPtr + size > halfHeapPtr) { if (freeHeapPtr + objectSize > halfHeapPtr) {
garbageCollector(); garbageCollector();
if (freeHeapPtr + size > halfHeapPtr) { if (freeHeapPtr + objectSize > halfHeapPtr) {
fprintf(stderr, "Heap is full\n"); fprintf(stderr, "Heap is full\n");
exit(1); exit(1);
} }
} }
ObjRef or; ObjRef or;
or = (ObjRef) freeHeapPtr; or = (ObjRef) freeHeapPtr;
freeHeapPtr = freeHeapPtr + size; freeHeapPtr = freeHeapPtr + objectSize;
return or; return or;
} }
void heapAllocator(int n) { void heapAllocator(int n) {
heapSizeKiB = n; heapSizeKiB = n;
if ((heap = alloc(n * 1024)) == NULL) { if ((heap = malloc(n * 1024)) == NULL) {
perror("malloc"); perror("malloc");
exit(1); exit(1);
} }
@ -503,7 +503,7 @@ int main(int argc, char *argv[]) {
run = 1; run = 1;
} }
} }
//heapAllocator(argVheapSizeKiB); heapAllocator(argVheapSizeKiB);
// Init the sda // Init the sda
ObjRef s[sizeSDA]; ObjRef s[sizeSDA];
sda.size = &sizeSDA; sda.size = &sizeSDA;

11
njvm.h Normal file
View File

@ -0,0 +1,11 @@
//
// Created by Elias Bennour on 28.01.24.
//
#ifndef NINJA_NJVM_H
#define NINJA_NJVM_H
#include "objref.c"
ObjRef alloc(unsigned int size);
#endif //NINJA_NJVM_H

BIN
njvm.o

Binary file not shown.

BIN
support.o

Binary file not shown.