From 42b04c6c902fd39bf191e8d18b1bf0fababae409 Mon Sep 17 00:00:00 2001 From: Bob Nystrom Date: Sat, 7 Dec 2013 18:47:40 -0800 Subject: [PATCH] Fix bug in loops. It was still popping the stack for the body even though loop bodies are statements now. --- src/wren_core.c | 7 +++++++ src/wren_vm.c | 7 ++----- src/wren_vm.h | 1 + 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/wren_core.c b/src/wren_core.c index a5bee0f1..b0f9974b 100644 --- a/src/wren_core.c +++ b/src/wren_core.c @@ -212,6 +212,12 @@ DEF_NATIVE(list_subscript) return list->elements[index]; } +DEF_NATIVE(null_toString) +{ + // TODO(bob): Intern this string or something. + return wrenNewString(vm, "null", 4); +} + DEF_NATIVE(num_abs) { return NUM_VAL(fabs(AS_NUM(args[0]))); @@ -471,6 +477,7 @@ void wrenInitializeCore(WrenVM* vm) NATIVE(vm->listClass, "[ ]", list_subscript); vm->nullClass = defineClass(vm, "Null", vm->objectClass); + NATIVE(vm->nullClass, "toString", null_toString); vm->numClass = defineClass(vm, "Num", vm->objectClass); NATIVE(vm->numClass, "abs", num_abs); diff --git a/src/wren_vm.c b/src/wren_vm.c index 08deb00e..64a9c048 100644 --- a/src/wren_vm.c +++ b/src/wren_vm.c @@ -5,8 +5,9 @@ #include "wren.h" #include "wren_common.h" #include "wren_compiler.h" -#include "wren_vm.h" #include "wren_core.h" +#include "wren_vm.h" +#include "wren_debug.h" WrenVM* wrenNewVM(WrenReallocateFn reallocateFn) { @@ -939,10 +940,6 @@ Value interpret(WrenVM* vm, Value function) CASE_CODE(LOOP): { - // The loop body's result is on the top of the stack. Since we are - // looping and running the body again, discard it. - POP(); - // Jump back to the top of the loop. int offset = READ_ARG(); ip -= offset; diff --git a/src/wren_vm.h b/src/wren_vm.h index 8be7b6c9..154c3d06 100644 --- a/src/wren_vm.h +++ b/src/wren_vm.h @@ -186,6 +186,7 @@ struct WrenVM Value unsupported; SymbolTable globalSymbols; + // TODO(bob): Using a fixed array is gross here. Value globals[MAX_SYMBOLS];