From a5e153d8558a43fbdc78f5b9fdaff426feea4654 Mon Sep 17 00:00:00 2001 From: LLLL Colonq Date: Tue, 21 Jul 2026 20:56:52 -0400 Subject: pit: Backtraces --- pit/include/lcq/pit/runtime.h | 8 ++++++++ pit/include/lcq/pit/runtime/dump.h | 12 ++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'pit/include') diff --git a/pit/include/lcq/pit/runtime.h b/pit/include/lcq/pit/runtime.h index b9143cf..a55c2d2 100644 --- a/pit/include/lcq/pit/runtime.h +++ b/pit/include/lcq/pit/runtime.h @@ -31,6 +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_annotation ann; +} pit_backtrace_entry; +PIT_DECLARE_VEC(pit_backtrace_entry) + /* entries on a stack used when traversing trees of values */ typedef struct { enum { @@ -63,6 +70,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 */ /* 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/dump.h b/pit/include/lcq/pit/runtime/dump.h index 2aeba2f..600604e 100644 --- a/pit/include/lcq/pit/runtime/dump.h +++ b/pit/include/lcq/pit/runtime/dump.h @@ -3,9 +3,17 @@ #include -typedef i64 (*pit_dump_callback)(u8 *buf, i64 len, void *data); +typedef enum { + PIT_DUMP_CONDITION_NORMAL = 0, + PIT_DUMP_CONDITION_FULL = -1, + PIT_DUMP_CONDITION_STACK_UNDERFLOW = -2, + PIT_DUMP_CONDITION_STACK_OVERFLOW = -3, + PIT_DUMP_CONDITION_MALFORMED_TRAVERSAL = -4, +} pit_dump_condition; -void pit_dump_with_callback(pit_runtime *rt, pit_value top, bool readable, pit_dump_callback write, void *data); +typedef pit_dump_condition (*pit_dump_callback)(u8 *buf, i64 len, void *data); + +pit_dump_condition pit_dump_with_callback(pit_runtime *rt, pit_value top, bool readable, pit_dump_callback write, void *data); /* pretty-print a pit value if readable is true, try to produce output that can be machine-read (quotes on strings, etc) */ -- cgit v1.3.1