feat: add runtime error support with source paths, line info, and stack traces
Introduce primitive error signaling, runtime error handling with callstack printing, and fiber termination on error. Add source file path and method name tracking to functions, along with debug line number information. Update arithmetic operators to error on non-numeric operands and implement proper "method not found" runtime errors. Refactor the test runner to expect runtime errors with exit code 70 (EX_SOFTWARE) and update the C API to accept source paths in wrenInterpret and wrenCompile. Rename WrenNativeMethodFn to WrenForeignMethodFn and adjust related typedefs. Add debug source line arrays to compilers and functions, and replace the old debug dump functions with new print-based variants that display line numbers.
This commit is contained in:
+3
-3
@@ -23,7 +23,7 @@ typedef struct WrenVM WrenVM;
|
||||
// [oldSize] will be zero. It should return NULL.
|
||||
typedef void* (*WrenReallocateFn)(void* memory, size_t oldSize, size_t newSize);
|
||||
|
||||
typedef void (*WrenNativeMethodFn)(WrenVM* vm);
|
||||
typedef void (*WrenForeignMethodFn)(WrenVM* vm);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -80,7 +80,7 @@ void wrenFreeVM(WrenVM* vm);
|
||||
// Runs [source], a string of Wren source code in a new fiber in [vm]. Returns
|
||||
// zero if successful.
|
||||
// TODO: Define error codes.
|
||||
int wrenInterpret(WrenVM* vm, const char* source);
|
||||
int wrenInterpret(WrenVM* vm, const char* sourcePath, const char* source);
|
||||
|
||||
// Defines a foreign method implemented by the host application. Looks for a
|
||||
// global class named [className] to bind the method to. If not found, it will
|
||||
@@ -91,7 +91,7 @@ int wrenInterpret(WrenVM* vm, const char* source);
|
||||
// replaced. When invoked, the method will call [method].
|
||||
void wrenDefineMethod(WrenVM* vm, const char* className,
|
||||
const char* methodName, int numParams,
|
||||
WrenNativeMethodFn method);
|
||||
WrenForeignMethodFn method);
|
||||
|
||||
// Reads an numeric argument for a foreign call. This must only be called within
|
||||
// a function provided to [wrenDefineMethod]. Retrieves the argument at [index]
|
||||
|
||||
Reference in New Issue
Block a user