forked from Mirror/wren
Merge branch 'wrenHasError' of https://github.com/mhermier/canary into mhermier-wrenHasError
This commit is contained in:
1
AUTHORS
1
AUTHORS
@ -23,3 +23,4 @@ Kyle Charters <kylewcharters@gmail.com>
|
||||
Marshall Bowers <elliott.codes@gmail.com>
|
||||
Michal Kozakiewicz <michalkozakiewicz3@gmail.com>
|
||||
Charlotte Koch <cfkoch@edgebsd.org>
|
||||
Michel Hermier <michel.hermier@gmail.com>
|
||||
|
||||
@ -81,7 +81,7 @@ static bool runFiber(WrenVM* vm, ObjFiber* fiber, Value* args, bool isCall,
|
||||
bool hasValue, const char* verb)
|
||||
{
|
||||
|
||||
if (!IS_NULL(fiber->error))
|
||||
if (wrenHasError(fiber))
|
||||
{
|
||||
RETURN_ERROR_FMT("Cannot $ an aborted fiber.", verb);
|
||||
}
|
||||
@ -154,7 +154,7 @@ DEF_PRIMITIVE(fiber_error)
|
||||
DEF_PRIMITIVE(fiber_isDone)
|
||||
{
|
||||
ObjFiber* runFiber = AS_FIBER(args[0]);
|
||||
RETURN_BOOL(runFiber->numFrames == 0 || !IS_NULL(runFiber->error));
|
||||
RETURN_BOOL(runFiber->numFrames == 0 || wrenHasError(runFiber));
|
||||
}
|
||||
|
||||
DEF_PRIMITIVE(fiber_suspend)
|
||||
@ -187,7 +187,7 @@ DEF_PRIMITIVE(fiber_try)
|
||||
runFiber(vm, AS_FIBER(args[0]), args, true, false, "try");
|
||||
|
||||
// If we're switching to a valid fiber to try, remember that we're trying it.
|
||||
if (IS_NULL(vm->fiber->error)) vm->fiber->state = FIBER_TRY;
|
||||
if (!wrenHasError(vm->fiber)) vm->fiber->state = FIBER_TRY;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -239,15 +239,10 @@ static const char* coreModuleSource =
|
||||
" }\n"
|
||||
"\n"
|
||||
" trim() { trim_(\"\t\r\n \", true, true) }\n"
|
||||
"\n"
|
||||
" trim(chars) { trim_(chars, true, true) }\n"
|
||||
"\n"
|
||||
" trimEnd() { trim_(\"\t\r\n \", false, true) }\n"
|
||||
"\n"
|
||||
" trimEnd(chars) { trim_(chars, false, true) }\n"
|
||||
"\n"
|
||||
" trimStart() { trim_(\"\t\r\n \", true, false) }\n"
|
||||
"\n"
|
||||
" trimStart(chars) { trim_(chars, true, false) }\n"
|
||||
"\n"
|
||||
" trim_(chars, trimStart, trimEnd) {\n"
|
||||
@ -256,7 +251,6 @@ static const char* coreModuleSource =
|
||||
" }\n"
|
||||
"\n"
|
||||
" var codePoints = chars.codePoints.toList\n"
|
||||
"// System.print(\"code points %(codePoints)\")\n"
|
||||
"\n"
|
||||
" var start\n"
|
||||
" if (trimStart) {\n"
|
||||
@ -274,12 +268,10 @@ static const char* coreModuleSource =
|
||||
" end = byteCount_ - 1\n"
|
||||
" while (end >= start) {\n"
|
||||
" var codePoint = codePointAt_(end)\n"
|
||||
"// System.print(\"test %(end) : %(codePoint)\")\n"
|
||||
" if (codePoint != -1 && !codePoints.contains(codePoint)) break\n"
|
||||
" end = end - 1\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
"// System.print(\"range %(start) %(end)\")\n"
|
||||
" if (end < start) return \"\"\n"
|
||||
" } else {\n"
|
||||
" end = -1\n"
|
||||
|
||||
@ -657,6 +657,11 @@ static inline void wrenAppendCallFrame(WrenVM* vm, ObjFiber* fiber,
|
||||
// Ensures [fiber]'s stack has at least [needed] slots.
|
||||
void wrenEnsureStack(WrenVM* vm, ObjFiber* fiber, int needed);
|
||||
|
||||
static inline bool wrenHasError(const ObjFiber* fiber)
|
||||
{
|
||||
return !IS_NULL(fiber->error);
|
||||
}
|
||||
|
||||
ObjForeign* wrenNewForeign(WrenVM* vm, ObjClass* classObj, size_t size);
|
||||
|
||||
// Creates a new empty function. Before being used, it must have code,
|
||||
|
||||
@ -388,7 +388,7 @@ static void callForeign(WrenVM* vm, ObjFiber* fiber,
|
||||
// handles the error. If none do, tells the VM to stop.
|
||||
static void runtimeError(WrenVM* vm)
|
||||
{
|
||||
ASSERT(!IS_NULL(vm->fiber->error), "Should only call this after an error.");
|
||||
ASSERT(wrenHasError(vm->fiber), "Should only call this after an error.");
|
||||
|
||||
ObjFiber* current = vm->fiber;
|
||||
Value error = current->error;
|
||||
@ -601,7 +601,7 @@ static void createClass(WrenVM* vm, int numFields, ObjModule* module)
|
||||
vm->fiber->stackTop--;
|
||||
|
||||
vm->fiber->error = validateSuperclass(vm, name, superclass, numFields);
|
||||
if (!IS_NULL(vm->fiber->error)) return;
|
||||
if (wrenHasError(vm->fiber)) return;
|
||||
|
||||
ObjClass* classObj = wrenNewClass(vm, AS_CLASS(superclass), numFields,
|
||||
AS_STRING(name));
|
||||
@ -1002,14 +1002,14 @@ static WrenInterpretResult runInterpreter(WrenVM* vm, register ObjFiber* fiber)
|
||||
// If we don't have a fiber to switch to, stop interpreting.
|
||||
fiber = vm->fiber;
|
||||
if (fiber == NULL) return WREN_RESULT_SUCCESS;
|
||||
if (!IS_NULL(fiber->error)) RUNTIME_ERROR();
|
||||
if (wrenHasError(fiber)) RUNTIME_ERROR();
|
||||
LOAD_FRAME();
|
||||
}
|
||||
break;
|
||||
|
||||
case METHOD_FOREIGN:
|
||||
callForeign(vm, fiber, method->as.foreign, numArgs);
|
||||
if (!IS_NULL(fiber->error)) RUNTIME_ERROR();
|
||||
if (wrenHasError(fiber)) RUNTIME_ERROR();
|
||||
break;
|
||||
|
||||
case METHOD_BLOCK:
|
||||
@ -1231,14 +1231,14 @@ static WrenInterpretResult runInterpreter(WrenVM* vm, register ObjFiber* fiber)
|
||||
CASE_CODE(CLASS):
|
||||
{
|
||||
createClass(vm, READ_BYTE(), NULL);
|
||||
if (!IS_NULL(fiber->error)) RUNTIME_ERROR();
|
||||
if (wrenHasError(fiber)) RUNTIME_ERROR();
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
CASE_CODE(FOREIGN_CLASS):
|
||||
{
|
||||
createClass(vm, -1, fn->module);
|
||||
if (!IS_NULL(fiber->error)) RUNTIME_ERROR();
|
||||
if (wrenHasError(fiber)) RUNTIME_ERROR();
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
@ -1249,7 +1249,7 @@ static WrenInterpretResult runInterpreter(WrenVM* vm, register ObjFiber* fiber)
|
||||
ObjClass* classObj = AS_CLASS(PEEK());
|
||||
Value method = PEEK2();
|
||||
bindMethod(vm, instruction, symbol, fn->module, classObj, method);
|
||||
if (!IS_NULL(fiber->error)) RUNTIME_ERROR();
|
||||
if (wrenHasError(fiber)) RUNTIME_ERROR();
|
||||
DROP();
|
||||
DROP();
|
||||
DISPATCH();
|
||||
@ -1269,7 +1269,7 @@ static WrenInterpretResult runInterpreter(WrenVM* vm, register ObjFiber* fiber)
|
||||
// imported module's closure in the slot in case a GC happens when
|
||||
// invoking the closure.
|
||||
PUSH(importModule(vm, fn->constants.data[READ_SHORT()]));
|
||||
if (!IS_NULL(fiber->error)) RUNTIME_ERROR();
|
||||
if (wrenHasError(fiber)) RUNTIME_ERROR();
|
||||
|
||||
// If we get a closure, call it to execute the module body.
|
||||
if (IS_CLOSURE(PEEK()))
|
||||
@ -1294,7 +1294,7 @@ static WrenInterpretResult runInterpreter(WrenVM* vm, register ObjFiber* fiber)
|
||||
Value variable = fn->constants.data[READ_SHORT()];
|
||||
ASSERT(vm->lastModule != NULL, "Should have already imported module.");
|
||||
Value result = getModuleVariable(vm, vm->lastModule, variable);
|
||||
if (!IS_NULL(fiber->error)) RUNTIME_ERROR();
|
||||
if (wrenHasError(fiber)) RUNTIME_ERROR();
|
||||
|
||||
PUSH(result);
|
||||
DISPATCH();
|
||||
|
||||
Reference in New Issue
Block a user