summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog2
-rw-r--r--eval.c89
-rw-r--r--instruby.rb3
-rw-r--r--lib/mailread.rb3
-rw-r--r--node.h9
-rw-r--r--rubytest.rb3
-rw-r--r--version.h4
7 files changed, 74 insertions, 39 deletions
diff --git a/ChangeLog b/ChangeLog
index 71c28746cd0..362247c1e30 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
Thu Mar 26 11:51:09 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
+ * eval.c (rb_call): new feature: `protected' methods.
+
* string.c (str_dump): new method.
* eval.c (block_pass): block argument can be nil, which means no
diff --git a/eval.c b/eval.c
index 50f288acdf1..1b8a99e2752 100644
--- a/eval.c
+++ b/eval.c
@@ -45,8 +45,12 @@ static VALUE block_pass _((VALUE,NODE*));
static VALUE cMethod;
static VALUE method_proc _((VALUE));
-#define SCOPE_PRIVATE FL_USER4
-#define SCOPE_MODFUNC FL_USER5
+#define SCOPE_PUBLIC 0
+#define SCOPE_PRIVATE FL_USER4
+#define SCOPE_PROTECTED FL_USER5
+#define SCOPE_MODFUNC (FL_USER4|FL_USER4)
+#define SCOPE_MASK (FL_USER4|FL_USER4)
+#define SCOPE_SET(x,f) do {FL_UNSET(x,SCOPE_MASK);FL_SET(x,(f))} while(0)
#define CACHE_SIZE 0x200
#define CACHE_MASK 0x1ff
@@ -755,13 +759,13 @@ ruby_init()
the_scope->local_tbl = 0;
top_scope = the_scope;
/* default visibility is private at toplevel */
- FL_SET(top_scope, SCOPE_PRIVATE);
- FL_UNSET(top_scope, SCOPE_MODFUNC);
+ SCOPE_SET(top_scope, SCOPE_PRIVATE);
PUSH_TAG(PROT_NONE)
if ((state = EXEC_TAG()) == 0) {
rb_call_inits();
the_class = cObject;
+ the_frame->self = TopSelf;
the_frame->cbase = (VALUE)node_newnode(NODE_CREF,cObject,0,0);
rb_define_global_const("TOPLEVEL_BINDING", f_binding(TopSelf));
ruby_prog_init();
@@ -2199,9 +2203,12 @@ rb_eval(self, node)
rb_clear_cache_by_id(node->nd_mid);
}
- if (FL_TEST(the_scope,SCOPE_PRIVATE) || node->nd_mid == init) {
+ if (FL_TEST(the_scope, SCOPE_PRIVATE) || node->nd_mid == init) {
noex = NOEX_PRIVATE;
}
+ else if (FL_TEST(the_scope, SCOPE_PROTECTED)) {
+ noex = NOEX_PROTECTED;
+ }
else {
noex = NOEX_PUBLIC;
}
@@ -2209,7 +2216,7 @@ rb_eval(self, node)
noex |= NOEX_UNDEF;
}
rb_add_method(the_class, node->nd_mid, node->nd_defn, noex);
- if (FL_TEST(the_scope,SCOPE_MODFUNC)) {
+ if (FL_TEST(the_scope,SCOPE_MODFUNC) == SCOPE_MODFUNC) {
rb_add_method(rb_singleton_class(the_class),
node->nd_mid, node->nd_defn, NOEX_PUBLIC);
rb_funcall(the_class, rb_intern("singleton_method_added"),
@@ -3023,8 +3030,10 @@ rb_ensure(b_proc, data1, e_proc, data2)
}
static int last_call_status;
-#define CSTAT_NOEX 1
-#define CSTAT_VCALL 2
+
+#define CSTAT_PRIV 1
+#define CSTAT_PROT 2
+#define CSTAT_VCALL 4
static VALUE
f_missing(argc, argv, obj)
@@ -3059,9 +3068,12 @@ f_missing(argc, argv, obj)
break;
}
if (desc) {
- if (last_call_status & CSTAT_NOEX) {
+ if (last_call_status & CSTAT_PRIV) {
format = "private method `%s' called for %s";
}
+ if (last_call_status & CSTAT_PROT) {
+ format = "protected method `%s' called for %s";
+ }
else if (iterator_p()) {
format = "undefined iterator `%s' for %s";
}
@@ -3455,8 +3467,12 @@ rb_call(klass, recv, mid, argc, argv, scope)
}
/* receiver specified form for private method */
- if (noex & NOEX_PRIVATE && scope == 0)
- return rb_undefined(recv, mid, argc, argv, CSTAT_NOEX);
+ if ((noex & NOEX_PRIVATE) && scope == 0)
+ return rb_undefined(recv, mid, argc, argv, CSTAT_PRIV);
+
+ /* self must be kind of a specified form for private method */
+ if ((noex & NOEX_PROTECTED) && !obj_is_kind_of(the_frame->self, klass))
+ return rb_undefined(recv, mid, argc, argv, CSTAT_PROT);
return rb_call0(klass, recv, id, argc, argv, body, noex & NOEX_UNDEF);
}
@@ -3802,24 +3818,16 @@ mod_module_eval(mod, src)
VALUE mod, src;
{
int state;
- int private, modfunc;
+ int mode;
VALUE result = Qnil;
- private = FL_TEST(the_scope, SCOPE_PRIVATE);
- modfunc = FL_TEST(the_scope, SCOPE_MODFUNC);
- FL_UNSET(the_scope, SCOPE_PRIVATE);
- FL_UNSET(the_scope, SCOPE_MODFUNC);
+ mode = FL_TEST(the_scope, SCOPE_MASK);
PUSH_TAG(PROT_NONE)
if ((state = EXEC_TAG()) == 0) {
result = eval_under(mod, mod, src);
}
POP_TAG();
- if (private) {
- FL_TEST(the_scope, SCOPE_PRIVATE);
- }
- if (modfunc) {
- FL_TEST(the_scope, SCOPE_MODFUNC);
- }
+ SCOPE_SET(the_scope, mode);
if (state) JUMP_TAG(state);
return result;
@@ -3896,8 +3904,7 @@ f_load(obj, fname)
the_scope->local_vars = vars;
}
/* default visibility is private at loading toplevel */
- FL_SET(the_scope, SCOPE_PRIVATE);
- FL_UNSET(top_scope, SCOPE_MODFUNC);
+ SCOPE_SET(the_scope, SCOPE_PRIVATE);
state = EXEC_TAG();
last_func = the_frame->last_func;
@@ -4089,8 +4096,7 @@ mod_public(argc, argv, module)
VALUE module;
{
if (argc == 0) {
- FL_UNSET(the_scope, SCOPE_PRIVATE);
- FL_UNSET(top_scope, SCOPE_MODFUNC);
+ SCOPE_SET(the_scope, SCOPE_PUBLIC);
}
else {
set_method_visibility(module, argc, argv, NOEX_PUBLIC);
@@ -4099,14 +4105,28 @@ mod_public(argc, argv, module)
}
static VALUE
+mod_protected(argc, argv, module)
+ int argc;
+ VALUE *argv;
+ VALUE module;
+{
+ if (argc == 0) {
+ SCOPE_SET(the_scope, SCOPE_PROTECTED);
+ }
+ else {
+ set_method_visibility(module, argc, argv, NOEX_PROTECTED);
+ }
+ return module;
+}
+
+static VALUE
mod_private(argc, argv, module)
int argc;
VALUE *argv;
VALUE module;
{
if (argc == 0) {
- FL_SET(the_scope, SCOPE_PRIVATE);
- FL_UNSET(top_scope, SCOPE_MODFUNC);
+ SCOPE_SET(the_scope, SCOPE_PRIVATE);
}
else {
set_method_visibility(module, argc, argv, NOEX_PRIVATE);
@@ -4143,6 +4163,14 @@ top_public(argc, argv)
}
static VALUE
+top_protected(argc, argv)
+ int argc;
+ VALUE *argv;
+{
+ return mod_protected(argc, argv, cObject);
+}
+
+static VALUE
top_private(argc, argv)
int argc;
VALUE *argv;
@@ -4161,8 +4189,7 @@ mod_modfunc(argc, argv, module)
NODE *body;
if (argc == 0) {
- FL_SET(the_scope, SCOPE_PRIVATE);
- FL_SET(the_scope, SCOPE_MODFUNC);
+ SCOPE_SET(the_scope, SCOPE_MODFUNC);
return module;
}
@@ -4392,6 +4419,7 @@ Init_eval()
rb_define_private_method(cModule, "extend_object", mod_extend_object, 1);
rb_define_private_method(cModule, "include", mod_include, -1);
rb_define_private_method(cModule, "public", mod_public, -1);
+ rb_define_private_method(cModule, "protected", mod_protected, -1);
rb_define_private_method(cModule, "private", mod_private, -1);
rb_define_private_method(cModule, "module_function", mod_modfunc, -1);
rb_define_method(cModule, "method_defined?", mod_method_defined, 1);
@@ -4408,6 +4436,7 @@ Init_eval()
rb_define_singleton_method(TopSelf, "include", top_include, -1);
rb_define_singleton_method(TopSelf, "public", top_public, -1);
+ rb_define_singleton_method(TopSelf, "protected", top_protected, -1);
rb_define_singleton_method(TopSelf, "private", top_private, -1);
rb_define_method(mKernel, "extend", obj_extend, -1);
diff --git a/instruby.rb b/instruby.rb
index 3d3f2a41730..47b7fcad9a8 100644
--- a/instruby.rb
+++ b/instruby.rb
@@ -1,4 +1,5 @@
-#!./miniruby
+#!./miniruby -I.
+
require "rbconfig.rb"
include Config
diff --git a/lib/mailread.rb b/lib/mailread.rb
index a5d60c84b47..8ec951e7541 100644
--- a/lib/mailread.rb
+++ b/lib/mailread.rb
@@ -15,7 +15,8 @@ class Mail
break if /^$/ # end of header
if /^(\S+):\s*(.*)/
- @header[attr = $1.capitalize!] = $2
+ (attr = $1).capitalize!
+ @header[attr] = $2
elsif attr
sub!(/^\s*/, '')
@header[attr] += "\n" + $_
diff --git a/node.h b/node.h
index a8e6ddb615c..04549d734c3 100644
--- a/node.h
+++ b/node.h
@@ -305,10 +305,11 @@ typedef struct RNode {
NODE *node_newnode();
VALUE rb_method_booundp();
-#define NOEX_PUBLIC 0
-#define NOEX_PRIVATE 1
-#define NOEX_UNDEF 2
-#define NOEX_CFUNC 2
+#define NOEX_PUBLIC 0
+#define NOEX_UNDEF 1
+#define NOEX_CFUNC 1
+#define NOEX_PRIVATE 2
+#define NOEX_PROTECTED 4
NODE *compile_string _((char *, char *, int));
NODE *compile_file _((char *, VALUE, int));
diff --git a/rubytest.rb b/rubytest.rb
index 4830c9a2617..cf583c1dfb5 100644
--- a/rubytest.rb
+++ b/rubytest.rb
@@ -1,4 +1,5 @@
-#! ./miniruby
+#! ./miniruby -I.
+
require 'rbconfig'
include Config
diff --git a/version.h b/version.h
index 1aceff6e7bc..6474e347cc4 100644
--- a/version.h
+++ b/version.h
@@ -1,2 +1,2 @@
-#define RUBY_VERSION "1.1b9_04"
-#define VERSION_DATE "98/03/19"
+#define RUBY_VERSION "1.1b9_05"
+#define VERSION_DATE "98/03/26"