Skip to content

Commit

Permalink
* parse.y, node.h, compile.c: change node tree structure. a purpose
Browse files Browse the repository at this point in the history
  of this change is to unify argument structure of method and block.
  this change prohibits duplicate block parameter name.
  new argument infromation:
  NODE_ARGS     [m: int, o: NODE_OPT_ARG, ->]
  NODE_ARGS_AUX [r: ID, b: ID, ->]
  NODE_ARGS_AUX [Pst: id, Plen: int, init: NODE*]
  optarg information:
  NODE_OPT_ARGS [idx, expr, ->]
* vm_macro.def: ditto.
* gc.c: ditto.
* iseq.c: ditto.
* compile.h: fix debug function name.
* test/ripper/test_scanner_events.rb: |_,_,foo| -> |_1,_2,foo|
* test/ruby/test_lambda.rb: disalbe test temporarily.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11840 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
ko1 committed Feb 24, 2007
1 parent c5148e0 commit 0fe7204
Show file tree
Hide file tree
Showing 10 changed files with 251 additions and 161 deletions.
24 changes: 24 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
Sat Feb 24 10:49:55 2007 Koichi Sasada <[email protected]>

* parse.y, node.h, compile.c: change node tree structure. a purpose
of this change is to unify argument structure of method and block.
this change prohibits duplicate block parameter name.
new argument infromation:
NODE_ARGS [m: int, o: NODE_OPT_ARG, ->]
NODE_ARGS_AUX [r: ID, b: ID, ->]
NODE_ARGS_AUX [Pst: id, Plen: int, init: NODE*]
optarg information:
NODE_OPT_ARGS [idx, expr, ->]

* vm_macro.def: ditto.

* gc.c: ditto.

* iseq.c: ditto.

* compile.h: fix debug function name.

* test/ripper/test_scanner_events.rb: |_,_,foo| -> |_1,_2,foo|

* test/ruby/test_lambda.rb: disalbe test temporarily.

Sat Feb 24 10:46:28 2007 Koichi Sasada <[email protected]>

* test/testunit/test_testcase.rb: catch up with current instance
Expand Down
115 changes: 106 additions & 9 deletions compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ iseq_compile(VALUE self, NODE *narg)

debugs("[compile step 1 (traverse each node)]\n");


iseq->node = node;

if (iseq->type == ISEQ_TYPE_BLOCK) {
Expand Down Expand Up @@ -1035,7 +1034,7 @@ set_block_local_tbl(rb_iseq_t *iseq, NODE * node, LINK_ANCHOR *anchor)
}
}

if (iseq->arg_opts || iseq->arg_rest) {
if (iseq->arg_opts || iseq->arg_rest || iseq->arg_block) {
iseq->arg_simple = 0;
}
else {
Expand Down Expand Up @@ -1077,9 +1076,96 @@ get_dyna_var_idx(rb_iseq_t *iseq, ID id, int *level, int *ls)
return -1;
}

/**
#if 1

static int
set_arguments(rb_iseq_t *iseq, LINK_ANCHOR *optargs, NODE *node_arg)
{
NODE *node_aux = node_arg->nd_next;
int mandatory_len = 0;
NODE *node_opt = 0;
ID rest_id = 0;
ID block_id = 0;
ID post_start_id = 0;
int post_len = 0;
NODE *node_init = 0;

iseq->argc = node_arg->nd_frml;
node_opt = node_arg->nd_opt;

if (node_aux) {
rest_id = node_aux->nd_rest;
block_id = (ID)node_aux->nd_body;
node_aux = node_aux->nd_next;

if (node_aux) {
post_start_id = node_aux->nd_pid;
post_len = node_aux->nd_plen;
node_init = node_aux->nd_next;
}
}

if (node_init) {
COMPILE(optargs, "arguments", node_init);
}

if (node_opt) {
NODE *node = node_opt;
LABEL *label;
VALUE labels = rb_ary_new();
int i = 0, j;

while (node) {
label = NEW_LABEL(nd_line(node));
rb_ary_push(labels, (VALUE)label | 1);
ADD_LABEL(optargs, label);
COMPILE_POPED(optargs, "optarg", node->nd_body);

node = node->nd_next;
i += 1;
}
/* last label */
label = NEW_LABEL(nd_line(node_arg));
rb_ary_push(labels, (VALUE)label | 1);
ADD_LABEL(optargs, label);
i += 1;

iseq->arg_opts = i;
iseq->arg_opt_tbl = ALLOC_N(VALUE, i);
MEMCPY(iseq->arg_opt_tbl, RARRAY_PTR(labels), VALUE, i);
for (j = 0; j < i; j++) {
iseq->arg_opt_tbl[j] &= ~1;
}
}
else {
iseq->arg_opts = 0;
}

if ((long)rest_id == -1) {
iseq->arg_rest = get_dyna_var_idx_at_raw(iseq, 0 /* dummy var */);
}
else if (rest_id) {
iseq->arg_rest = get_dyna_var_idx_at_raw(iseq, rest_id);
}
if (iseq->arg_rest == -1) rb_bug("arg_rest: -1");


if (block_id) {
iseq->arg_block = get_dyna_var_idx_at_raw(iseq, block_id);
}

if (iseq->arg_rest != 0 || iseq->arg_opts != 0 || iseq->arg_block != 0) {
iseq->arg_simple = 0;
}
else {
iseq->arg_simple = 1;
}

return COMPILE_OK;
}

#else

*/
static int
set_arguments(rb_iseq_t *iseq, LINK_ANCHOR *optargs, NODE * node)
{
Expand Down Expand Up @@ -1121,7 +1207,9 @@ set_arguments(rb_iseq_t *iseq, LINK_ANCHOR *optargs, NODE * node)

iseq->arg_opts = i;
iseq->arg_opt_tbl = ALLOC_N(VALUE, i);

MEMCPY(iseq->arg_opt_tbl, RARRAY_PTR(labels), VALUE, i);

for (j = 0; j < i; j++) {
iseq->arg_opt_tbl[j] &= ~1;
}
Expand All @@ -1144,6 +1232,7 @@ set_arguments(rb_iseq_t *iseq, LINK_ANCHOR *optargs, NODE * node)
}
return COMPILE_OK;
}
#endif

static int
set_localtbl(rb_iseq_t *iseq, ID *tbl)
Expand Down Expand Up @@ -3681,6 +3770,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
int idx = liseq->local_size - i;
ADD_INSN1(args, nd_line(node), getlocal, INT2FIX(idx));
}

if (!liseq->arg_simple) {
if (liseq->arg_opts) {
/* optional arguments */
Expand All @@ -3693,13 +3783,20 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
i += j;
argc = INT2FIX(i);
}

if (liseq->arg_rest) {
/* rest arguments */
int idx = liseq->local_size - liseq->arg_rest + 1;
ADD_INSN1(args, nd_line(node), getlocal,
INT2FIX(idx));
argc = INT2FIX(liseq->arg_rest);
flag |= VM_CALL_ARGS_SPLAT_BIT;

if (liseq->arg_rest == -1) {
/* TODO */
}
else {
int idx = liseq->local_size - liseq->arg_rest + 1;
ADD_INSN1(args, nd_line(node), getlocal,
INT2FIX(idx));
argc = INT2FIX(liseq->arg_rest);
flag |= VM_CALL_ARGS_SPLAT_BIT;
}
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,27 @@
#if CPDEBUG > 0

#define debugp(header, value) \
(debug_indent(0, CPDEBUG, gl_node_level * 2), \
(ruby_debug_indent(0, CPDEBUG, gl_node_level * 2), \
ruby_debug_value(0, CPDEBUG, header, value))

#define debugi(header, id) \
(debug_indent(0, CPDEBUG, gl_node_level * 2), \
debug_id(0, CPDEBUG, header, id))
(ruby_debug_indent(0, CPDEBUG, gl_node_level * 2), \
ruby_debug_id(0, CPDEBUG, header, id))

#define debugp_param(header, value) \
(debug_indent(1, CPDEBUG, gl_node_level * 2), \
(ruby_debug_indent(1, CPDEBUG, gl_node_level * 2), \
ruby_debug_value(1, CPDEBUG, header, value))

#define debugp_verbose(header, value) \
(debug_indent(2, CPDEBUG, gl_node_level * 2), \
(ruby_debug_indent(2, CPDEBUG, gl_node_level * 2), \
ruby_debug_value(2, CPDEBUG, header, value))

#define debugp_verbose_node(header, value) \
(debug_indent(10, CPDEBUG, gl_node_level * 2), \
(ruby_debug_indent(10, CPDEBUG, gl_node_level * 2), \
ruby_debug_value(10, CPDEBUG, header, value))

#define debug_nodeprint(node) \
debug_indent(-1, CPDEBUG, gl_node_level*2); \
ruby_debug_indent(-1, CPDEBUG, gl_node_level*2); \
printf("node: %s (%d)\n", ruby_node_name(nd_type(node)), nd_line(node)); \
gl_node_level ++;

Expand Down Expand Up @@ -91,8 +91,8 @@ r_value(VALUE value)
#endif

#if CPDEBUG > 1
#define debugs debug_indent(-1, CPDEBUG, gl_node_level*2), printf
#define debug_compile(msg, v) (debug_indent(-1, CPDEBUG, gl_node_level*2), printf("%s", msg), (v))
#define debugs ruby_debug_indent(-1, CPDEBUG, gl_node_level*2), printf
#define debug_compile(msg, v) (ruby_debug_indent(-1, CPDEBUG, gl_node_level*2), printf("%s", msg), (v))
#else
#define debugs if(0)printf
#define debug_compile(msg, v) (v)
Expand Down
4 changes: 3 additions & 1 deletion gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,6 @@ gc_mark_children(VALUE ptr, int lev)
case NODE_RESCUE:
case NODE_RESBODY:
case NODE_CLASS:
case NODE_ARGS:
case NODE_BLOCK_PASS:
gc_mark((VALUE)obj->as.node.u2.node, lev);
/* fall through */
Expand All @@ -859,11 +858,13 @@ gc_mark_children(VALUE ptr, int lev)
case NODE_CALL:
case NODE_DEFS:
case NODE_OP_ASGN1:
case NODE_ARGS:
gc_mark((VALUE)obj->as.node.u1.node, lev);
/* fall through */
case NODE_SUPER: /* 3 */
case NODE_FCALL:
case NODE_DEFN:
case NODE_ARGS_AUX:
ptr = (VALUE)obj->as.node.u3.node;
goto again;

Expand Down Expand Up @@ -922,6 +923,7 @@ gc_mark_children(VALUE ptr, int lev)

case NODE_SCOPE: /* 2,3 */
case NODE_CDECL:
case NODE_OPT_ARG:
gc_mark((VALUE)obj->as.node.u3.node, lev);
ptr = (VALUE)obj->as.node.u2.node;
goto again;
Expand Down
11 changes: 8 additions & 3 deletions iseq.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,10 +542,15 @@ insn_operand_intern(rb_iseq_t *iseq,
case TS_LINDEX:
{
rb_iseq_t *ip = iseq->local_iseq;
int lidx = ip->local_size - op + 1;
ID id = ip->local_tbl[lidx];

ret =
rb_str_new2(
rb_id2name(ip->local_tbl[ip->local_size - op + 1]));
if (id) {
ret = rb_str_new2(rb_id2name(id));
}
else {
ret = rb_str_new2("*");
}
break;
}
case TS_DINDEX:{
Expand Down
14 changes: 10 additions & 4 deletions node.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ enum node_type {
NODE_DREGX,
NODE_DREGX_ONCE,
NODE_ARGS,
NODE_ARGS_AUX,
NODE_OPT_ARG,
NODE_POSTARG,
NODE_ARGSCAT,
NODE_ARGSPUSH,
Expand Down Expand Up @@ -209,9 +211,11 @@ typedef struct RNode {

#define nd_lit u1.value

#define nd_frml u3.value
#define nd_rest u2.node
#define nd_frml u2.argc
#define nd_rest u1.id
#define nd_opt u1.node
#define nd_pid u1.id
#define nd_plen u2.argc

#define nd_recv u1.node
#define nd_mid u2.id
Expand Down Expand Up @@ -315,8 +319,10 @@ typedef struct RNode {
#define NEW_VCALL(m) NEW_NODE(NODE_VCALL,0,m,0)
#define NEW_SUPER(a) NEW_NODE(NODE_SUPER,0,0,a)
#define NEW_ZSUPER() NEW_NODE(NODE_ZSUPER,0,0,0)
#define NEW_ARGS(f,o,r) NEW_NODE(NODE_ARGS,o,r,f)
#define NEW_POSTARG(r,m) NEW_NODE(NODE_POSTARG,m,0,r)
#define NEW_ARGS(m,o) NEW_NODE(NODE_ARGS,o,m,0)
#define NEW_ARGS_AUX(r,b) NEW_NODE(NODE_ARGS_AUX,r,b,0)
#define NEW_OPT_ARG(i,v) NEW_NODE(NODE_OPT_ARG,i,v,0)
#define NEW_POSTARG(i,v) NEW_NODE(NODE_POSTARG,i,v,0)
#define NEW_ARGSCAT(a,b) NEW_NODE(NODE_ARGSCAT,a,b,0)
#define NEW_ARGSPUSH(a,b) NEW_NODE(NODE_ARGSPUSH,a,b,0)
#define NEW_SPLAT(a) NEW_NODE(NODE_SPLAT,a,0,0)
Expand Down
Loading

0 comments on commit 0fe7204

Please sign in to comment.