summaryrefslogtreecommitdiff
path: root/include/lcq
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2026-02-27 20:59:37 -0500
committerLLLL Colonq <llll@colonq>2026-02-27 20:59:37 -0500
commit83d7d3cf960ecb7b1e20b691d4018a67d407cf47 (patch)
tree074732177f1bd5a4b18f1ae53f6b718812b5621a /include/lcq
parenta525fadf516bc5aae2c0ec648d3b8c22e9f86293 (diff)
Update for RealNaesten :)
Diffstat (limited to 'include/lcq')
-rw-r--r--include/lcq/pit/runtime.h66
1 files changed, 15 insertions, 51 deletions
diff --git a/include/lcq/pit/runtime.h b/include/lcq/pit/runtime.h
index 02a2249..3ff8c90 100644
--- a/include/lcq/pit/runtime.h
+++ b/include/lcq/pit/runtime.h
@@ -13,10 +13,9 @@ typedef struct {
u8 data[];
} pit_arena;
pit_arena *pit_arena_new(i64 capacity, i64 elem_size);
-i32 pit_arena_next_idx(pit_arena *a);
-i32 pit_arena_alloc_idx(pit_arena *a);
-i32 pit_arena_alloc_bulk_idx(pit_arena *a, i64 num);
-void *pit_arena_idx(pit_arena *a, i32 idx);
+i64 pit_arena_alloc_idx(pit_arena *a);
+i64 pit_arena_alloc_bulk_idx(pit_arena *a, i64 num);
+void *pit_arena_idx(pit_arena *a, i64 idx);
void *pit_arena_alloc(pit_arena *a);
void *pit_arena_alloc_bulk(pit_arena *a, i64 num);
@@ -30,8 +29,8 @@ enum pit_value_sort {
PIT_VALUE_SORT_SYMBOL = 2, /* 0b10 - NaN-boxed index into symbol table */
PIT_VALUE_SORT_REF = 3 /* 0b11 - NaN-boxed index into "heavy object" arena */
};
-typedef i32 pit_symbol; /* a symbol at runtime is an index into the runtime's symbol table */
-typedef i32 pit_ref; /* a reference is an index into the runtime's arena */
+typedef i64 pit_symbol; /* a symbol at runtime is an index into the runtime's symbol table */
+typedef i64 pit_ref; /* a reference is an index into the runtime's arena */
typedef u64 pit_value;
enum pit_value_sort pit_value_sort(pit_value v);
u64 pit_value_data(pit_value v);
@@ -53,7 +52,8 @@ typedef struct { /* "heavy" values, the targets of refs */
PIT_VALUE_HEAVY_SORT_BYTES, /* bytestring */
PIT_VALUE_HEAVY_SORT_FUNC, /* Lisp closure */
PIT_VALUE_HEAVY_SORT_NATIVEFUNC, /* native function */
- PIT_VALUE_HEAVY_SORT_NATIVEDATA /* native data (C pointer) */
+ PIT_VALUE_HEAVY_SORT_NATIVEDATA, /* native data (C pointer) */
+ PIT_VALUE_HEAVY_SORT_FORWARDING_POINTER /* forwarding pointer to to-space (during GC) */
} hsort;
union {
pit_value cell;
@@ -63,6 +63,7 @@ typedef struct { /* "heavy" values, the targets of refs */
struct { pit_value env; pit_value args; pit_value arg_rest_nm; pit_value body; } func;
pit_nativefunc nativefunc;
struct { pit_value tag; void *data; } nativedata;
+ i64 forwarding_pointer;
} in;
} pit_value_heavy;
@@ -95,6 +96,7 @@ void pit_runtime_eval_program_push_apply(struct pit_runtime *rt, pit_runtime_eva
typedef struct pit_runtime {
/* interpreter state */
pit_arena *values; /* all heavy values - effectively an array of pit_value_heavy - MUTABLE! */
+ pit_arena *values_backbuffer; /* other values buffer (used by GC) */
pit_arena *arrays; /* all arrays - MUTABLE! */
pit_arena *bytes; /* all bytestrings (including symbol names) - immutable */
pit_arena *symtab; i64 symtab_len; /* all symbols - effectively an array of pit_symtab_entry - MUTABLE! */
@@ -150,6 +152,7 @@ bool pit_is_bytes(pit_runtime *rt, pit_value a);
bool pit_is_func(pit_runtime *rt, pit_value a);
bool pit_is_nativefunc(pit_runtime *rt, pit_value a);
bool pit_is_nativedata(pit_runtime *rt, pit_value a);
+bool pit_is_forwarding_pointer(pit_runtime *rt, pit_value a);
bool pit_eq(pit_value a, pit_value b);
bool pit_equal(pit_runtime *rt, pit_value a, pit_value b);
@@ -224,50 +227,11 @@ void *pit_nativedata_get(pit_runtime *rt, pit_value tag, pit_value v);
pit_value pit_expand_macros(pit_runtime *rt, pit_value top);
pit_value pit_eval(pit_runtime *rt, pit_value e);
+/* garbage collection */
+void pit_collect_garbage(pit_runtime *rt);
+
/* repl / file loading */
-#define PIT_DEFAULT_MAIN(rt) \
- if (argc < 2) { /* run repl */ \
- char buf[1024] = {0}; \
- i64 len = 0; \
- pit_runtime_freeze(rt); \
- if (pit_runtime_print_error(rt)) { exit(1); } \
- setbuf(stdout, NULL); \
- printf("> "); \
- while (len < (i64) sizeof(buf) && (buf[len++] = (char) getchar()) != EOF) { \
- if (buf[len - 1] == '\n') { \
- pit_value bs, prog, res; \
- buf[len - 1] = 0; \
- bs = pit_bytes_new_cstr(rt, buf); \
- prog = pit_read_bytes(rt, bs); \
- res = pit_eval(rt, prog); \
- if (pit_runtime_print_error(rt)) { \
- rt->error = PIT_NIL; \
- printf("> "); \
- } else { \
- char dumpbuf[1024] = {0}; \
- pit_dump(rt, dumpbuf, sizeof(dumpbuf) - 1, res, true); \
- printf("%s\n> ", dumpbuf); \
- } \
- len = 0; \
- } \
- } \
- } else { /* run file */ \
- pit_value bs = pit_bytes_new_file(rt, argv[1]); \
- pit_lexer lex; \
- pit_parser parse; \
- bool eof = false; \
- pit_value p = PIT_NIL; \
- if (!pit_lexer_from_bytes(rt, &lex, bs)) { \
- pit_error(rt, "failed to initialize lexer"); \
- } \
- pit_parser_from_lexer(&parse, &lex); \
- while (p = pit_parse(rt, &parse, &eof), !eof) { \
- if (pit_runtime_print_error(rt)) exit(1); \
- pit_eval(rt, p); \
- if (pit_runtime_print_error(rt)) exit(1); \
- } \
- if (pit_runtime_print_error(rt)) exit(1); \
- } \
- return 0;
+void pit_run_file(pit_runtime *rt, char *path);
+void pit_repl(pit_runtime *rt);
#endif