[前][次][番号順一覧][スレッド一覧]

ruby-changes:58102

From: Yusuke <ko1@a...>
Date: Fri, 4 Oct 2019 02:30:56 +0900 (JST)
Subject: [ruby-changes:58102] b43afa0a8f (master): Make parser_params have parent_iseq instead of base_block

https://git.ruby-lang.org/ruby.git/commit/?id=b43afa0a8f

From b43afa0a8f82a5d806adc24afa2eaf41479da1a3 Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Fri, 4 Oct 2019 01:48:31 +0900
Subject: Make parser_params have parent_iseq instead of base_block

The parser needs to determine whether a local varaiable is defined or
not in outer scope.  For the sake, "base_block" field has kept the outer
block.

However, the whole block was actually unneeded; the parser used only
base_block->iseq.

So, this change lets parser_params have the iseq directly, instead of
the whole block.

diff --git a/compile.c b/compile.c
index 78d2fd4..7a88f81 100644
--- a/compile.c
+++ b/compile.c
@@ -9123,11 +9123,9 @@ rb_iseq_build_from_ary(rb_iseq_t *iseq, VALUE misc, VALUE locals, VALUE params, https://github.com/ruby/ruby/blob/trunk/compile.c#L9123
 /* for parser */
 
 int
-rb_dvar_defined(ID id, const struct rb_block *base_block)
+rb_dvar_defined(ID id, const rb_iseq_t *iseq)
 {
-    const rb_iseq_t *iseq;
-
-    if (base_block && (iseq = vm_block_iseq(base_block)) != NULL) {
+    if (iseq) {
 	const struct rb_iseq_constant_body *body = iseq->body;
 	while (body->type == ISEQ_TYPE_BLOCK ||
 	       body->type == ISEQ_TYPE_RESCUE ||
@@ -9150,11 +9148,9 @@ rb_dvar_defined(ID id, const struct rb_block *base_block) https://github.com/ruby/ruby/blob/trunk/compile.c#L9148
 }
 
 int
-rb_local_defined(ID id, const struct rb_block *base_block)
+rb_local_defined(ID id, const rb_iseq_t *iseq)
 {
-    const rb_iseq_t *iseq;
-
-    if (base_block && (iseq = vm_block_iseq(base_block)) != NULL) {
+    if (iseq) {
 	unsigned int i;
 	const struct rb_iseq_constant_body *const body = iseq->body->local_iseq->body;
 
diff --git a/internal.h b/internal.h
index 2346703..7d24e33 100644
--- a/internal.h
+++ b/internal.h
@@ -1457,8 +1457,9 @@ VALUE rb_invcmp(VALUE, VALUE); https://github.com/ruby/ruby/blob/trunk/internal.h#L1457
 
 /* compile.c */
 struct rb_block;
-int rb_dvar_defined(ID, const struct rb_block *);
-int rb_local_defined(ID, const struct rb_block *);
+struct rb_iseq_struct;
+int rb_dvar_defined(ID, const struct rb_iseq_struct *);
+int rb_local_defined(ID, const struct rb_iseq_struct *);
 const char * rb_insns_name(int i);
 VALUE rb_insns_name_array(void);
 int rb_vm_insn_addr2insn(const void *);
@@ -1954,7 +1955,7 @@ struct RBasicRaw { https://github.com/ruby/ruby/blob/trunk/internal.h#L1955
 VALUE rb_parser_get_yydebug(VALUE);
 VALUE rb_parser_set_yydebug(VALUE, VALUE);
 RUBY_SYMBOL_EXPORT_BEGIN
-VALUE rb_parser_set_context(VALUE, const struct rb_block *, int);
+VALUE rb_parser_set_context(VALUE, const struct rb_iseq_struct *, int);
 RUBY_SYMBOL_EXPORT_END
 void *rb_parser_load_file(VALUE parser, VALUE name);
 int rb_is_const_name(VALUE name);
diff --git a/iseq.c b/iseq.c
index ae7b1cc..d7e8cce 100644
--- a/iseq.c
+++ b/iseq.c
@@ -994,7 +994,7 @@ rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE realpath, VALUE line, c https://github.com/ruby/ruby/blob/trunk/iseq.c#L994
     }
     {
 	const VALUE parser = rb_parser_new();
-	rb_parser_set_context(parser, base_block, FALSE);
+	rb_parser_set_context(parser, parent, FALSE);
 	ast = (*parse)(parser, file, src, ln);
     }
 
diff --git a/parse.y b/parse.y
index 651e2ce..8ff7b8a 100644
--- a/parse.y
+++ b/parse.y
@@ -294,7 +294,7 @@ struct parser_params { https://github.com/ruby/ruby/blob/trunk/parse.y#L294
     NODE *eval_tree;
     VALUE error_buffer;
     VALUE debug_lines;
-    const struct rb_block *base_block;
+    const rb_iseq_t *parent_iseq;
 
     struct {
 	NODE *outer, *inner, *current;
@@ -329,7 +329,7 @@ static int parser_yyerror(struct parser_params*, const YYLTYPE *yylloc, const ch https://github.com/ruby/ruby/blob/trunk/parse.y#L329
 #ifdef RIPPER
 #define compile_for_eval	(0)
 #else
-#define compile_for_eval	(p->base_block != 0)
+#define compile_for_eval	(p->parent_iseq != 0)
 #endif
 
 #define token_column		((int)(p->lex.ptok - p->lex.pbeg))
@@ -11777,7 +11777,7 @@ local_id_ref(struct parser_params *p, ID id, ID **vidrefp) https://github.com/ruby/ruby/blob/trunk/parse.y#L11777
     }
 
     if (vars && vars->prev == DVARS_INHERIT) {
-	return rb_local_defined(id, p->base_block);
+	return rb_local_defined(id, p->parent_iseq);
     }
     else if (vtable_included(args, id)) {
 	return 1;
@@ -11920,7 +11920,7 @@ dvar_defined_ref(struct parser_params *p, ID id, ID **vidrefp) https://github.com/ruby/ruby/blob/trunk/parse.y#L11920
     }
 
     if (vars == DVARS_INHERIT) {
-        return rb_dvar_defined(id, p->base_block);
+        return rb_dvar_defined(id, p->parent_iseq);
     }
 
     return 0;
@@ -12301,13 +12301,13 @@ rb_parser_new(void) https://github.com/ruby/ruby/blob/trunk/parse.y#L12301
 }
 
 VALUE
-rb_parser_set_context(VALUE vparser, const struct rb_block *base, int main)
+rb_parser_set_context(VALUE vparser, const rb_iseq_t *base, int main)
 {
     struct parser_params *p;
 
     TypedData_Get_Struct(vparser, struct parser_params, &parser_data_type, p);
     p->error_buffer = main ? Qfalse : Qnil;
-    p->base_block = base;
+    p->parent_iseq = base;
     return vparser;
 }
 #endif
diff --git a/vm_eval.c b/vm_eval.c
index 1c205f0..07af3b4 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -1579,7 +1579,7 @@ eval_make_iseq(VALUE src, VALUE fname, int line, const rb_binding_t *bind, https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L1579
         fname = rb_fstring_lit("(eval)");
     }
 
-    rb_parser_set_context(parser, base_block, FALSE);
+    rb_parser_set_context(parser, parent, FALSE);
     ast = rb_parser_compile_string_path(parser, fname, src, line);
     if (ast->body.root) {
 	iseq = rb_iseq_new_with_opt(&ast->body,
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]