Browse Source

change how loop works

master
Martin Dørum 7 months ago
parent
commit
39c00b7535
3 changed files with 6 additions and 4 deletions
  1. 1
    0
      include/lang2/builtins.x.h
  2. 1
    1
      include/lang2/vm/vm.h
  3. 4
    3
      lib/vm/builtins.c

+ 1
- 0
include/lang2/builtins.x.h View File

@@ -7,6 +7,7 @@ XNAME("none", knone)
#ifdef XATOM
XATOM("true", ktrue)
XATOM("false", kfalse)
XATOM("stop", kstop)
#endif

#ifdef XFUNCTION

+ 1
- 1
include/lang2/vm/vm.h View File

@@ -122,7 +122,7 @@ struct l2_vm {
struct l2_vm_stack_frame fstack[1024];
l2_word fsptr;

l2_word knone, ktrue, kfalse;
l2_word knone, ktrue, kfalse, kstop;
l2_word gc_start;
};


+ 4
- 3
lib/vm/builtins.c View File

@@ -298,11 +298,12 @@ struct loop_context {
};

static l2_word loop_callback(struct l2_vm *vm, l2_word retval, l2_word cont) {
if (l2_vm_val_is_true(vm, &vm->values[retval])) {
struct l2_vm_value *val = &vm->values[retval];
if (l2_value_get_type(val) == L2_VAL_TYPE_ATOM && val->atom == vm->values[vm->kstop].atom) {
return vm->knone;
} else {
return cont;
}

return retval;
}

static void loop_marker(

Loading…
Cancel
Save