Browse Source

make l2_vm_value_type take pointer

master
Martin Dørum 3 years ago
parent
commit
b6b283b7a1
3 changed files with 5 additions and 5 deletions
  1. 1
    1
      include/lang2/vm/vm.h
  2. 3
    3
      lib/vm/vm.c
  3. 1
    1
      test/src/eval.t.c

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

}; };
}; };


#define l2_vm_value_type(val) ((val).flags & 0x0f)
#define l2_vm_value_type(val) ((val)->flags & 0x0f)


struct l2_vm_buffer { struct l2_vm_buffer {
size_t len; size_t len;

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

struct l2_vm_value *val = &vm->values[id]; struct l2_vm_value *val = &vm->values[id];
val->flags |= L2_VAL_MARKED; val->flags |= L2_VAL_MARKED;


int typ = l2_vm_value_type(*val);
int typ = l2_vm_value_type(val);
if (typ == L2_VAL_TYPE_ARRAY) { if (typ == L2_VAL_TYPE_ARRAY) {
gc_mark_array(vm, val); gc_mark_array(vm, val);
} else if (typ == L2_VAL_TYPE_NAMESPACE) { } else if (typ == L2_VAL_TYPE_NAMESPACE) {
struct l2_vm_value *val = &vm->values[id]; struct l2_vm_value *val = &vm->values[id];
l2_bitset_unset(&vm->valueset, id); l2_bitset_unset(&vm->valueset, id);


int typ = l2_vm_value_type(*val);
int typ = l2_vm_value_type(val);
if (typ == L2_VAL_TYPE_ARRAY || typ == L2_VAL_TYPE_BUFFER || typ == L2_VAL_TYPE_NAMESPACE) { if (typ == L2_VAL_TYPE_ARRAY || typ == L2_VAL_TYPE_BUFFER || typ == L2_VAL_TYPE_NAMESPACE) {
free(val->data); free(val->data);
// Don't need to do anything more; the next round of GC will free // Don't need to do anything more; the next round of GC will free
} }


void l2_vm_free(struct l2_vm *vm) { void l2_vm_free(struct l2_vm *vm) {
// Skip ID 0, because that should always exist
// Skip ID 0, because that's always NONE
for (size_t i = 1; i < vm->valuessize; ++i) { for (size_t i = 1; i < vm->valuessize; ++i) {
if (!l2_bitset_get(&vm->valueset, i)) { if (!l2_bitset_get(&vm->valueset, i)) {
continue; continue;

+ 1
- 1
test/src/eval.t.c View File



l2_vm_init(&vm, (l2_word *)w.mem, w.len / sizeof(l2_word)); l2_vm_init(&vm, (l2_word *)w.mem, w.len / sizeof(l2_word));
l2_vm_run(&vm); l2_vm_run(&vm);
assert(l2_vm_value_type(*var_lookup("foo")) == L2_VAL_TYPE_REAL);
assert(l2_vm_value_type(var_lookup("foo")) == L2_VAL_TYPE_REAL);
assert(var_lookup("foo")->real == 10); assert(var_lookup("foo")->real == 10);
} }
} }

Loading…
Cancel
Save