mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-12 06:38:45 +01:00
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:
@ -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);
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -186,6 +186,7 @@ struct WrenVM
|
||||
Value unsupported;
|
||||
|
||||
SymbolTable globalSymbols;
|
||||
|
||||
// TODO(bob): Using a fixed array is gross here.
|
||||
Value globals[MAX_SYMBOLS];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user