Skip to content

Commit

Permalink
refactor to check if instruction has a constant
Browse files Browse the repository at this point in the history
  • Loading branch information
ggmichaelgo committed Nov 6, 2021
1 parent 70b1754 commit 00fc47a
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions ext/liquid_c/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,11 @@ static VALUE vm_render_until_error(VALUE uncast_args)
const uint8_t *ip = args->ip;
vm_t *vm = args->vm;
VALUE output = args->output;
uint16_t constant_index;
VALUE constant = Qnil;
args->ip = NULL; // used by vm_render_rescue, NULL to indicate that it isn't in a rescue block

while (true) {
if (vm_assembler_opcode_has_constant(*ip)) {
uint16_t constant_index = (ip[1] << 8) | ip[2];
constant = constants[constant_index];
}

switch (*ip++) {
case OP_LEAVE:
return false;
Expand Down Expand Up @@ -271,6 +267,8 @@ static VALUE vm_render_until_error(VALUE uncast_args)
}
case OP_FIND_STATIC_VAR:
{
constant_index = (ip[0] << 8) | ip[1];
constant = constants[constant_index];
ip += 2;
VALUE value = context_find_variable(&vm->context, constant, Qtrue);
vm_stack_push(vm, value);
Expand All @@ -286,6 +284,8 @@ static VALUE vm_render_until_error(VALUE uncast_args)
case OP_LOOKUP_CONST_KEY:
case OP_LOOKUP_COMMAND:
{
constant_index = (ip[0] << 8) | ip[1];
constant = constants[constant_index];
ip += 2;
vm_stack_push(vm, constant);
}
Expand Down Expand Up @@ -325,6 +325,8 @@ static VALUE vm_render_until_error(VALUE uncast_args)
uint8_t num_args;

if (ip[-1] == OP_FILTER) {
constant_index = (ip[0] << 8) | ip[1];
constant = constants[constant_index];
filter_name = RARRAY_AREF(constant, 0);
num_args = RARRAY_AREF(constant, 1);
ip += 2;
Expand Down Expand Up @@ -376,13 +378,17 @@ static VALUE vm_render_until_error(VALUE uncast_args)

case OP_PUSH_CONST:
{
constant_index = (ip[0] << 8) | ip[1];
constant = constants[constant_index];
ip += 2;
vm_stack_push(vm, constant);
break;
}

case OP_WRITE_NODE:
{
constant_index = (ip[0] << 8) | ip[1];
constant = constants[constant_index];
ip += 2;
rb_funcall(cLiquidBlockBody, id_render_node, 3, vm->context.self, output, constant);

Expand Down

0 comments on commit 00fc47a

Please sign in to comment.