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

@@ -24,7 +24,7 @@ struct l2_vm_value {
};
};

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

struct l2_vm_buffer {
size_t len;

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

@@ -42,7 +42,7 @@ static void gc_mark(struct l2_vm *vm, l2_word id) {
struct l2_vm_value *val = &vm->values[id];
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) {
gc_mark_array(vm, val);
} else if (typ == L2_VAL_TYPE_NAMESPACE) {
@@ -82,7 +82,7 @@ static void gc_free(struct l2_vm *vm, l2_word id) {
struct l2_vm_value *val = &vm->values[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) {
free(val->data);
// Don't need to do anything more; the next round of GC will free
@@ -127,7 +127,7 @@ void l2_vm_init(struct l2_vm *vm, l2_word *ops, size_t opcount) {
}

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) {
if (!l2_bitset_get(&vm->valueset, i)) {
continue;

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

@@ -44,7 +44,7 @@ describe(parse) {

l2_vm_init(&vm, (l2_word *)w.mem, w.len / sizeof(l2_word));
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);
}
}

Loading…
Cancel
Save