diff options
author | Jemma Issroff <[email protected]> | 2023-08-30 17:30:42 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2023-08-30 14:30:42 -0700 |
commit | 36786cc381c118986e66d8c3184e25adbaeaf591 (patch) | |
tree | 8d0680387bb7d9cd4d6512100cbee1e2814eed8f | |
parent | 0ec5021f3d14707d1354158b8dec26ba6e079396 (diff) |
[YARP] Compile ProgramNode as ScopeNode (#8327)
* [YARP] Compile ProgramNode as ScopeNode
Notes
Notes:
Merged-By: jemmaissroff
-rw-r--r-- | test/yarp/compiler_test.rb | 8 | ||||
-rw-r--r-- | yarp/yarp_compiler.c | 7 |
2 files changed, 12 insertions, 3 deletions
diff --git a/test/yarp/compiler_test.rb b/test/yarp/compiler_test.rb index bb1a1f47e8..668908d423 100644 --- a/test/yarp/compiler_test.rb +++ b/test/yarp/compiler_test.rb @@ -69,6 +69,10 @@ module YARP assert_equal 1, compile("class YARP::CompilerTest; @yct = 1; @yct; end") end + def test_LocalVariableReadNode + assert_equal 1, compile("yct = 1; yct") + end + ############################################################################ # Writes # ############################################################################ @@ -93,6 +97,10 @@ module YARP assert_equal 1, compile("class YARP::CompilerTest; @yct = 1; end") end + def test_LocalVariableWriteNode + assert_equal 1, compile("yct = 1") + end + ############################################################################ # String-likes # ############################################################################ diff --git a/yarp/yarp_compiler.c b/yarp/yarp_compiler.c index e75937d689..57638a36fb 100644 --- a/yarp/yarp_compiler.c +++ b/yarp/yarp_compiler.c @@ -1064,13 +1064,15 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, case YP_NODE_PROGRAM_NODE: { yp_program_node_t *program_node = (yp_program_node_t *) node; + yp_scope_node_t scope_node; + yp_scope_node_init((yp_node_t *)node, &scope_node); if (program_node->statements->body.size == 0) { ADD_INSN(ret, &dummy_line_node, putnil); } else { - yp_compile_node(iseq, (yp_node_t *) program_node->statements, ret, src, popped, compile_context); + yp_scope_node_t *res_node = &scope_node; + yp_compile_node(iseq, (yp_node_t *) res_node, ret, src, popped, compile_context); } - ADD_INSN(ret, &dummy_line_node, leave); return; } case YP_NODE_RANGE_NODE: { @@ -1285,7 +1287,6 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret, yp_statements_node_t *statements_node = (yp_statements_node_t *) node; yp_node_list_t node_list = statements_node->body; for (size_t index = 0; index < node_list.size; index++) { - // We only want to have popped == false for the last instruction if (!popped && (index != node_list.size - 1)) { yp_compile_node(iseq, node_list.nodes[index], ret, src, true, compile_context); } |