summaryrefslogtreecommitdiff
path: root/pit/include/lcq
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2026-09-01 06:26:13 -0400
committerLLLL Colonq <llll@colonq>2026-09-01 06:26:13 -0400
commitff7407c146b8129c2f1cc7ebe3b5771ad2f5dfdd (patch)
treebc70d9773ebc0deb25773d3b5c86ec7ea96eef6d /pit/include/lcq
parent6ebac820c84b218a45368eeaf1c853ff9c9d638f (diff)
pit: Fix evaluator
Diffstat (limited to 'pit/include/lcq')
-rw-r--r--pit/include/lcq/pit/runtime.h29
-rw-r--r--pit/include/lcq/pit/runtime/macroexpand.h3
-rw-r--r--pit/include/lcq/pit/runtime/symtab.h1
3 files changed, 30 insertions, 3 deletions
diff --git a/pit/include/lcq/pit/runtime.h b/pit/include/lcq/pit/runtime.h
index 70e65ca..feeb267 100644
--- a/pit/include/lcq/pit/runtime.h
+++ b/pit/include/lcq/pit/runtime.h
@@ -39,23 +39,47 @@ typedef struct {
} pit_callstack_entry;
PIT_DECLARE_VEC(pit_callstack_entry)
+/* entries on a stack used when compiling expressions */
+typedef struct {
+ enum {
+ PIT_COMPILATION_ENTRY_VALUE,
+ PIT_COMPILATION_ENTRY_DROP,
+ PIT_COMPILATION_ENTRY_BEGIN_CODE,
+ PIT_COMPILATION_ENTRY_END_CODE,
+ } sort;
+ union {
+ pit_value value;
+ /* void end_code; */
+ } in;
+} pit_compilation_entry;
+PIT_DECLARE_VEC(pit_compilation_entry)
+void pit_compilation_push_value(struct pit_runtime *rt, pit_vec(pit_compilation_entry) *s, pit_value x);
+void pit_compilation_push_drop(struct pit_runtime *rt, pit_vec(pit_compilation_entry) *s);
+void pit_compilation_push_begin_code(struct pit_runtime *rt, pit_vec(pit_compilation_entry) *s);
+void pit_compilation_push_end_code(struct pit_runtime *rt, pit_vec(pit_compilation_entry) *s);
+
/* entries on a stack used when traversing trees of values */
typedef struct {
enum {
PIT_TRAVERSAL_ENTRY_VALUE,
PIT_TRAVERSAL_ENTRY_DUMP_STRING,
PIT_TRAVERSAL_ENTRY_APPLICATION,
+ PIT_TRAVERSAL_ENTRY_BEGIN_CODE,
+ PIT_TRAVERSAL_ENTRY_END_CODE,
} sort;
union {
pit_value value;
char *dump_string;
struct { i64 arity; pit_annotation *annotation; } application;
+ /* void end_code; */
} in;
} pit_traversal_entry;
PIT_DECLARE_VEC(pit_traversal_entry)
void pit_traversal_push_value(struct pit_runtime *rt, pit_vec(pit_traversal_entry) *s, pit_value x);
void pit_traversal_push_dump_string(struct pit_runtime *rt, pit_vec(pit_traversal_entry) *s, char *m);
void pit_traversal_push_application(struct pit_runtime *rt, pit_vec(pit_traversal_entry) *s, i64 arity, pit_annotation *annotation);
+void pit_traversal_push_begin_code(struct pit_runtime *rt, pit_vec(pit_traversal_entry) *s);
+void pit_traversal_push_end_code(struct pit_runtime *rt, pit_vec(pit_traversal_entry) *s);
typedef struct pit_runtime {
/* interpreter state */
@@ -67,9 +91,10 @@ typedef struct pit_runtime {
pit_hashtable(pit_ref, pit_annotation) *annotations_backbuffer;
pit_vec(pit_symtab_entry) *symtab; /* all symbols */
/* temporary/"scratch" memory */
- pit_vec(pit_value) *saved_bindings; /* stack used to save old values of bindings to be restored ("shallow binding") */
+ pit_vec(pit_value) *saved_bindings; /* stack used to save old values of bindings ("shallow binding") */
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_compilation_entry) *compilation_stack; /* stack of subexpressions to compile */
pit_vec(pit_traversal_entry) *traversal; /* intermediate stack used during tree traversal */
pit_vec(pit_callstack_entry) *callstack; /* stack of enclosing function calls */
/* bookkeeping */
@@ -78,6 +103,8 @@ typedef struct pit_runtime {
pit_value error; /* error value - if this is non-nil, an error has occured! only tracks the first error */
i64 source_line, source_column; /* for error reporting only; line and column of token start */
i64 error_line, error_column; /* line and column of token start at time of error */
+ pit_value msg_out_of_memory; /* a pre-allocated "out of memory" error message */
+ /* we make sure to have this ready, since we can't allocate space for it if we run out! */
} pit_runtime;
pit_runtime *pit_runtime_new(u8 *buf, i64 len);
diff --git a/pit/include/lcq/pit/runtime/macroexpand.h b/pit/include/lcq/pit/runtime/macroexpand.h
index bc1f756..db56849 100644
--- a/pit/include/lcq/pit/runtime/macroexpand.h
+++ b/pit/include/lcq/pit/runtime/macroexpand.h
@@ -3,6 +3,7 @@
#include <lcq/pit/runtime.h>
-pit_value pit_macroexpand(pit_runtime *rt, pit_value top);
+pit_value pit_macroexpand_1(pit_runtime *rt, pit_value f);
+pit_value pit_macroexpand(pit_runtime *rt, pit_value f);
#endif
diff --git a/pit/include/lcq/pit/runtime/symtab.h b/pit/include/lcq/pit/runtime/symtab.h
index ac60523..e385884 100644
--- a/pit/include/lcq/pit/runtime/symtab.h
+++ b/pit/include/lcq/pit/runtime/symtab.h
@@ -20,7 +20,6 @@ void pit_symtab_symbol_mark_macro(pit_runtime *rt, pit_value sym);
void pit_symtab_mset(pit_runtime *rt, pit_value sym, pit_value v);
bool pit_symtab_is_symbol_special_form(pit_runtime *rt, pit_value sym);
void pit_symtab_symbol_mark_special_form(pit_runtime *rt, pit_value sym);
-void pit_symtab_sfset(pit_runtime *rt, pit_value sym, pit_value v);
void pit_symtab_bind(pit_runtime *rt, pit_value sym, pit_value v);
pit_value pit_symtab_unbind(pit_runtime *rt, pit_value sym);