1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* compile.c (defined_expr): support for assignment.

[ruby-core:10867]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12151 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2007-04-05 08:58:46 +00:00
parent a39ab5220d
commit 22e4a7703f
3 changed files with 148 additions and 84 deletions

View file

@ -1,3 +1,8 @@
Thu Apr 5 17:59:19 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* compile.c (defined_expr): support for assignment.
[ruby-core:10867]
Thu Apr 5 15:13:34 2007 NAKAMURA Usaku <usa@ruby-lang.org>
* ext/openssl/ossl_ssl_session.c (ossl_ssl_session_alloc): should

View file

@ -150,7 +150,6 @@ rb_iseq_compile(VALUE self, NODE *node)
set_arguments(iseq, ret, node->nd_args);
if (iseq->type == ISEQ_TYPE_BLOCK) {
VALUE tmp; /* required by ADD_LABEL */
LABEL *start = iseq->compile_data->start_label = NEW_LABEL(0);
LABEL *end = iseq->compile_data->end_label = NEW_LABEL(0);
@ -2048,8 +2047,31 @@ defined_expr(rb_iseq_t *iseq, LINK_ANCHOR *ret,
case NODE_FALSE:
estr = "false";
break;
case NODE_ARRAY:{
LABEL *lfalse = NULL;
NODE *vals = node;
do {
NODE *val = vals->nd_head;
defined_expr(iseq, ret, vals->nd_head, lfinish, Qfalse);
if (lfalse) {
ADD_INSNL(ret, nd_line(node), branchunless, lfalse);
}
else {
LABEL *lcont = NEW_LABEL(nd_line(node));
ADD_INSNL(ret, nd_line(node), branchif, lcont);
lfalse = NEW_LABEL(nd_line(node));
ADD_LABEL(ret, lfalse);
ADD_INSN(ret, nd_line(node), putnil);
ADD_INSNL(ret, nd_line(node), jump, lfinish);
ADD_LABEL(ret, lcont);
}
} while (vals = vals->nd_next);
}
case NODE_STR:
case NODE_LIT:
case NODE_ZARRAY:
estr = "expression";
break;
@ -2120,11 +2142,30 @@ defined_expr(rb_iseq_t *iseq, LINK_ANCHOR *ret,
case NODE_CALL:
case NODE_VCALL:
case NODE_FCALL:
if (nd_type(node) == NODE_CALL) {
case NODE_ATTRASGN:{
LABEL *lfalse = NULL;
int self = Qtrue;
switch (nd_type(node)) {
case NODE_ATTRASGN:
lfalse = NEW_LABEL(nd_line(node));
defined_expr(iseq, ret, node->nd_args, lfinish, Qfalse);
if (node->nd_recv == (NODE *)1) break;
case NODE_CALL:
self = Qfalse;
break;
}
if (!self) {
LABEL *lcont = NEW_LABEL(nd_line(node));
if (lfalse) {
ADD_INSNL(ret, nd_line(node), branchunless, lfalse);
}
defined_expr(iseq, ret, node->nd_recv, lfinish, Qfalse);
ADD_INSNL(ret, nd_line(node), branchif, lcont);
if (lfalse) {
ADD_LABEL(ret, lfalse);
}
ADD_INSN(ret, nd_line(node), putnil);
ADD_INSNL(ret, nd_line(node), jump, lfinish);
@ -2137,8 +2178,16 @@ defined_expr(rb_iseq_t *iseq, LINK_ANCHOR *ret,
ADD_INSN(ret, nd_line(node), putself);
ADD_INSN3(ret, nd_line(node), defined, INT2FIX(DEFINED_FUNC),
ID2SYM(node->nd_mid), needstr);
if (lfalse) {
ADD_INSNL(ret, nd_line(node), branchif, lfinish);
ADD_LABEL(ret, lfalse);
ADD_INSN(ret, nd_line(node), putnil);
ADD_INSNL(ret, nd_line(node), jump, lfinish);
}
}
return 1;
}
case NODE_YIELD:
ADD_INSN(ret, nd_line(node), putnil);
@ -2158,27 +2207,42 @@ defined_expr(rb_iseq_t *iseq, LINK_ANCHOR *ret,
needstr);
return 1;
case NODE_OP_ASGN1:
case NODE_OP_ASGN2:
case NODE_MASGN:
case NODE_LASGN:
case NODE_DASGN:
case NODE_DASGN_CURR:
case NODE_GASGN:
case NODE_IASGN:
case NODE_CDECL:
case NODE_CVDECL:
case NODE_CVASGN:
estr = "assignment";
break;
default:{
LABEL *lstart = NEW_LABEL(nd_line(node));
LABEL *lend = NEW_LABEL(nd_line(node));
LABEL *ldefed = NEW_LABEL(nd_line(node));
VALUE str = rb_str_new2("expression");
VALUE tmp;
VALUE ensure = NEW_CHILD_ISEQVAL(NEW_NIL(),
rb_str_concat(rb_str_new2
("defined guard in "),
iseq->name),
ISEQ_TYPE_DEFINED_GUARD);
iseq_add_mark_object_compile_time(iseq, str);
ADD_LABEL(ret, lstart);
COMPILE(ret, "defined expr (others)", node);
ADD_INSNL(ret, nd_line(node), branchif, ldefed);
ADD_INSN(ret, nd_line(node), putnil);
ADD_INSNL(ret, nd_line(node), jump, lend);
ADD_LABEL(ret, ldefed);
ADD_INSN1(ret, nd_line(node), putobject, str);
if (needstr) {
ADD_INSN1(ret, nd_line(node), putstring, rb_str_new2("expression"));
}
else {
ADD_INSN1(ret, nd_line(node), putobject, Qtrue);
}
ADD_LABEL(ret, lend);
ADD_CATCH_ENTRY(CATCH_TYPE_ENSURE, lstart, lend, ensure, lfinish);
@ -2347,7 +2411,6 @@ setup_arg(rb_iseq_t *iseq, LINK_ANCHOR *args, NODE *node, VALUE *flag)
static int
iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
{
VALUE tmp; /* reserved for macro */
int type;
GC_CHECK();
@ -4436,7 +4499,6 @@ iseq_build_exception(rb_iseq_t *iseq, struct st_table *labels_table,
VALUE exception)
{
int i;
VALUE tmp;
for (i=0; i<RARRAY_LEN(exception); i++) {
VALUE v = rb_ary_entry(exception, i);

View file

@ -10,8 +10,8 @@
**********************************************************************/
#ifndef _COMPILER_H_INCLUDED_
#define _COMPILER_H_INCLUDED_
#ifndef RUBY_COMPILE_H
#define RUBY_COMPILE_H
#if YARVDEBUG > CPDEBUG
@ -162,13 +162,10 @@ r_value(VALUE value)
ADD_ELEM(seq, (LINK_ELEMENT *)label)
#define ADD_CATCH_ENTRY(type, ls, le, iseqv, lc) \
(tmp = rb_ary_new(), \
rb_ary_push(tmp, type), \
rb_ary_push(tmp, (VALUE) ls | 1), \
rb_ary_push(tmp, (VALUE) le | 1), \
rb_ary_push(tmp, iseqv), \
rb_ary_push(tmp, (VALUE) lc | 1), \
rb_ary_push(iseq->compile_data->catch_table_ary, tmp))
(rb_ary_push(iseq->compile_data->catch_table_ary, \
rb_ary_new3(5, type, \
(VALUE)(ls) | 1, (VALUE)(le) | 1, \
iseqv, (VALUE)(lc) | 1)))
/* compile node */
#define COMPILE(anchor, desc, node) \
@ -212,4 +209,4 @@ r_value(VALUE value)
LINK_ANCHOR name##_body__ = {{0,}, &name##_body__.anchor}; \
LINK_ANCHOR *name = & name##_body__
#endif /* _COMPILER_H_INCLUDED_ */
#endif /* RUBY_COMPILE_H */