1
0
forked from Mirror/wren

Fix bug in loops.

It was still popping the stack for the body even though loop
bodies are statements now.
This commit is contained in:
Bob Nystrom
2013-12-07 18:47:40 -08:00
parent eb1e5b48d6
commit 42b04c6c90
3 changed files with 10 additions and 5 deletions

View File

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

View File

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

View File

@ -186,6 +186,7 @@ struct WrenVM
Value unsupported;
SymbolTable globalSymbols;
// TODO(bob): Using a fixed array is gross here.
Value globals[MAX_SYMBOLS];