Permalink
Browse files

19991117

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 0d2a06406ebd4f99046373e815473ed99046f7fe
Showing with 366 additions and 132 deletions.
  1. +39 −0 ChangeLog
  2. +6 −2 ToDo
  3. +2 −2 class.c
  4. +8 −11 enum.c
  5. +61 −32 eval.c
  6. +11 −8 intern.h
  7. +1 −0 io.c
  8. +11 −0 lib/pstore.rb
  9. +1 −0 lib/singleton.rb
  10. +2 −0 node.h
  11. +17 −11 object.c
  12. +26 −17 parse.y
  13. +1 −4 re.c
  14. +2 −2 ruby.c
  15. +4 −5 ruby.h
  16. +1 −1 sample/rename.rb
  17. +1 −1 struct.c
  18. +170 −34 variable.c
  19. +2 −2 version.h
View
@@ -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.
View
8 ToDo
@@ -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 ???
@@ -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
@@ -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(?)
View
@@ -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;
@@ -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;
View
19 enum.c
@@ -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;
}
@@ -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 {
View
93 eval.c
@@ -1300,7 +1300,7 @@ superclass(self, node)
}
static VALUE
-ev_const_defined(cref, id)
+ev_shvar_defined(cref, id)
NODE *cref;
ID id;
{
@@ -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;
{
@@ -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
@@ -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;
}
@@ -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;
@@ -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)) {
@@ -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:
@@ -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:
@@ -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:
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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:
@@ -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);
View
@@ -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));
@@ -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));
@@ -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));
Oops, something went wrong.

0 comments on commit 0d2a064

Please sign in to comment.