summaryrefslogtreecommitdiff
path: root/src/runtime.h
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2025-09-25 20:05:19 -0400
committerLLLL Colonq <llll@colonq>2025-09-25 20:05:19 -0400
commit811f11463851a0f35835ac72ef09b65b1072de20 (patch)
tree225cee11b86af7662e6319c9864788b92be3dfb1 /src/runtime.h
parent8e79c8ac42d3fa248174120266ae0988361df212 (diff)
Add runtime freezing, add defun and defmacro
Diffstat (limited to 'src/runtime.h')
-rw-r--r--src/runtime.h15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/runtime.h b/src/runtime.h
index c5040f1..f9995d1 100644
--- a/src/runtime.h
+++ b/src/runtime.h
@@ -12,6 +12,7 @@ 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);
@@ -86,18 +87,26 @@ pit_runtime_eval_program *pit_runtime_eval_program_new(i64 capacity);
void pit_runtime_eval_program_push(struct pit_runtime *rt, pit_runtime_eval_program *s, pit_runtime_eval_program_entry x);
typedef struct pit_runtime {
- pit_arena *values; // all heavy values - effectively an array of pit_value_heavy
- pit_arena *bytes; // all bytestrings (including symbol names)
- pit_arena *symtab; i64 symtab_len; // all symbols - effectively an array of pit_symtab_entry
+ // interpreter state
+ pit_arena *values; // all heavy values - effectively an array of pit_value_heavy - 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!
+ // temporary/"scratch" memory
pit_arena *scratch; // temporary arena used during parsing and evaluation
pit_values *saved_bindings; // stack used to save old values of bindings to be restored ("shallow binding")
pit_values *expr_stack; // stack of subexpressions to evaluate during evaluation
pit_values *result_stack; // stack of intermediate values during evaluation
pit_runtime_eval_program *program; // intermediate stack-based program constructed during evaluation
+ // bookkeeping
+ // "frozen" values offsets: values before these offsets are immutable, and we can reset here later
+ i64 frozen_values, frozen_bytes, frozen_symtab;
pit_value error; // error value - if this is non-nil, an error has occured! only tracks the first error
} pit_runtime;
pit_runtime *pit_runtime_new();
+void pit_runtime_freeze(pit_runtime *rt); // freeze the runtime at the current point - everything currently defined becomes immutable
+void pit_runtime_reset(pit_runtime *rt); // restore the runtime to the frozen point, resetting everything that has happened since
+
i64 pit_dump(pit_runtime *rt, char *buf, i64 len, pit_value v);
#define pit_trace(rt, v) pit_trace_(rt, "Trace [" __FILE__ ":" PIT_STR(__LINE__) "] %s\n", v)
void pit_trace_(pit_runtime *rt, const char *format, pit_value v);