feat: add call stack tracking and enhanced error reporting with file:line context
Implement a full call stack system that tracks function calls during interpretation, including native function boundaries. Add `push_call_frame`/`pop_call_frame` functions, a `CallStack` struct with depth-limited frames, and `print_stacktrace` for formatted error output. Introduce `error_with_context` to replace bare `error()` calls, and modify the tokenizer to track line/column/filename per token. Update the parser and interpreter to push/pop frames on function entry/exit, and add new Makefile targets (`demo-error-*`) plus test scripts (`test_error_stacktrace.rc`, `test_error_native.rc`, `test_error_undefined_var.rc`) and an `examples/error_handling_demo.rc` to demonstrate the new error reporting capabilities.
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
int deep_function_3() {
|
||||
int result = non_existent_variable * 5;
|
||||
return result;
|
||||
}
|
||||
|
||||
int deep_function_2(int x) {
|
||||
printf("In deep_function_2 with x=%d\n", x);
|
||||
int value = deep_function_3();
|
||||
return value + x;
|
||||
}
|
||||
|
||||
int deep_function_1(int a, int b) {
|
||||
printf("In deep_function_1 with a=%d, b=%d\n", a, b);
|
||||
int sum = a + b;
|
||||
int result = deep_function_2(sum);
|
||||
return result;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("=== Error Handling Demonstration ===\n");
|
||||
printf("This program will intentionally trigger an error\n");
|
||||
printf("to demonstrate the enhanced error reporting system.\n\n");
|
||||
|
||||
int final_result = deep_function_1(10, 20);
|
||||
printf("Final result: %d\n", final_result);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user