Skip to content

Commit fcbd69b

Browse files
committed
Compile echo tag to VM code
1 parent 8655f00 commit fcbd69b

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

ext/liquid_c/block.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,8 @@ static VALUE block_body_add_write_raw(VALUE self, VALUE string)
535535
{
536536
block_body_t *body;
537537
BlockBody_Get_Struct(self, body);
538-
vm_assembler_add_write_raw_from_ruby(&body->code, string);
538+
ensure_intermediate(body);
539+
vm_assembler_add_write_raw_from_ruby(body->as.intermediate.code, string);
539540
return self;
540541
}
541542

ext/liquid_c/tag.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "liquid.h"
22
#include "vm_assembler.h"
33
#include "block.h"
4+
#include "tokenizer.h"
5+
#include "variable.h"
46

57
static ID id_parse;
68

@@ -29,10 +31,32 @@ static VALUE tag_compile(VALUE self, VALUE block_body_obj)
2931
{
3032
block_body_t *body;
3133
BlockBody_Get_Struct(block_body_obj, body);
34+
block_body_ensure_intermediate(body);
3235
vm_assembler_add_write_node_from_ruby(body->as.intermediate.code, self);
3336
return Qnil;
3437
}
3538

39+
static VALUE echo_class_compile(VALUE klass, VALUE tag_name, VALUE markup,
40+
VALUE tokenizer_obj, VALUE parse_context_obj, VALUE block_body_obj)
41+
{
42+
block_body_t *body;
43+
BlockBody_Get_Struct(block_body_obj, body);
44+
block_body_ensure_intermediate(body);
45+
46+
tokenizer_t *tokenizer;
47+
Tokenizer_Get_Struct(tokenizer_obj, tokenizer);
48+
49+
variable_parse_args_t parse_args = {
50+
.markup = RSTRING_PTR(markup),
51+
.markup_end = RSTRING_PTR(markup) + RSTRING_LEN(markup),
52+
.code = body->as.intermediate.code,
53+
.code_obj = block_body_obj,
54+
.parse_context = parse_context_obj,
55+
};
56+
internal_variable_compile(&parse_args, tokenizer->line_number);
57+
return Qnil;
58+
}
59+
3660
void liquid_define_tag()
3761
{
3862
id_parse = rb_intern("parse");
@@ -42,4 +66,7 @@ void liquid_define_tag()
4266

4367
rb_define_singleton_method(cLiquidTag, "compile", tag_class_compile, 5);
4468
rb_define_method(cLiquidTag, "compile", tag_compile, 1);
69+
70+
VALUE cLiquidEcho = rb_const_get(mLiquid, rb_intern("Echo"));
71+
rb_define_singleton_method(cLiquidEcho, "compile", echo_class_compile, 5);
4572
}

0 commit comments

Comments
 (0)