Skip to content

Commit

Permalink
reorder bytecode operators in vm in same order they are listed in enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Holodome committed Oct 18, 2023
1 parent f0da80d commit 4ace44b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ifneq (,$(COV))
endif

DEPFLAGS = -MT $@ -MMD -MP -MF build/$*.d
CFLAGS += -std=c99 -Ihololisp -pedantic -Wshadow -Wextra -Wall -Werror -Wno-gnu-label-as-value
CFLAGS += -std=c99 -Ihololisp -Wshadow -Wextra -Wall -Werror -Wno-gnu-label-as-value

ifneq (,$(ASAN))
CFLAGS += -fsanitize=address
Expand Down
48 changes: 24 additions & 24 deletions hololisp/hll_vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,6 @@ hll_value hll_interpret_bytecode_internal(hll_vm *vm, hll_value env_,
current_call_frame = &hll_sb_last(vm->call_stack);
HLL_VM_NEXT();
}
HLL_VM_CASE(HLL_BC_POP) {
assert(hll_sb_len(vm->stack) != 0);
(void)hll_sb_pop(vm->stack);
HLL_VM_NEXT();
}
HLL_VM_CASE(HLL_BC_NIL) {
hll_sb_push(vm->stack, hll_nil());
HLL_VM_NEXT();
Expand Down Expand Up @@ -362,6 +357,11 @@ hll_value hll_interpret_bytecode_internal(hll_vm *vm, hll_value env_,
hll_gc_pop_temp_root(vm->gc); // obj
HLL_VM_NEXT();
}
HLL_VM_CASE(HLL_BC_POP) {
assert(hll_sb_len(vm->stack) != 0);
(void)hll_sb_pop(vm->stack);
HLL_VM_NEXT();
}
HLL_VM_CASE(HLL_BC_FIND) {
hll_value symb = hll_sb_pop(vm->stack);
hll_gc_push_temp_root(vm->gc, symb);
Expand All @@ -381,40 +381,25 @@ hll_value hll_interpret_bytecode_internal(hll_vm *vm, hll_value env_,
hll_sb_push(vm->stack, found);
HLL_VM_NEXT();
}
HLL_VM_CASE(HLL_BC_MAKEFUN) {
uint16_t idx =
(current_call_frame->ip[0] << 8) | current_call_frame->ip[1];
current_call_frame->ip += 2;
assert(idx < hll_sb_len(current_call_frame->bytecode->constant_pool));

hll_value value = current_call_frame->bytecode->constant_pool[idx];
assert(hll_get_value_kind(value) == HLL_VALUE_FUNC);
value = hll_new_func(vm, hll_unwrap_func(value)->param_names,
hll_unwrap_func(value)->bytecode);
hll_unwrap_func(value)->env = vm->env;

hll_sb_push(vm->stack, value);
HLL_VM_NEXT();
}
HLL_VM_CASE(HLL_BC_MBTRCALL) {
HLL_VM_CASE(HLL_BC_CALL) {
hll_value args = hll_sb_pop(vm->stack);
hll_gc_push_temp_root(vm->gc, args);
hll_value callable = hll_sb_pop(vm->stack);
hll_gc_push_temp_root(vm->gc, callable);

call_func(vm, callable, args, &current_call_frame, true);
call_func(vm, callable, args, &current_call_frame, false);

hll_gc_pop_temp_root(vm->gc); // args
hll_gc_pop_temp_root(vm->gc); // callable
HLL_VM_NEXT();
}
HLL_VM_CASE(HLL_BC_CALL) {
HLL_VM_CASE(HLL_BC_MBTRCALL) {
hll_value args = hll_sb_pop(vm->stack);
hll_gc_push_temp_root(vm->gc, args);
hll_value callable = hll_sb_pop(vm->stack);
hll_gc_push_temp_root(vm->gc, callable);

call_func(vm, callable, args, &current_call_frame, false);
call_func(vm, callable, args, &current_call_frame, true);

hll_gc_pop_temp_root(vm->gc); // args
hll_gc_pop_temp_root(vm->gc); // callable
Expand Down Expand Up @@ -491,6 +476,21 @@ hll_value hll_interpret_bytecode_internal(hll_vm *vm, hll_value env_,
hll_gc_pop_temp_root(vm->gc); // cdr
HLL_VM_NEXT();
}
HLL_VM_CASE(HLL_BC_MAKEFUN) {
uint16_t idx =
(current_call_frame->ip[0] << 8) | current_call_frame->ip[1];
current_call_frame->ip += 2;
assert(idx < hll_sb_len(current_call_frame->bytecode->constant_pool));

hll_value value = current_call_frame->bytecode->constant_pool[idx];
assert(hll_get_value_kind(value) == HLL_VALUE_FUNC);
value = hll_new_func(vm, hll_unwrap_func(value)->param_names,
hll_unwrap_func(value)->bytecode);
hll_unwrap_func(value)->env = vm->env;

hll_sb_push(vm->stack, value);
HLL_VM_NEXT();
}
}

hll_value result;
Expand Down

0 comments on commit 4ace44b

Please sign in to comment.