feat: add wrenAbortFiber() API to abort current fiber with runtime error object
Add a new public API function `wrenAbortFiber()` that allows foreign methods to abort the currently executing fiber with a custom runtime error object. The function validates the API slot, then sets the fiber's error field to the value in the specified slot. The interpreter loop is updated to check for a non-null fiber error after calling a foreign method, triggering a runtime error if set. New test files (error.c, error.h, error.wren) demonstrate usage via a static Error.runtimeError foreign method, verifying that the error is propagated through Fiber.try() and that the fiber's isDone and error properties are correctly set. Xcode project updated to include the new error.c source file.
This commit is contained in:
+1
-1
@@ -513,7 +513,7 @@ typedef struct
|
||||
// S[NaN ]1---------------------------------------------------
|
||||
//
|
||||
// For singleton values, we just enumerate the different values. We'll use the
|
||||
// low three bits of the mantissa for that, and only need a couple:
|
||||
// low bits of the mantissa for that, and only need a few:
|
||||
//
|
||||
// 3 Type bits--v
|
||||
// 0[NaN ]1------------------------------------------------[T]
|
||||
|
||||
@@ -927,6 +927,7 @@ static WrenInterpretResult runInterpreter(WrenVM* vm, register ObjFiber* fiber)
|
||||
|
||||
case METHOD_FOREIGN:
|
||||
callForeign(vm, fiber, method->fn.foreign, numArgs);
|
||||
if (!IS_NULL(fiber->error)) RUNTIME_ERROR();
|
||||
break;
|
||||
|
||||
case METHOD_FN_CALL:
|
||||
@@ -1660,3 +1661,9 @@ void wrenGetVariable(WrenVM* vm, const char* module, const char* name,
|
||||
|
||||
setSlot(vm, slot, moduleObj->variables.data[variableSlot]);
|
||||
}
|
||||
|
||||
void wrenAbortFiber(WrenVM* vm, int slot)
|
||||
{
|
||||
validateApiSlot(vm, slot);
|
||||
vm->fiber->error = vm->apiStack[slot];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user