Skip to content

Commit

Permalink
* eval.c (rb_eval): [EXPERIMENTAL] NODE_LAMBDA implemented.
Browse files Browse the repository at this point in the history
  [ruby-dev:25780]

* node.h (NODE_LAMBDA): for literal Proc object.

* parse.y (expr): interpret mere do...end block as proc object.

* parse.y (primary): ditto, for brace block.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8044 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Mar 2, 2005
1 parent eaf373d commit 6c0cc67
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
11 changes: 11 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
Wed Mar 2 12:21:18 2005 Nobuyoshi Nakada <[email protected]>

* eval.c (rb_eval): [EXPERIMENTAL] NODE_LAMBDA implemented.
[ruby-dev:25780]

* node.h (NODE_LAMBDA): for literal Proc object.

* parse.y (expr): interpret mere do...end block as proc object.

* parse.y (primary): ditto, for brace block.

Tue Mar 1 21:16:54 2005 K.Kosako <sndgk393 AT ybb.ne.jp>

* regcomp.c (optimize_node_left): uninitialized member
Expand Down
5 changes: 5 additions & 0 deletions eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -2941,6 +2941,7 @@ rb_eval(self, n)

case NODE_ITER:
case NODE_FOR:
case NODE_LAMBDA:
{
PUSH_TAG(PROT_LOOP);
PUSH_BLOCK(node->nd_var, node->nd_body);
Expand All @@ -2952,6 +2953,10 @@ rb_eval(self, n)
if (nd_type(node) == NODE_ITER) {
result = rb_eval(self, node->nd_iter);
}
else if (nd_type(node) == NODE_LAMBDA) {
ruby_iter->iter = ruby_frame->iter = ITER_CUR;
result = rb_block_proc();
}
else {
VALUE recv;

Expand Down
2 changes: 2 additions & 0 deletions node.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ enum node_type {
NODE_DSYM,
NODE_ATTRASGN,
NODE_PRELUDE,
NODE_LAMBDA,
NODE_LAST
};

Expand Down Expand Up @@ -340,6 +341,7 @@ typedef struct RNode {
#define NEW_BMETHOD(b) NEW_NODE(NODE_BMETHOD,0,0,b)
#define NEW_ATTRASGN(r,m,a) NEW_NODE(NODE_ATTRASGN,r,m,a)
#define NEW_PRELUDE(p,b) NEW_NODE(NODE_PRELUDE,p,b,0)
#define NEW_LAMBDA(v,b) NEW_NODE(NODE_LAMBDA,v,b,0)

#define NOEX_PUBLIC 0
#define NOEX_NOSUPER 1
Expand Down
37 changes: 34 additions & 3 deletions parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ static void ripper_compile_error _((struct parser_params*, const char *fmt, ...)
%type <node> mrhs superclass block_call block_command
%type <node> f_arglist f_args f_optarg f_opt f_block_arg opt_f_block_arg
%type <node> assoc_list assocs assoc undef_list backref string_dvar
%type <node> for_var block_var opt_block_var block_par
%type <node> for_var block_var opt_block_var block_var_def block_par
%type <node> brace_block cmd_brace_block do_block lhs none fitem
%type <node> mlhs mlhs_head mlhs_basic mlhs_entry mlhs_item mlhs_node
%type <id> fsym variable sym symbol operation operation2 operation3
Expand Down Expand Up @@ -1014,6 +1014,11 @@ expr : command_call
$$ = dispatch2(unary, ID2SYM('!'), $2);
%*/
}
| do_block
{
$$ = $1;
nd_set_type($$, NODE_LAMBDA);
}
| arg
;

Expand Down Expand Up @@ -2504,6 +2509,26 @@ primary : literal
$$ = dispatch1(hash, escape_Qundef($2));
%*/
}
| tLBRACE
{
/*%%%*/
$<vars>$ = dyna_push();
$<num>1 = ruby_sourceline;
/*%
%*/
}
block_var_def {$<vars>$ = ruby_dyna_vars;}
compstmt
'}'
{
/*%%%*/
$$ = NEW_LAMBDA($3, dyna_init($5, $<vars>4));
nd_set_line($$, $<num>1);
dyna_pop($<vars>2);
/*%
$$ = dispatch2(brace_block, escape_Qundef($3), $5);
%*/
}
| kRETURN
{
/*%%%*/
Expand Down Expand Up @@ -3062,7 +3087,13 @@ block_var : block_par
;

opt_block_var : none
| '|' /* none */ '|'
| block_var_def
{
$$ = $1;
}
;

block_var_def : '|' /* none */ '|'
{
/*%%%*/
$$ = (NODE*)1;
Expand Down Expand Up @@ -6380,7 +6411,7 @@ parser_yylex(parser)
if (COND_P()) return kDO_COND;
if (CMDARG_P() && state != EXPR_CMDARG)
return kDO_BLOCK;
if (state == EXPR_ENDARG)
if (state == EXPR_ENDARG || state == EXPR_BEG)
return kDO_BLOCK;
return kDO;
}
Expand Down

0 comments on commit 6c0cc67

Please sign in to comment.