summaryrefslogtreecommitdiff
path: root/node.c
diff options
context:
space:
mode:
Diffstat (limited to 'node.c')
-rw-r--r--node.c47
1 files changed, 35 insertions, 12 deletions
diff --git a/node.c b/node.c
index 3dea7fe398..180142d089 100644
--- a/node.c
+++ b/node.c
@@ -1043,12 +1043,12 @@ dump_node(VALUE buf, VALUE indent, int comment, const NODE * node)
ANN("new scope");
ANN("format: [nd_tbl]: local table, [nd_args]: arguments, [nd_body]: body");
F_CUSTOM1(nd_tbl, "local table") {
- ID *tbl = node->nd_tbl;
+ rb_ast_id_table_t *tbl = node->nd_tbl;
int i;
- int size = tbl ? (int)*tbl++ : 0;
+ int size = tbl ? tbl->size : 0;
if (size == 0) A("(empty)");
for (i = 0; i < size; i++) {
- A_ID(tbl[i]); if (i < size - 1) A(",");
+ A_ID(tbl->ids[i]); if (i < size - 1) A(",");
}
}
F_NODE(nd_args, "arguments");
@@ -1162,7 +1162,7 @@ typedef struct {
struct node_buffer_struct {
node_buffer_list_t unmarkable;
node_buffer_list_t markable;
- ID *local_tables;
+ struct rb_ast_local_table_link *local_tables;
VALUE mark_hash;
};
@@ -1205,15 +1205,22 @@ node_buffer_list_free(node_buffer_list_t * nb)
}
}
+struct rb_ast_local_table_link {
+ struct rb_ast_local_table_link *next;
+ // struct rb_ast_id_table {
+ int size;
+ ID ids[FLEX_ARY_LEN];
+ // }
+};
+
static void
rb_node_buffer_free(node_buffer_t *nb)
{
node_buffer_list_free(&nb->unmarkable);
node_buffer_list_free(&nb->markable);
- ID * local_table = nb->local_tables;
+ struct rb_ast_local_table_link *local_table = nb->local_tables;
while (local_table) {
- unsigned int size = (unsigned int)*local_table;
- ID * next_table = (ID *)local_table[size + 1];
+ struct rb_ast_local_table_link *next_table = local_table->next;
xfree(local_table);
local_table = next_table;
}
@@ -1277,12 +1284,28 @@ rb_ast_node_type_change(NODE *n, enum node_type type)
}
}
-void
-rb_ast_add_local_table(rb_ast_t *ast, ID *buf)
+rb_ast_id_table_t *
+rb_ast_new_local_table(rb_ast_t *ast, int size)
+{
+ size_t alloc_size = sizeof(struct rb_ast_local_table_link) + size * sizeof(ID);
+ struct rb_ast_local_table_link *link = ruby_xmalloc(alloc_size);
+ link->next = ast->node_buffer->local_tables;
+ ast->node_buffer->local_tables = link;
+ link->size = size;
+
+ return (rb_ast_id_table_t *) &link->size;
+}
+
+rb_ast_id_table_t *
+rb_ast_resize_latest_local_table(rb_ast_t *ast, int size)
{
- unsigned int size = (unsigned int)*buf;
- buf[size + 1] = (ID)ast->node_buffer->local_tables;
- ast->node_buffer->local_tables = buf;
+ struct rb_ast_local_table_link *link = ast->node_buffer->local_tables;
+ size_t alloc_size = sizeof(struct rb_ast_local_table_link) + size * sizeof(ID);
+ link = ruby_xrealloc(link, alloc_size);
+ ast->node_buffer->local_tables = link;
+ link->size = size;
+
+ return (rb_ast_id_table_t *) &link->size;
}
void