De-inline wrenHasError.

Move fiber error detection inside a function instead of using inlined
version everywhere.
This commit is contained in:
Michel Hermier
2018-07-19 17:57:51 +02:00
parent 0ebf4e1277
commit 051e224ce6
3 changed files with 17 additions and 12 deletions

View File

@ -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;
}

View File

@ -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,

View File

@ -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));
@ -1003,14 +1003,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:
@ -1232,14 +1232,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();
}
@ -1250,7 +1250,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();
@ -1270,7 +1270,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()))
@ -1295,7 +1295,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();