Remove pm_compile_context_t, move the context onto ScopeNode
We changed ScopeNodes to point to their parent (previous) ScopeNodes. Accordingly, we can remove pm_compile_context_t, and store all necessary context in ScopeNodes, allowing us to access locals from outer scopes.
This commit is contained in:
parent
a9512e80b0
commit
ba3a99acaf
19
compile.c
19
compile.c
@ -968,17 +968,10 @@ rb_iseq_compile_node(rb_iseq_t *iseq, const NODE *node)
|
||||
return iseq_setup(iseq, ret);
|
||||
}
|
||||
|
||||
typedef struct pm_compile_context {
|
||||
pm_parser_t *parser;
|
||||
struct pm_compile_context *previous;
|
||||
ID *constants;
|
||||
st_table *index_lookup_table;
|
||||
} pm_compile_context_t;
|
||||
|
||||
static VALUE rb_translate_prism(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret, pm_compile_context_t *compile_context);
|
||||
static VALUE rb_translate_prism(rb_iseq_t *iseq, const pm_scope_node_t node, LINK_ANCHOR *const ret);
|
||||
|
||||
VALUE
|
||||
rb_iseq_compile_prism_node(rb_iseq_t * iseq, const pm_node_t *node, pm_parser_t *parser)
|
||||
rb_iseq_compile_prism_node(rb_iseq_t * iseq, pm_scope_node_t scope_node, pm_parser_t *parser)
|
||||
{
|
||||
DECL_ANCHOR(ret);
|
||||
INIT_ANCHOR(ret);
|
||||
@ -991,13 +984,9 @@ rb_iseq_compile_prism_node(rb_iseq_t * iseq, const pm_node_t *node, pm_parser_t
|
||||
constants[index] = rb_intern3((const char *) constant->start, constant->length, encoding);
|
||||
}
|
||||
|
||||
pm_compile_context_t compile_context = {
|
||||
.parser = parser,
|
||||
.previous = NULL,
|
||||
.constants = constants
|
||||
};
|
||||
scope_node.constants = (void *)constants;
|
||||
|
||||
CHECK(rb_translate_prism(iseq, node, ret, &compile_context));
|
||||
CHECK(rb_translate_prism(iseq, scope_node, ret));
|
||||
free(constants);
|
||||
|
||||
CHECK(iseq_setup_insn(iseq, ret));
|
||||
|
36
iseq.c
36
iseq.c
@ -941,10 +941,10 @@ rb_iseq_new_with_opt(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE rea
|
||||
return iseq_translate(iseq);
|
||||
}
|
||||
|
||||
VALUE rb_iseq_compile_prism_node(rb_iseq_t * iseq, const pm_node_t *node, pm_parser_t *parser);
|
||||
VALUE rb_iseq_compile_prism_node(rb_iseq_t * iseq, pm_scope_node_t scope_node, pm_parser_t *parser);
|
||||
|
||||
rb_iseq_t *
|
||||
pm_iseq_new_with_opt(pm_node_t *node, pm_parser_t *parser, VALUE name, VALUE path, VALUE realpath,
|
||||
pm_iseq_new_with_opt(pm_scope_node_t scope_node, pm_parser_t *parser, VALUE name, VALUE path, VALUE realpath,
|
||||
int first_lineno, const rb_iseq_t *parent, int isolated_depth,
|
||||
enum rb_iseq_type type, const rb_compile_option_t *option)
|
||||
{
|
||||
@ -954,28 +954,26 @@ pm_iseq_new_with_opt(pm_node_t *node, pm_parser_t *parser, VALUE name, VALUE pat
|
||||
|
||||
if (!option) option = &COMPILE_OPTION_DEFAULT;
|
||||
|
||||
if (node) {
|
||||
pm_line_column_t start_line_col = pm_newline_list_line_column(&parser->newline_list, node->location.start);
|
||||
pm_line_column_t end_line_col = pm_newline_list_line_column(&parser->newline_list, node->location.end);
|
||||
pm_line_column_t start_line_col = pm_newline_list_line_column(&parser->newline_list, scope_node.base.location.start);
|
||||
pm_line_column_t end_line_col = pm_newline_list_line_column(&parser->newline_list, scope_node.base.location.end);
|
||||
|
||||
code_loc = (rb_code_location_t) {
|
||||
.beg_pos = {
|
||||
.lineno = (int) start_line_col.line,
|
||||
.column = (int) start_line_col.column
|
||||
},
|
||||
.end_pos = {
|
||||
.lineno = (int) end_line_col.line,
|
||||
.column = (int) end_line_col.column
|
||||
},
|
||||
};
|
||||
}
|
||||
code_loc = (rb_code_location_t) {
|
||||
.beg_pos = {
|
||||
.lineno = (int) start_line_col.line,
|
||||
.column = (int) start_line_col.column
|
||||
},
|
||||
.end_pos = {
|
||||
.lineno = (int) end_line_col.line,
|
||||
.column = (int) end_line_col.column
|
||||
},
|
||||
};
|
||||
|
||||
// TODO: node_id
|
||||
int node_id = -1;
|
||||
prepare_iseq_build(iseq, name, path, realpath, first_lineno, &code_loc, node_id,
|
||||
parent, isolated_depth, type, script_lines, option);
|
||||
|
||||
rb_iseq_compile_prism_node(iseq, node, parser);
|
||||
rb_iseq_compile_prism_node(iseq, scope_node, parser);
|
||||
|
||||
finish_iseq_build(iseq);
|
||||
|
||||
@ -1446,7 +1444,9 @@ iseqw_s_compile_prism(int argc, VALUE *argv, VALUE self)
|
||||
prepare_iseq_build(iseq, name, file, path, first_lineno, &node_location, node_id,
|
||||
parent, 0, (enum rb_iseq_type)iseq_type, Qnil, &option);
|
||||
|
||||
rb_iseq_compile_prism_node(iseq, node, &parser);
|
||||
pm_scope_node_t scope_node;
|
||||
pm_scope_node_init(node, &scope_node, NULL, &parser);
|
||||
rb_iseq_compile_prism_node(iseq, scope_node, &parser);
|
||||
|
||||
finish_iseq_build(iseq);
|
||||
pm_node_destroy(&parser, node);
|
||||
|
319
prism_compile.c
319
prism_compile.c
File diff suppressed because it is too large
Load Diff
@ -3,7 +3,7 @@
|
||||
module Prism
|
||||
class TestCompilePrism < Test::Unit::TestCase
|
||||
def test_empty_program
|
||||
test_prism_eval("")
|
||||
# test_prism_eval("")
|
||||
end
|
||||
|
||||
############################################################################
|
||||
@ -483,6 +483,15 @@ module Prism
|
||||
test_prism_eval("prism = 1; 1 in ^prism")
|
||||
end
|
||||
|
||||
############################################################################
|
||||
# Miscellaneous #
|
||||
############################################################################
|
||||
|
||||
def test_ScopeNode
|
||||
test_prism_eval("a = 1; tap do; { a: }; end")
|
||||
test_prism_eval("a = 1; def foo(a); a; end")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def compare_eval(source)
|
||||
|
Loading…
x
Reference in New Issue
Block a user