Skip to content

Commit

Permalink
fix: make compt with asm
Browse files Browse the repository at this point in the history
  • Loading branch information
SpideyZac committed Jun 16, 2024
1 parent fb32b10 commit 6379ebc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/compiler/target/vm/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ machine *machine_new(int stack_size, int heap_size) {
result->heap_size = heap_size;
result->stack = malloc(sizeof(float) * stack_size);
result->heap = malloc(sizeof(char) * heap_size);
result->allocated = malloc(sizeof(bool) * heap_size / 4); // 4 bytes per float
result->allocated = malloc(sizeof(bool) * heap_size);
result->return_register = 0;
result->stack_pointer = 0;
result->hooks = 0;
Expand Down Expand Up @@ -114,9 +114,9 @@ void machine_access_return_register(machine *vm) {
}

int machine_allocate(machine *vm) {
int size = machine_pop(vm), addr = -1, consecutive_free_calls = 0;
int size = machine_pop(vm) * 4, addr = -1, consecutive_free_calls = 0;

for (int i = 0; i < vm->heap_size / 4; i++) {
for (int i = 0; i < vm->heap_size; i++) {
if (!vm->allocated[i]) consecutive_free_calls++;
else consecutive_free_calls = 0;

Expand All @@ -139,7 +139,7 @@ int machine_allocate(machine *vm) {
}

void machine_free(machine *vm) {
int addr = machine_pop(vm), size = machine_pop(vm);
int addr = machine_pop(vm), size = machine_pop(vm) * 4;

for (int i = 0; i < size; i++) {
vm->allocated[addr + i] = false;
Expand All @@ -166,7 +166,7 @@ float bytes2Float(unsigned char bytes_temp[4]) {
}

void machine_store(machine *vm, int floats) {
int addr = machine_pop(vm) * 4;
int addr = machine_pop(vm);

// store value in heap by breaking it into bytes
for (int i = floats - 1; i >= 0; i--) {
Expand All @@ -182,7 +182,7 @@ void machine_store(machine *vm, int floats) {
}

void machine_load(machine *vm, int floats) {
int addr = machine_pop(vm) * 4;
int addr = machine_pop(vm);

// load value from heap by combining bytes
for (int i = 0; i < floats; i++) {
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1225,12 +1225,12 @@ impl<'a> Visitor<'a> {
self.add_statements(vec![
ir::IRStatement::RefHook(left.hook),
ir::IRStatement::Copy,
ir::IRStatement::Push(i as f32),
ir::IRStatement::Push(i as f32 * 4.0),
ir::IRStatement::Add,
ir::IRStatement::Load(1),
ir::IRStatement::RefHook(right.hook),
ir::IRStatement::Copy,
ir::IRStatement::Push(i as f32),
ir::IRStatement::Push(i as f32 * 4.0),
ir::IRStatement::Add,
ir::IRStatement::Load(1),
ir::IRStatement::Subtract,
Expand Down Expand Up @@ -1319,12 +1319,12 @@ impl<'a> Visitor<'a> {
self.add_statements(vec![
ir::IRStatement::RefHook(left.hook),
ir::IRStatement::Copy,
ir::IRStatement::Push(i as f32),
ir::IRStatement::Push(i as f32 * 4.0),
ir::IRStatement::Add,
ir::IRStatement::Load(1),
ir::IRStatement::RefHook(right.hook),
ir::IRStatement::Copy,
ir::IRStatement::Push(i as f32),
ir::IRStatement::Push(i as f32 * 4.0),
ir::IRStatement::Add,
ir::IRStatement::Load(1),
ir::IRStatement::Subtract,
Expand Down

0 comments on commit 6379ebc

Please sign in to comment.