From 7b9c4a3ac265026d98624ac614eead866a190042 Mon Sep 17 00:00:00 2001 From: LLLL Colonq Date: Mon, 10 Aug 2026 21:49:57 -0400 Subject: pit: VM-style evaluation --- pit/include/lcq/pit/runtime.h | 11 ++++++----- pit/include/lcq/pit/runtime/eval.h | 3 ++- pit/include/lcq/pit/vec.h | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) (limited to 'pit/include') diff --git a/pit/include/lcq/pit/runtime.h b/pit/include/lcq/pit/runtime.h index a55c2d2..075d94c 100644 --- a/pit/include/lcq/pit/runtime.h +++ b/pit/include/lcq/pit/runtime.h @@ -31,12 +31,13 @@ PIT_DECLARE_HASHTABLE(pit_ref, pit_annotation) void pit_annotation_set(struct pit_runtime *rt, pit_ref ref, pit_annotation annotation); pit_annotation *pit_annotation_get(struct pit_runtime *rt, pit_ref ref); -/* entry in the backtrace */ typedef struct { - pit_value val; + pit_value tag; /* (possibly nil) identifier for this frame for error messages */ pit_annotation ann; -} pit_backtrace_entry; -PIT_DECLARE_VEC(pit_backtrace_entry) + pit_value bound; /* list of bound names */ + pit_value code; /* list of vm expressions */ +} pit_callstack_entry; +PIT_DECLARE_VEC(pit_callstack_entry) /* entries on a stack used when traversing trees of values */ typedef struct { @@ -70,7 +71,7 @@ typedef struct pit_runtime { pit_vec(pit_value) *expr_stack; /* stack of subexpressions to evaluate during evaluation */ pit_vec(pit_value) *result_stack; /* stack of intermediate values during evaluation */ pit_vec(pit_traversal_entry) *traversal; /* intermediate stack used during tree traversal */ - pit_vec(pit_backtrace_entry) *backtrace; /* stack of enclosing function calls */ + pit_vec(pit_callstack_entry) *callstack; /* stack of enclosing function calls */ /* bookkeeping */ /* "frozen" values offsets: values before these offsets are immutable, and we can reset here later */ i64 frozen_values, frozen_symtab; diff --git a/pit/include/lcq/pit/runtime/eval.h b/pit/include/lcq/pit/runtime/eval.h index 3dc9e3c..41ec046 100644 --- a/pit/include/lcq/pit/runtime/eval.h +++ b/pit/include/lcq/pit/runtime/eval.h @@ -3,6 +3,7 @@ #include -pit_value pit_eval(pit_runtime *rt, pit_value e); +pit_value pit_vm_compile(pit_runtime *rt, pit_value top); +pit_value pit_vm_eval(pit_runtime *rt, pit_value v); #endif diff --git a/pit/include/lcq/pit/vec.h b/pit/include/lcq/pit/vec.h index b60140f..e4f918c 100644 --- a/pit/include/lcq/pit/vec.h +++ b/pit/include/lcq/pit/vec.h @@ -45,7 +45,7 @@ static __attribute__ ((unused)) i64 pit_vec_pop(ty)(pit_vec(ty) *s, ty *v) { \ i64 idx = (s->next - 1); \ if (s->next == 0 || idx + 1 > s->capacity) return -1; \ - *v = s->data[idx]; \ + if (v) *v = s->data[idx]; \ return --s->next; \ } -- cgit v1.3.1