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,12 @@
|
||||
int process_string(char* text) {
|
||||
int len = strlen(text);
|
||||
int pos = strpos(text, bad_variable);
|
||||
return pos;
|
||||
}
|
||||
|
||||
int main() {
|
||||
char* message = "Hello World";
|
||||
int result = process_string(message);
|
||||
printf("Result: %d\n", result);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
int level3() {
|
||||
int bad = undefined_var;
|
||||
return bad;
|
||||
}
|
||||
|
||||
int level2(int x) {
|
||||
int result = level3();
|
||||
return result + x;
|
||||
}
|
||||
|
||||
int level1(int a, int b) {
|
||||
int sum = a + b;
|
||||
int final = level2(sum);
|
||||
return final;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Starting program\n");
|
||||
int value = level1(5, 10);
|
||||
printf("Value: %d\n", value);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
int main() {
|
||||
int x = 10;
|
||||
int y = unknown_variable + 5;
|
||||
printf("Y: %d\n", y);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user