forked from Mirror/wren
Add wrenAbortFiber().
Thanks, @underscorediscovery!
This commit is contained in:
@ -436,5 +436,8 @@ void wrenInsertInList(WrenVM* vm, int listSlot, int index, int elementSlot);
|
||||
// [slot].
|
||||
void wrenGetVariable(WrenVM* vm, const char* module, const char* name,
|
||||
int slot);
|
||||
// Sets the current fiber to be aborted, and uses the value in [slot] as the
|
||||
// runtime error object.
|
||||
void wrenAbortFiber(WrenVM* vm, int slot);
|
||||
|
||||
#endif
|
||||
|
||||
@ -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];
|
||||
}
|
||||
|
||||
18
test/api/error.c
Normal file
18
test/api/error.c
Normal file
@ -0,0 +1,18 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "error.h"
|
||||
|
||||
static void runtimeError(WrenVM* vm)
|
||||
{
|
||||
wrenEnsureSlots(vm, 1);
|
||||
wrenSetSlotString(vm, 0, "Error!");
|
||||
wrenAbortFiber(vm, 0);
|
||||
}
|
||||
|
||||
WrenForeignMethodFn errorBindMethod(const char* signature)
|
||||
{
|
||||
if (strcmp(signature, "static Error.runtimeError") == 0) return runtimeError;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
3
test/api/error.h
Normal file
3
test/api/error.h
Normal file
@ -0,0 +1,3 @@
|
||||
#include "wren.h"
|
||||
|
||||
WrenForeignMethodFn errorBindMethod(const char* signature);
|
||||
12
test/api/error.wren
Normal file
12
test/api/error.wren
Normal file
@ -0,0 +1,12 @@
|
||||
class Error {
|
||||
foreign static runtimeError
|
||||
}
|
||||
|
||||
var fiber = Fiber.new {
|
||||
Error.runtimeError
|
||||
}
|
||||
|
||||
var error = fiber.try()
|
||||
System.print(error) // expect: Error!
|
||||
System.print(fiber.isDone) // expect: true
|
||||
System.print(fiber.error) // expect: Error!
|
||||
@ -6,6 +6,7 @@
|
||||
|
||||
#include "benchmark.h"
|
||||
#include "call.h"
|
||||
#include "error.h"
|
||||
#include "get_variable.h"
|
||||
#include "foreign_class.h"
|
||||
#include "handle.h"
|
||||
@ -35,6 +36,9 @@ static WrenForeignMethodFn bindForeignMethod(
|
||||
|
||||
method = benchmarkBindMethod(fullName);
|
||||
if (method != NULL) return method;
|
||||
|
||||
method = errorBindMethod(fullName);
|
||||
if (method != NULL) return method;
|
||||
|
||||
method = getVariableBindMethod(fullName);
|
||||
if (method != NULL) return method;
|
||||
|
||||
@ -36,6 +36,7 @@
|
||||
29A427391BDBE435001E6E22 /* wren_opt_random.c in Sources */ = {isa = PBXBuildFile; fileRef = 29A427311BDBE435001E6E22 /* wren_opt_random.c */; };
|
||||
29A4273A1BDBE435001E6E22 /* wren_opt_random.wren.inc in Sources */ = {isa = PBXBuildFile; fileRef = 29A427331BDBE435001E6E22 /* wren_opt_random.wren.inc */; };
|
||||
29A4273B1BDBE435001E6E22 /* wren_opt_random.wren.inc in Sources */ = {isa = PBXBuildFile; fileRef = 29A427331BDBE435001E6E22 /* wren_opt_random.wren.inc */; };
|
||||
29AD96611D0A57F800C4DFE7 /* error.c in Sources */ = {isa = PBXBuildFile; fileRef = 29AD965F1D0A57F800C4DFE7 /* error.c */; };
|
||||
29C8A9331AB71FFF00DEC81D /* vm.c in Sources */ = {isa = PBXBuildFile; fileRef = 29C8A9311AB71FFF00DEC81D /* vm.c */; };
|
||||
29C946981C88F14F00B4A4F3 /* new_vm.c in Sources */ = {isa = PBXBuildFile; fileRef = 29C946961C88F14F00B4A4F3 /* new_vm.c */; };
|
||||
29D025E31C19CD1000A3BB28 /* os.c in Sources */ = {isa = PBXBuildFile; fileRef = 29D025E01C19CD1000A3BB28 /* os.c */; };
|
||||
@ -124,6 +125,8 @@
|
||||
29A427321BDBE435001E6E22 /* wren_opt_random.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = wren_opt_random.h; path = ../../src/optional/wren_opt_random.h; sourceTree = "<group>"; };
|
||||
29A427331BDBE435001E6E22 /* wren_opt_random.wren.inc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.pascal; name = wren_opt_random.wren.inc; path = ../../src/optional/wren_opt_random.wren.inc; sourceTree = "<group>"; };
|
||||
29AB1F061816E3AD004B501E /* wren */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = wren; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
29AD965F1D0A57F800C4DFE7 /* error.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = error.c; path = ../../test/api/error.c; sourceTree = "<group>"; };
|
||||
29AD96601D0A57F800C4DFE7 /* error.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = error.h; path = ../../test/api/error.h; sourceTree = "<group>"; };
|
||||
29C8A9311AB71FFF00DEC81D /* vm.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = vm.c; path = ../../src/cli/vm.c; sourceTree = "<group>"; };
|
||||
29C8A9321AB71FFF00DEC81D /* vm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = vm.h; path = ../../src/cli/vm.h; sourceTree = "<group>"; };
|
||||
29C946961C88F14F00B4A4F3 /* new_vm.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = new_vm.c; path = ../../test/api/new_vm.c; sourceTree = "<group>"; };
|
||||
@ -266,6 +269,8 @@
|
||||
29D009A61B7E3993000CE58C /* main.c */,
|
||||
293D46941BB43F9900200083 /* call.c */,
|
||||
293D46951BB43F9900200083 /* call.h */,
|
||||
29AD965F1D0A57F800C4DFE7 /* error.c */,
|
||||
29AD96601D0A57F800C4DFE7 /* error.h */,
|
||||
29D009A81B7E39A8000CE58C /* foreign_class.c */,
|
||||
29D009A91B7E39A8000CE58C /* foreign_class.h */,
|
||||
2949AA8B1C2F14F000B106BA /* get_variable.c */,
|
||||
@ -405,6 +410,8 @@
|
||||
29D025E61C19CD1000A3BB28 /* os.wren.inc in Sources */,
|
||||
29DC14A91BBA302F008A8274 /* wren_vm.c in Sources */,
|
||||
29DC14AA1BBA3032008A8274 /* main.c in Sources */,
|
||||
293B25581CEFD8C7005D9537 /* repl.c in Sources */,
|
||||
29AD96611D0A57F800C4DFE7 /* error.c in Sources */,
|
||||
293D46961BB43F9900200083 /* call.c in Sources */,
|
||||
29A427351BDBE435001E6E22 /* wren_opt_meta.c in Sources */,
|
||||
29DC14AB1BBA3038008A8274 /* foreign_class.c in Sources */,
|
||||
|
||||
Reference in New Issue
Block a user