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

*** empty log message ***

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_3@416 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 1999-04-12 09:59:33 +00:00
parent 32e799db48
commit 83627b120c
9 changed files with 1810 additions and 1829 deletions

View file

@ -1,5 +1,7 @@
Fri Apr 9 17:45:11 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
* parse.y (rb_compile_string): bug for nested eval().
* regex.c (re_match): should pop non-greedy stack items on
failure, after best_regs are fixed.

68
eval.c
View file

@ -416,7 +416,6 @@ struct BLOCK {
struct BLOCK *prev;
};
static struct BLOCK *ruby_block;
static struct BLOCK *ruby_calling_block;
#define PUSH_BLOCK(v,b) { \
struct BLOCK _block; \
@ -443,12 +442,9 @@ static struct BLOCK *ruby_calling_block;
struct BLOCK * volatile _old; \
struct BLOCK * volatile _old_call; \
_old = ruby_block; \
_old_call = ruby_calling_block; \
ruby_calling_block = b; \
ruby_block = b;
#define POP_BLOCK2() \
ruby_calling_block = _old_call; \
ruby_block = _old; \
}
@ -476,6 +472,14 @@ new_dvar(id, value)
return vars;
}
static void
mark_dvar(vars)
struct RVarmap *vars;
{
ruby_dyna_vars = new_dvar(0, 0);
ruby_dyna_vars->next = vars;
}
VALUE
rb_dvar_defined(id)
ID id;
@ -512,14 +516,16 @@ rb_dvar_push(id, value)
ruby_dyna_vars = new_dvar(id, value);
}
void
rb_dvar_asgn(id, value)
static void
dvar_asgn(id, value, push)
ID id;
VALUE value;
int push;
{
struct RVarmap *vars = ruby_dyna_vars;
while (vars) {
if (push && vars->id == 0) break;
if (vars->id == id) {
vars->val = value;
return;
@ -527,7 +533,14 @@ rb_dvar_asgn(id, value)
vars = vars->next;
}
rb_dvar_push(id, value);
return;
}
void
rb_dvar_asgn(id, value)
ID id;
VALUE value;
{
dvar_asgn(id, value, 0);
}
static void
@ -535,9 +548,16 @@ dvar_asgn_push(id, value)
ID id;
VALUE value;
{
rb_dvar_asgn(id, value);
if (ruby_calling_block) {
ruby_calling_block->d_vars = ruby_dyna_vars;
struct RVarmap* vars = 0;
if (ruby_dyna_vars && ruby_dyna_vars->id == 0) {
vars = ruby_dyna_vars;
ruby_dyna_vars = ruby_dyna_vars->next;
}
dvar_asgn(id, value, 1);
if (vars) {
vars->next = ruby_dyna_vars;
ruby_dyna_vars = vars;
}
}
@ -653,7 +673,7 @@ static VALUE ruby_wrapper; /* security wrapper */
static VALUE rb_eval _((VALUE,NODE*));
static VALUE eval _((VALUE,VALUE,VALUE,char*,int));
static NODE *compile _((VALUE));
static NODE *compile _((VALUE, char*, int));
static VALUE rb_yield_0 _((VALUE, VALUE, VALUE));
static VALUE rb_call _((VALUE,VALUE,ID,int,VALUE*,int));
@ -2451,7 +2471,9 @@ rb_eval(self, node)
case NODE_EVSTR:
ruby_sourceline = nd_line(node);
ruby_in_eval++;
list->nd_head = compile(list->nd_head->nd_lit);
list->nd_head = compile(list->nd_head->nd_lit,
ruby_sourcefile,
ruby_sourceline);
ruby_eval_tree = 0;
ruby_in_eval--;
if (ruby_nerrs > 0) {
@ -3106,7 +3128,7 @@ rb_yield_0(val, self, klass)
old_scope = ruby_scope;
ruby_scope = block->scope;
ruby_block = block->prev;
ruby_dyna_vars = block->d_vars;
mark_dvar(block->d_vars);
ruby_class = klass?klass:block->klass;
if (!self) self = block->self;
node = block->body;
@ -4086,13 +4108,15 @@ rb_frame_last_func()
}
static NODE*
compile(src)
compile(src, file, line)
VALUE src;
char *file;
int line;
{
NODE *node;
Check_Type(src, T_STRING);
node = rb_compile_string("(eval)", src);
node = rb_compile_string(file, src, line);
if (ruby_nerrs == 0) return node;
return 0;
@ -4135,8 +4159,6 @@ eval(self, src, scope, file, line)
ruby_frame = &(frame);
old_scope = ruby_scope;
ruby_scope = data->scope;
old_call_block = ruby_calling_block;
ruby_calling_block = data;
old_block = ruby_block;
ruby_block = data->prev;
old_d_vars = ruby_dyna_vars;
@ -4161,9 +4183,7 @@ eval(self, src, scope, file, line)
}
PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) {
ruby_sourcefile = file;
ruby_sourceline = line - 1;
compile(src);
compile(src, file, line);
if (ruby_nerrs > 0) {
compile_error(0);
}
@ -4178,9 +4198,6 @@ eval(self, src, scope, file, line)
FL_SET(old_scope, SCOPE_DONT_RECYCLE);
ruby_scope = old_scope;
ruby_block = old_block;
ruby_calling_block = old_call_block;
data->d_vars = ruby_dyna_vars;
ruby_dyna_vars = old_d_vars;
data->vmode = scope_vmode; /* write back visibility mode */
scope_vmode = old_vmode;
}
@ -4235,7 +4252,7 @@ rb_f_eval(argc, argv, self)
}
Check_SafeStr(src);
return eval(self, src, scope, file, line);
return eval(self, src, scope, file, line-1);
}
static VALUE
@ -5738,7 +5755,6 @@ struct thread {
struct SCOPE *scope;
struct RVarmap *dyna_vars;
struct BLOCK *block;
struct BLOCK *cblock;
struct iter *iter;
struct tag *tag;
VALUE klass;
@ -5899,7 +5915,6 @@ rb_thread_save_context(th)
th->wrapper = ruby_wrapper;
th->dyna_vars = ruby_dyna_vars;
th->block = ruby_block;
th->cblock = ruby_calling_block;
th->misc = scope_vmode | (rb_trap_immediate<<8);
th->iter = ruby_iter;
th->tag = prot_tag;
@ -5970,7 +5985,6 @@ rb_thread_restore_context(th, exit)
ruby_wrapper = th->wrapper;
ruby_dyna_vars = th->dyna_vars;
ruby_block = th->block;
ruby_calling_block = th->cblock;
scope_vmode = th->misc&SCOPE_MASK;
rb_trap_immediate = th->misc>>8;
ruby_iter = th->iter;

View file

@ -451,7 +451,7 @@ if $extlist.size > 0
if File.exist?(l)
$extinit += format("\
\tInit_%s();\n\
\trb_provide(\"%s.o\");\n\
\trb_provide(\"%s.so\");\n\
", s, s)
$extobjs += "ext/"
#$extobjs += f # *.obj

4
node.h
View file

@ -331,8 +331,8 @@ VALUE rb_method_booundp();
#define NOEX_PRIVATE 2
#define NOEX_PROTECTED 4
NODE *rb_compile_cstr _((const char*, const char*, int));
NODE *rb_compile_string _((const char*, VALUE));
NODE *rb_compile_cstr _((const char*, const char*, int, int));
NODE *rb_compile_string _((const char*, VALUE, int));
NODE *rb_compile_file _((const char*, VALUE, int));
void rb_add_method _((VALUE, ID, NODE *, int));

597
parse.c

File diff suppressed because it is too large Load diff

21
parse.y
View file

@ -245,7 +245,8 @@ program : {
}
compstmt
{
if ($2) { /* last expression is void */
if ($2 && !compile_for_eval) {
/* last expression should not be void */
if (nd_type($2) != NODE_BLOCK) void_expr($2);
else {
NODE *node = $2;
@ -1712,28 +1713,27 @@ lex_get_str(s)
}
NODE*
rb_compile_string(f, s)
rb_compile_string(f, s, line)
const char *f;
VALUE s;
int line;
{
lex_gets = lex_get_str;
lex_gets_ptr = 0;
lex_input = s;
lex_pbeg = lex_p = lex_pend = 0;
if (!ruby_sourcefile || strcmp(f, ruby_sourcefile)) /* not in eval() */
ruby_sourceline = 0;
else /* in eval() */
compile_for_eval = 1;
ruby_sourceline = line;
compile_for_eval = 1;
return yycompile(f);
}
NODE*
rb_compile_cstr(f, s, len)
rb_compile_cstr(f, s, len, line)
const char *f, *s;
int len;
int len, line;
{
return rb_compile_string(f, rb_str_new(s, len));
return rb_compile_string(f, rb_str_new(s, len), line);
}
NODE*
@ -3798,10 +3798,7 @@ void_expr(node)
case '<':
case tLEQ:
case tEQ:
case tEQQ:
case tNEQ:
case tMATCH:
case tNMATCH:
case tAREF:
case tRSHFT:
case tCOLON2:

2917
regex.c

File diff suppressed because it is too large Load diff

View file

@ -599,14 +599,21 @@ ok(("abc" =~ /d*$/) == 3)
ok("" =~ /^$/)
ok("\n" =~ /^$/)
ok("a\n\n" =~ /^$/)
"abcabc" =~ /.*a/
ok($& == "abca")
"abcabc" =~ /.*c/
ok($& == "abcabc")
"abcabc" =~ /.*?a/
ok($& == "a")
"abcabc" =~ /.*?c/
ok($& == "abc")
ok("abcabc" =~ /.*a/ && $& == "abca")
ok("abcabc" =~ /.*c/ && $& == "abcabc")
ok("abcabc" =~ /.*?a/ && $& == "a")
ok("abcabc" =~ /.*?c/ && $& == "abc")
ok(/(.|\n)*?\n(b|\n)/ =~ "a\nb\n\n" && $& == "a\nb")
$x = <<END;
ABCD
ABCD
END
$x.gsub!(/((.|\n)*?)B((.|\n)*?)D/){$1+$3}
ok($x == "AC\nAC\n")
ok("foobar" =~ /foo(?=(bar)|(baz))/)
ok("foobaz" =~ /foo(?=(bar)|(baz))/)
$foo = "abc"
ok("#$foo = abc" == "abc = abc")
@ -845,9 +852,13 @@ ok($x[4].call == 8)
proc {
p = binding
eval "foo11 = 1", p
foo22 = 5
proc{foo11=22}.call
proc{foo22=55}.call
ok(eval("foo11", p) == eval("foo11"))
ok(eval("foo11") == 1)
ok(eval("foo22", p) == eval("foo22"))
ok(eval("foo22") == 55)
}.call
p1 = proc{i6 = 0; proc{i6}}.call

View file

@ -197,7 +197,6 @@ EXPORTS
ruby_run
rb_eval_string
rb_eval_cmd
rb_trap_eval
rb_test_false_or_nil
rb_respond_to
rb_exit