Class: Liquid::C::Expression

Inherits:
Object
  • Object
show all
Defined in:
ext/liquid_c/expression.c

Direct Known Subclasses

VariableExpression

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.strict_parse(markup) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'ext/liquid_c/expression.c', line 63

static VALUE expression_strict_parse(VALUE klass, VALUE markup)
{
    if (NIL_P(markup))
        return Qnil;

    StringValue(markup);
    char *start = RSTRING_PTR(markup);

    parser_t p;
    init_parser(&p, start, start + RSTRING_LEN(markup));
    VALUE expr_obj = internal_expression_parse(&p);

    if (p.cur.type != TOKEN_EOS)
        rb_enc_raise(utf8_encoding, cLiquidSyntaxError, "[:%s] is not a valid expression", symbol_names[p.cur.type]);

    return expr_obj;
}

Instance Method Details

#disassembleObject



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'ext/liquid_c/expression.c', line 93

static VALUE expression_disassemble(VALUE self)
{
    expression_t *expression;
    Expression_Get_Struct(self, expression);

    VALUE constants = rb_ary_new();
    uint32_t constants_len = (uint32_t)(c_buffer_size(&expression->code.constants) / sizeof(VALUE));
    rb_ary_cat(constants, (VALUE *)expression->code.constants.data, constants_len);

    return vm_assembler_disassemble(
        expression->code.instructions.data,
        expression->code.instructions.data_end,
        &constants
    );
}

#evaluate(context) ⇒ Object



81
82
83
84
85
86
# File 'ext/liquid_c/expression.c', line 81

VALUE expression_evaluate(VALUE self, VALUE context)
{
    expression_t *expression;
    Expression_Get_Struct(self, expression);
    return liquid_vm_evaluate(context, &expression->code);
}