Skip to content

Commit

Permalink
Compile echo tag to VM code
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanahsmith committed Dec 18, 2020
1 parent 8655f00 commit fcbd69b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ext/liquid_c/block.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,8 @@ static VALUE block_body_add_write_raw(VALUE self, VALUE string)
{
block_body_t *body;
BlockBody_Get_Struct(self, body);
vm_assembler_add_write_raw_from_ruby(&body->code, string);
ensure_intermediate(body);
vm_assembler_add_write_raw_from_ruby(body->as.intermediate.code, string);
return self;
}

Expand Down
27 changes: 27 additions & 0 deletions ext/liquid_c/tag.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "liquid.h"
#include "vm_assembler.h"
#include "block.h"
#include "tokenizer.h"
#include "variable.h"

static ID id_parse;

Expand Down Expand Up @@ -29,10 +31,32 @@ static VALUE tag_compile(VALUE self, VALUE block_body_obj)
{
block_body_t *body;
BlockBody_Get_Struct(block_body_obj, body);
block_body_ensure_intermediate(body);
vm_assembler_add_write_node_from_ruby(body->as.intermediate.code, self);
return Qnil;
}

static VALUE echo_class_compile(VALUE klass, VALUE tag_name, VALUE markup,
VALUE tokenizer_obj, VALUE parse_context_obj, VALUE block_body_obj)
{
block_body_t *body;
BlockBody_Get_Struct(block_body_obj, body);
block_body_ensure_intermediate(body);

tokenizer_t *tokenizer;
Tokenizer_Get_Struct(tokenizer_obj, tokenizer);

variable_parse_args_t parse_args = {
.markup = RSTRING_PTR(markup),
.markup_end = RSTRING_PTR(markup) + RSTRING_LEN(markup),
.code = body->as.intermediate.code,
.code_obj = block_body_obj,
.parse_context = parse_context_obj,
};
internal_variable_compile(&parse_args, tokenizer->line_number);
return Qnil;
}

void liquid_define_tag()
{
id_parse = rb_intern("parse");
Expand All @@ -42,4 +66,7 @@ void liquid_define_tag()

rb_define_singleton_method(cLiquidTag, "compile", tag_class_compile, 5);
rb_define_method(cLiquidTag, "compile", tag_compile, 1);

VALUE cLiquidEcho = rb_const_get(mLiquid, rb_intern("Echo"));
rb_define_singleton_method(cLiquidEcho, "compile", echo_class_compile, 5);
}

0 comments on commit fcbd69b

Please sign in to comment.