Skip to content

Commit

Permalink
19991117
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@564 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
matz committed Nov 17, 1999
1 parent 2ee41de commit 0d2a064
Show file tree
Hide file tree
Showing 19 changed files with 366 additions and 132 deletions.
39 changes: 39 additions & 0 deletions ChangeLog
@@ -1,3 +1,42 @@
Wed Nov 17 02:40:40 1999 Yukihiro Matsumoto <matz@netlab.co.jp>

* io.c (Init_IO): $defout (alias of $>) added.

Tue Nov 16 09:47:14 1999 Yukihiro Matsumoto <matz@netlab.co.jp>

* lib/pstore.rb: add mutual lock using symlink.

Mon Nov 15 16:50:34 1999 Yukihiro Matsumoto <matz@netlab.co.jp>

* enum.c (enum_grep): non matching grep returns an empty array, no
longer returns nil.

* enum.c (enum_grep): grep with block returns collection of
evaluated values of block over matched elements.

Mon Nov 15 04:50:33 1999 Koji Arai <JCA02266@nifty.ne.jp>

* re.c (rb_reg_source): should not call rb_reg_expr_str()
everytime.

Sat Nov 13 07:34:18 1999 Yukihiro Matsumoto <matz@netlab.co.jp>

* variable.c (rb_mod_constants): traverse superclasses to collect
constants (shared variables).

* eval.c (assign): modified for shared variables.

* eval.c (rb_eval): search nested scope, then superclasses to
assign shared variables within methods.

* eval.c (rb_eval): remove warnings from constants modification,
becase they are no longer constants.

* parse.y (node_assign): modified for shared variables.

* parse.y (assignable): allow constant assignment in methods;
constants should be called `shared variable'.

Wed Nov 10 21:54:11 1999 EGUCHI Osamu <eguchi@shizuokanet.ne.jp>

* hash.c (rb_any_cmp): Fixed return without value.
Expand Down
8 changes: 6 additions & 2 deletions ToDo
Expand Up @@ -3,12 +3,14 @@ Language Spec.
- def foo; .. rescue .. end
- compile time string concatenation, "hello" "world" => "helloworld"
- rescue modifier; a rescue b => begin a rescue; b end
- assignable constant, which now should be called shared variable.
- class variable (prefix?) -- done by shared variable
* objectify symbols
* objectify characters
* ../... outside condition invokes operator method too.
* ... inside condition turns off just before right condition.???
* %w(a\ b\ c abc) => ["a b c", "abc"]
* package or access control for global variables
* class variable (prefix?)
* package or access control for global variables??
* named arguments like foo(nation:="german") or foo(nation: "german").
* method to retrieve argument information (need new C API)
* multiple return values, yield values. maybe incompatible ???
Expand All @@ -21,6 +23,7 @@ Hacking Interpreter

- use eban's fnmatch
- RUBYOPT environment variable
- alias $defout $>
* non-blocking open (e.g. for named pipe) for thread
* avoid blocking with gethostbyname/gethostbyaddr
* objectify interpreters
Expand All @@ -36,6 +39,7 @@ Standard Libraries
- Array#{first,last,at}
- Dir.glob(pat){|f|...}
- sprintf/printf's $ to specify argument order
* debugger for thread programming
* Dir.glob("**/*.c") ala zsh
* Struct::new([name,]member,...) ??
* String#scanf(?)
Expand Down
4 changes: 2 additions & 2 deletions class.c
Expand Up @@ -130,7 +130,7 @@ rb_define_class_under(outer, name, super)

id = rb_intern(name);
klass = rb_define_class_id(id, super);
rb_const_set(outer, id, klass);
rb_shvar_set(outer, id, klass);
rb_set_class_path(klass, outer, name);

return klass;
Expand Down Expand Up @@ -186,7 +186,7 @@ rb_define_module_under(outer, name)

id = rb_intern(name);
module = rb_define_module_id(id);
rb_const_set(outer, id, module);
rb_shvar_set(outer, id, module);
rb_set_class_path(module, outer, name);

return module;
Expand Down
19 changes: 8 additions & 11 deletions enum.c
Expand Up @@ -33,11 +33,11 @@ grep_i(i, arg)
}

static VALUE
grep_iter_i(i, pat)
VALUE i, pat;
grep_iter_i(i, arg)
VALUE i, *arg;
{
if (RTEST(rb_funcall(pat, id_eqq, 1, i))) {
rb_yield(i);
if (RTEST(rb_funcall(arg[0], id_eqq, 1, i))) {
rb_ary_push(arg[1], rb_yield(i));
}
return Qnil;
}
Expand All @@ -46,19 +46,16 @@ static VALUE
enum_grep(obj, pat)
VALUE obj, pat;
{
VALUE tmp, arg[2];

arg[0] = pat; arg[1] = tmp = rb_ary_new();
if (rb_iterator_p()) {
rb_iterate(rb_each, obj, grep_iter_i, pat);
return obj;
}
else {
VALUE tmp, arg[2];

arg[0] = pat; arg[1] = tmp = rb_ary_new();
rb_iterate(rb_each, obj, grep_i, (VALUE)arg);

if (RARRAY(tmp)->len == 0) return Qnil;
return tmp;
}
return tmp;
}

struct find_arg {
Expand Down
93 changes: 61 additions & 32 deletions eval.c
Expand Up @@ -1300,7 +1300,7 @@ superclass(self, node)
}

static VALUE
ev_const_defined(cref, id)
ev_shvar_defined(cref, id)
NODE *cref;
ID id;
{
Expand All @@ -1315,11 +1315,11 @@ ev_const_defined(cref, id)
}
cbase = cbase->nd_next;
}
return rb_const_defined(cref->nd_clss, id);
return rb_shvar_defined(cref->nd_clss, id);
}

static VALUE
ev_const_get(cref, id)
ev_shvar_get(cref, id)
NODE *cref;
ID id;
{
Expand All @@ -1329,13 +1329,34 @@ ev_const_get(cref, id)
while (cbase && cbase->nd_clss != rb_cObject) {
struct RClass *klass = RCLASS(cbase->nd_clss);

if (klass->iv_tbl &&
st_lookup(klass->iv_tbl, id, &result)) {
if (klass->iv_tbl && st_lookup(klass->iv_tbl, id, &result)) {
return result;
}
cbase = cbase->nd_next;
}
return rb_const_get(cref->nd_clss, id);
return rb_shvar_get(cref->nd_clss, id);
}

static VALUE
ev_shvar_set(cref, id, val)
NODE *cref;
ID id;
VALUE val;
{
NODE *cbase = cref;
VALUE tmp;

while (cbase && cbase->nd_clss != rb_cObject) {
struct RClass *klass = RCLASS(cbase->nd_clss);

if (klass->iv_tbl && st_lookup(klass->iv_tbl, id, 0)) {
st_insert(klass->iv_tbl, id, val);
return val;
}
cbase = cbase->nd_next;
}
rb_shvar_assign(cbase->nd_clss, id, val);
return val;
}

static VALUE
Expand All @@ -1352,17 +1373,17 @@ rb_mod_nesting()
}

static VALUE
rb_mod_s_constants()
rb_mod_s_shvars()
{
NODE *cbase = (NODE*)ruby_frame->cbase;
VALUE ary = rb_ary_new();

while (cbase && cbase->nd_clss != rb_cObject) {
rb_mod_const_at(cbase->nd_clss, ary);
rb_mod_shvar_at(cbase->nd_clss, ary);
cbase = cbase->nd_next;
}

rb_mod_const_of(((NODE*)ruby_frame->cbase)->nd_clss, ary);
rb_mod_shvar_of(((NODE*)ruby_frame->cbase)->nd_clss, ary);
return ary;
}

Expand Down Expand Up @@ -1585,7 +1606,7 @@ is_defined(self, node, buf)
break;

case NODE_CVAR:
if (ev_const_defined((NODE*)ruby_frame->cbase, node->nd_vid)) {
if (ev_shvar_defined((NODE*)ruby_frame->cbase, node->nd_vid)) {
return "constant";
}
break;
Expand All @@ -1601,7 +1622,7 @@ is_defined(self, node, buf)
switch (TYPE(val)) {
case T_CLASS:
case T_MODULE:
if (rb_const_defined_at(val, node->nd_mid))
if (rb_shvar_defined_at(val, node->nd_mid))
return "constant";
default:
if (rb_method_boundp(val, node->nd_mid, 1)) {
Expand Down Expand Up @@ -2392,13 +2413,15 @@ rb_eval(self, node)
rb_raise(rb_eTypeError, "no class/module to define constant");
}
result = rb_eval(self, node->nd_value);
/* check for static scope constants */
if (RTEST(ruby_verbose) &&
ev_const_defined((NODE*)ruby_frame->cbase, node->nd_vid)) {
rb_warn("already initialized constant %s",
rb_id2name(node->nd_vid));
ev_shvar_set((NODE*)ruby_frame->cbase, node->nd_vid, result);
break;

case NODE_CDECL:
if (NIL_P(ruby_class)) {
rb_raise(rb_eTypeError, "no class/module to define constant");
}
rb_const_set(ruby_class, node->nd_vid, result);
result = rb_eval(self, node->nd_value);
rb_shvar_set(ruby_class, node->nd_vid, result);
break;

case NODE_LVAR:
Expand All @@ -2421,7 +2444,7 @@ rb_eval(self, node)
break;

case NODE_CVAR:
result = ev_const_get((NODE*)ruby_frame->cbase, node->nd_vid);
result = ev_shvar_get((NODE*)ruby_frame->cbase, node->nd_vid);
break;

case NODE_BLOCK_ARG:
Expand All @@ -2448,12 +2471,12 @@ rb_eval(self, node)
default:
return rb_funcall(klass, node->nd_mid, 0, 0);
}
result = rb_const_get_at(klass, node->nd_mid);
result = rb_shvar_get(klass, node->nd_mid);
}
break;

case NODE_COLON3:
result = rb_const_get_at(rb_cObject, node->nd_mid);
result = rb_shvar_get(rb_cObject, node->nd_mid);
break;

case NODE_NTH_REF:
Expand Down Expand Up @@ -2754,12 +2777,12 @@ rb_eval(self, node)
}

klass = 0;
if (rb_const_defined_at(ruby_class, node->nd_cname) &&
if (rb_shvar_defined_at(ruby_class, node->nd_cname) &&
(ruby_class != rb_cObject || !rb_autoload_defined(node->nd_cname))) {
klass = rb_const_get_at(ruby_class, node->nd_cname);
klass = rb_shvar_get(ruby_class, node->nd_cname);
}
if (ruby_wrapper && rb_const_defined_at(rb_cObject, node->nd_cname)) {
klass = rb_const_get_at(rb_cObject, node->nd_cname);
if (ruby_wrapper && rb_shvar_defined_at(rb_cObject, node->nd_cname)) {
klass = rb_shvar_get(rb_cObject, node->nd_cname);
}
if (klass) {
if (TYPE(klass) != T_CLASS) {
Expand Down Expand Up @@ -2787,7 +2810,7 @@ rb_eval(self, node)
else {
if (!super) super = rb_cObject;
klass = rb_define_class_id(node->nd_cname, super);
rb_const_set(ruby_class, node->nd_cname, klass);
rb_shvar_set(ruby_class, node->nd_cname, klass);
rb_set_class_path(klass,ruby_class,rb_id2name(node->nd_cname));
}
if (ruby_wrapper) {
Expand All @@ -2807,13 +2830,13 @@ rb_eval(self, node)
rb_raise(rb_eTypeError, "no outer class/module");
}
module = 0;
if (rb_const_defined_at(ruby_class, node->nd_cname) &&
if (rb_shvar_defined_at(ruby_class, node->nd_cname) &&
(ruby_class != rb_cObject ||
!rb_autoload_defined(node->nd_cname))) {
module = rb_const_get_at(ruby_class, node->nd_cname);
module = rb_shvar_get(ruby_class, node->nd_cname);
}
if (ruby_wrapper && rb_const_defined_at(rb_cObject, node->nd_cname)) {
module = rb_const_get_at(rb_cObject, node->nd_cname);
if (ruby_wrapper && rb_shvar_defined_at(rb_cObject, node->nd_cname)) {
module = rb_shvar_get(rb_cObject, node->nd_cname);
}
if (module) {
if (TYPE(module) != T_MODULE) {
Expand All @@ -2826,7 +2849,7 @@ rb_eval(self, node)
}
else {
module = rb_define_module_id(node->nd_cname);
rb_const_set(ruby_class, node->nd_cname, module);
rb_shvar_set(ruby_class, node->nd_cname, module);
rb_set_class_path(module,ruby_class,rb_id2name(node->nd_cname));
}
if (ruby_wrapper) {
Expand Down Expand Up @@ -3368,7 +3391,11 @@ assign(self, lhs, val, check)
break;

case NODE_CASGN:
rb_const_set(ruby_class, lhs->nd_vid, val);
ev_shvar_set((NODE*)ruby_frame->cbase, lhs->nd_vid, val);
break;

case NODE_CDECL:
rb_shvar_set(ruby_class, lhs->nd_vid, val);
break;

case NODE_MASGN:
Expand Down Expand Up @@ -5317,7 +5344,9 @@ Init_eval()
rb_define_private_method(rb_cModule, "alias_method", rb_mod_alias_method, 2);

rb_define_singleton_method(rb_cModule, "nesting", rb_mod_nesting, 0);
rb_define_singleton_method(rb_cModule, "constants", rb_mod_s_constants, 0);
rb_define_singleton_method(rb_cModule, "shared_variables", rb_mod_s_shvars, 0);
/* to be removed at 1.6 */
rb_define_singleton_method(rb_cModule, "constants", rb_mod_s_shvars, 0);

rb_define_singleton_method(ruby_top_self, "include", top_include, -1);
rb_define_singleton_method(ruby_top_self, "public", top_public, -1);
Expand Down
19 changes: 11 additions & 8 deletions intern.h
Expand Up @@ -220,7 +220,7 @@ int yyparse _((void));
ID rb_id_attrset _((ID));
void rb_parser_append_print _((void));
void rb_parser_while_loop _((int, int));
int rb_is_const_id _((ID));
int rb_is_shvar_id _((ID));
int rb_is_instance_id _((ID));
VALUE rb_backref_get _((void));
void rb_backref_set _((VALUE));
Expand Down Expand Up @@ -310,7 +310,6 @@ VALUE rb_f_autoload _((VALUE, VALUE, VALUE));
void rb_gc_mark_global_tbl _((void));
VALUE rb_f_trace_var _((int, VALUE*));
VALUE rb_f_untrace_var _((int, VALUE*));
VALUE rb_gvar_set2 _((const char*, VALUE));
VALUE rb_f_global_variables _((void));
void rb_alias_variable _((ID, ID));
void rb_clone_generic_ivar _((VALUE,VALUE));
Expand All @@ -322,13 +321,17 @@ VALUE rb_ivar_set _((VALUE, ID, VALUE));
VALUE rb_ivar_defined _((VALUE, ID));
VALUE rb_obj_instance_variables _((VALUE));
VALUE rb_obj_remove_instance_variable _((VALUE, VALUE));
VALUE rb_mod_const_at _((VALUE, VALUE));
VALUE rb_mod_constants _((VALUE));
VALUE rb_mod_const_of _((VALUE, VALUE));
VALUE rb_mod_remove_const _((VALUE, VALUE));
int rb_const_defined_at _((VALUE, ID));
VALUE rb_mod_shvar_at _((VALUE, VALUE));
VALUE rb_mod_shvars _((VALUE));
VALUE rb_mod_shvar_of _((VALUE, VALUE));
VALUE rb_mod_remove_shvar _((VALUE, VALUE));
int rb_shvar_defined_at _((VALUE, ID));
int rb_autoload_defined _((ID));
int rb_const_defined _((VALUE, ID));
int rb_shvar_defined _((VALUE, ID));
VALUE rb_shvar_get _((VALUE, ID));
VALUE rb_shvar_get_at _((VALUE, ID));
void rb_shvar_set _((VALUE, ID, VALUE));
VALUE rb_mod_shared_variables _((VALUE));
/* version.c */
void ruby_show_version _((void));
void ruby_show_copyright _((void));

0 comments on commit 0d2a064

Please sign in to comment.