Skip to content

Commit 105ed8d

Browse files
committed
New RTS
1 parent b3a1194 commit 105ed8d

7 files changed

Lines changed: 71 additions & 336 deletions

File tree

package.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ data-files:
1414
- builtin/Builtin.vix
1515
- rts/Sixten.Builtin.c
1616
- rts/Sixten.Builtin.ll
17-
- rts/garbage_collector.c
18-
- rts/garbage_collector.h
1917
- rts/main.ll
18+
- rts/memory.c
19+
- rts/memory.h
2020

2121
ghc-options:
2222
- -Wall

rts/garbage_collector.c

Lines changed: 0 additions & 292 deletions
This file was deleted.

rts/garbage_collector.h

Lines changed: 0 additions & 34 deletions
This file was deleted.

rts/memory.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include "memory.h"
2+
3+
#include <stdlib.h>
4+
5+
static const uintptr_t TAG_BITS = 16;
6+
static const uintptr_t TAG_MASK = ((uintptr_t)1 << TAG_BITS) - 1;
7+
8+
struct header {
9+
uint32_t pointers;
10+
};
11+
12+
uintptr_t sixten_heap_allocate(uint64_t tag, uint32_t pointers, uint32_t non_pointer_bytes) {
13+
uintptr_t bytes = (uintptr_t)pointers * sizeof(void*) + (uintptr_t)non_pointer_bytes;
14+
uint8_t* pointer = 0;
15+
16+
if (bytes > 0) {
17+
pointer = malloc(sizeof(struct header) + bytes);
18+
}
19+
20+
struct header* header = (struct header*)pointer;
21+
header->pointers = pointers;
22+
23+
pointer += sizeof(struct header);
24+
25+
return (uintptr_t)pointer << TAG_BITS | (uintptr_t)(tag & TAG_MASK);
26+
}
27+
28+
struct sixten_reference sixten_heap_payload(uintptr_t heap_object) {
29+
uint8_t* pointer = (uint8_t*)((intptr_t)heap_object >> TAG_BITS);
30+
if (pointer == 0) {
31+
return (struct sixten_reference) {
32+
.pointers = 0,
33+
.non_pointers = 0,
34+
};
35+
}
36+
37+
struct header* header = (struct header*)(pointer - sizeof(struct header));
38+
39+
return (struct sixten_reference) {
40+
.pointers = pointer,
41+
.non_pointers = pointer + header->pointers * sizeof(void*),
42+
};
43+
}
44+
45+
uint64_t sixten_heap_tag(uintptr_t heap_object) {
46+
return (uint64_t)(heap_object & TAG_MASK);
47+
}

0 commit comments

Comments
 (0)