diff options
author | yui-knk <spiketeika@gmail.com> | 2023-08-22 10:26:38 +0900 |
---|---|---|
committer | Yuichiro Kaneko <spiketeika@gmail.com> | 2023-09-28 11:58:10 +0900 |
commit | 74c67811537c0c1840668c218dc0e2510d00b473 (patch) | |
tree | 1f387a71cf9f797217721345e85e098b790187e5 /vm.c | |
parent | 684686a1e14d923b43cfd6c1d5a80222281a4070 (diff) | |
download | ruby-74c67811537c0c1840668c218dc0e2510d00b473.tar.gz |
Change RNode structure from union to struct
All kind of AST nodes use same struct RNode, which has u1, u2, u3 union members
for holding different kind of data.
This has two problems.
1. Low flexibility of data structure
Some nodes, for example NODE_TRUE, don’t use u1, u2, u3. On the other hand,
NODE_OP_ASGN2 needs more than three union members. However they use same
structure definition, need to allocate three union members for NODE_TRUE and
need to separate NODE_OP_ASGN2 into another node.
This change removes the restriction so make it possible to
change data structure by each node type.
2. No compile time check for union member access
It’s developer’s responsibility for using correct member for each node type when it’s union.
This change clarifies which node has which type of fields and enables compile time check.
This commit also changes node_buffer_elem_struct buf management to handle
different size data with alignment.
Diffstat (limited to 'vm.c')
-rw-r--r-- | vm.c | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -1384,7 +1384,7 @@ rb_binding_add_dynavars(VALUE bindval, rb_binding_t *bind, int dyncount, const I rb_execution_context_t *ec = GET_EC(); const rb_iseq_t *base_iseq, *iseq; rb_ast_body_t ast; - NODE tmp_node; + rb_node_scope_t tmp_node; if (dyncount < 0) return 0; @@ -1396,8 +1396,12 @@ rb_binding_add_dynavars(VALUE bindval, rb_binding_t *bind, int dyncount, const I dyns->size = dyncount; MEMCPY(dyns->ids, dynvars, ID, dyncount); - rb_node_init(&tmp_node, NODE_SCOPE, (VALUE)dyns, 0, 0); - ast.root = &tmp_node; + rb_node_init(RNODE(&tmp_node), NODE_SCOPE); + tmp_node.nd_tbl = dyns; + tmp_node.nd_body = 0; + tmp_node.nd_args = 0; + + ast.root = RNODE(&tmp_node); ast.frozen_string_literal = -1; ast.coverage_enabled = -1; ast.script_lines = INT2FIX(-1); |