Define error type enum.
This commit is contained in:
+10
-1
@@ -50,7 +50,13 @@ static int runFile(WrenVM* vm, const char* path)
|
||||
{
|
||||
char* source = readFile(path);
|
||||
|
||||
int result = wrenInterpret(vm, path, source);
|
||||
int result;
|
||||
switch (wrenInterpret(vm, path, source))
|
||||
{
|
||||
case WREN_RESULT_SUCCESS: result = 0; break;
|
||||
case WREN_RESULT_COMPILE_ERROR: result = 65; break; // EX_DATAERR.
|
||||
case WREN_RESULT_RUNTIME_ERROR: result = 70; break; // EX_SOFTWARE.
|
||||
}
|
||||
|
||||
wrenFreeVM(vm);
|
||||
free(source);
|
||||
@@ -60,6 +66,9 @@ static int runFile(WrenVM* vm, const char* path)
|
||||
|
||||
static int runRepl(WrenVM* vm)
|
||||
{
|
||||
printf("\\\\/\"-\n");
|
||||
printf(" \\_/ wren v0.0.0\n");
|
||||
|
||||
for (;;)
|
||||
{
|
||||
printf("> ");
|
||||
|
||||
+11
-12
@@ -1029,25 +1029,24 @@ static bool runInterpreter(WrenVM* vm)
|
||||
ASSERT(0, "Should not reach end of interpret.");
|
||||
}
|
||||
|
||||
int wrenInterpret(WrenVM* vm, const char* sourcePath, const char* source)
|
||||
WrenInterpretResult wrenInterpret(WrenVM* vm, const char* sourcePath,
|
||||
const char* source)
|
||||
{
|
||||
// TODO: Move actual error codes to main.c and return something Wren-specific
|
||||
// from here.
|
||||
int result = 0;
|
||||
ObjFn* fn = wrenCompile(vm, sourcePath, source);
|
||||
if (fn != NULL)
|
||||
{
|
||||
WREN_PIN(vm, fn);
|
||||
vm->fiber = wrenNewFiber(vm, (Obj*)fn);
|
||||
WREN_UNPIN(vm);
|
||||
if (fn == NULL) return WREN_RESULT_COMPILE_ERROR;
|
||||
|
||||
if (!runInterpreter(vm)) result = 70; // EX_SOFTWARE.
|
||||
WREN_PIN(vm, fn);
|
||||
vm->fiber = wrenNewFiber(vm, (Obj*)fn);
|
||||
WREN_UNPIN(vm);
|
||||
|
||||
if (runInterpreter(vm))
|
||||
{
|
||||
return WREN_RESULT_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = 65; // EX_DATAERR.
|
||||
return WREN_RESULT_RUNTIME_ERROR;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void wrenPinObj(WrenVM* vm, Obj* obj, PinnedObj* pinned)
|
||||
|
||||
Reference in New Issue
Block a user