Skip to content

Commit

Permalink
New RTS
Browse files Browse the repository at this point in the history
  • Loading branch information
ollef committed May 30, 2024
1 parent b3a1194 commit 105ed8d
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 336 deletions.
4 changes: 2 additions & 2 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ data-files:
- builtin/Builtin.vix
- rts/Sixten.Builtin.c
- rts/Sixten.Builtin.ll
- rts/garbage_collector.c
- rts/garbage_collector.h
- rts/main.ll
- rts/memory.c
- rts/memory.h

ghc-options:
- -Wall
Expand Down
292 changes: 0 additions & 292 deletions rts/garbage_collector.c

This file was deleted.

34 changes: 0 additions & 34 deletions rts/garbage_collector.h

This file was deleted.

47 changes: 47 additions & 0 deletions rts/memory.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "memory.h"

#include <stdlib.h>

static const uintptr_t TAG_BITS = 16;
static const uintptr_t TAG_MASK = ((uintptr_t)1 << TAG_BITS) - 1;

struct header {
uint32_t pointers;
};

uintptr_t sixten_heap_allocate(uint64_t tag, uint32_t pointers, uint32_t non_pointer_bytes) {
uintptr_t bytes = (uintptr_t)pointers * sizeof(void*) + (uintptr_t)non_pointer_bytes;
uint8_t* pointer = 0;

if (bytes > 0) {
pointer = malloc(sizeof(struct header) + bytes);
}

struct header* header = (struct header*)pointer;
header->pointers = pointers;

pointer += sizeof(struct header);

return (uintptr_t)pointer << TAG_BITS | (uintptr_t)(tag & TAG_MASK);
}

struct sixten_reference sixten_heap_payload(uintptr_t heap_object) {
uint8_t* pointer = (uint8_t*)((intptr_t)heap_object >> TAG_BITS);
if (pointer == 0) {
return (struct sixten_reference) {
.pointers = 0,
.non_pointers = 0,
};
}

struct header* header = (struct header*)(pointer - sizeof(struct header));

return (struct sixten_reference) {
.pointers = pointer,
.non_pointers = pointer + header->pointers * sizeof(void*),
};
}

uint64_t sixten_heap_tag(uintptr_t heap_object) {
return (uint64_t)(heap_object & TAG_MASK);
}
Loading

0 comments on commit 105ed8d

Please sign in to comment.