diff options
author | Yukihiro Matsumoto <[email protected]> | 1995-02-24 13:15:43 +0900 |
---|---|---|
committer | Takashi Kokubun <[email protected]> | 2019-08-17 22:09:31 +0900 |
commit | 881c5a9c320c637ee0f6526b40cf70c1379ab656 (patch) | |
tree | 3c0327fc9bdef8f056563ceee400226ac572535b | |
parent | 2f106ab85c4f4e171374aee261f5a12bdd923c41 (diff) |
version 0.68v0_68
https://cache.ruby-lang.org/pub/ruby/1.0/ruby-0.67-0.68.diff.gz
Fri Feb 24 13:15:43 1995 Yukihiro Matsumoto (matz@ix-02)
* version 0.68
Thu Feb 23 11:19:19 1995 Yukihiro Matsumoto (matz@ix-02)
* eval.c: resque節のselfの値が間違っていた.
* eval.c(rb_clear_cache): キャッシュのクリアし忘れがあった.
* eval.c: 定数のスコープをクラス内の静的スコープに変更した.これに
よって,特異メソッドからは参照される定数は,レシーバのクラスでは
なく,定義されたスコープのクラスの定数となる.
Wed Feb 22 00:51:38 1995 Yukihiro Matsumoto (matz@dyna)
* regex.c: ignorecaseを正規表現のコンパイル前に指定しないと正しく
動作しない.修正.
* string.c(toupper,tolower): bug fix.
* ENV,VERSION: readonly変数から定数へ.
-rw-r--r-- | ChangeLog | 36 | ||||
-rw-r--r-- | array.c | 2 | ||||
-rw-r--r-- | class.c | 22 | ||||
-rw-r--r-- | compar.c | 2 | ||||
-rw-r--r-- | cons.c | 2 | ||||
-rw-r--r-- | dbm.c | 2 | ||||
-rw-r--r-- | dict.c | 7 | ||||
-rw-r--r-- | dir.c | 2 | ||||
-rw-r--r-- | dln.c | 2 | ||||
-rw-r--r-- | enum.c | 2 | ||||
-rw-r--r-- | env.h | 2 | ||||
-rw-r--r-- | error.c | 2 | ||||
-rw-r--r-- | eval.c | 138 | ||||
-rw-r--r-- | file.c | 2 | ||||
-rw-r--r-- | gc.c | 4 | ||||
-rw-r--r-- | ident.h | 2 | ||||
-rw-r--r-- | inits.c | 2 | ||||
-rw-r--r-- | io.c | 33 | ||||
-rw-r--r-- | io.h | 2 | ||||
-rw-r--r-- | math.c | 2 | ||||
-rw-r--r-- | node.h | 99 | ||||
-rw-r--r-- | numeric.c | 2 | ||||
-rw-r--r-- | object.c | 2 | ||||
-rw-r--r-- | pack.c | 2 | ||||
-rw-r--r-- | parse.y | 134 | ||||
-rw-r--r-- | process.c | 2 | ||||
-rw-r--r-- | random.c | 2 | ||||
-rw-r--r-- | range.c | 2 | ||||
-rw-r--r-- | re.c | 50 | ||||
-rw-r--r-- | re.h | 2 | ||||
-rw-r--r-- | regex.c | 10 | ||||
-rw-r--r-- | ruby.c | 4 | ||||
-rw-r--r-- | ruby.h | 2 | ||||
-rw-r--r-- | sample/MANIFEST | 1 | ||||
-rw-r--r-- | sample/biorhythm.rb | 24 | ||||
-rw-r--r-- | sample/cbreak.rb | 4 | ||||
-rw-r--r-- | sample/clnt.rb | 2 | ||||
-rw-r--r-- | sample/from.rb | 100 | ||||
-rw-r--r-- | sample/io.rb | 2 | ||||
-rw-r--r-- | sample/ruby-mode.el | 6 | ||||
-rw-r--r-- | sample/svr.rb | 8 | ||||
-rwxr-xr-x | sample/time.rb | 2 | ||||
-rw-r--r-- | sample/trojan.rb | 2 | ||||
-rw-r--r-- | spec | 170 | ||||
-rw-r--r-- | sprintf.c | 2 | ||||
-rw-r--r-- | string.c | 17 | ||||
-rw-r--r-- | struct.c | 2 | ||||
-rw-r--r-- | time.c | 2 | ||||
-rw-r--r-- | variable.c | 15 | ||||
-rw-r--r-- | version.c | 11 | ||||
-rw-r--r-- | version.h | 4 |
51 files changed, 587 insertions, 368 deletions
@@ -1,3 +1,35 @@ +Fri Feb 24 13:15:43 1995 Yukihiro Matsumoto (matz@ix-02) + + * version 0.68 + +Thu Feb 23 11:19:19 1995 Yukihiro Matsumoto (matz@ix-02) + + * eval.c: resque���self���ͤ��ְ�äƤ����� + + * eval.c(rb_clear_cache): ����å���Υ��ꥢ��˺�줬���ä��� + + * eval.c: ����Υ������פ饹�����Ū�������פ��ѹ������������ + ��äơ��ðۥ�åɤ���ϻ��Ȥ��������ϡ��쥷���ФΥ��饹�Ǥ� + �ʤ���������줿�������פΥ��饹������Ȥʤ롥 + +Wed Feb 22 00:51:38 1995 Yukihiro Matsumoto (matz@dyna) + + * regex.c: ignorecase������ɽ���Υ���ѥ������˻��ꤷ�ʤ��������� + ư��ʤ��������� + + * string.c(toupper,tolower): bug fix. + + * ENV,VERSION: readonly�ѿ���������ء� + +Tue Feb 21 18:56:56 1995 Yukihiro Matsumoto (matz@ix-02) + + * io.c(STDIN, STDOUT, STDERR): ����Ȥ�����������ޤǤ�$stdin�ʤ� + �Ͼ���ʤ��ʤ뤫���Τ�ʤ��� + + * io.c(select): bug fix. + + * version 0.67 + Mon Feb 20 16:10:14 1995 Yukihiro Matsumoto (matz@ix-02) * parse.y(yylex): �����`%���̻�'���顤��1ʸ������ʸ���μ��̻Ҥ��� @@ -38,11 +70,15 @@ Fri Feb 10 16:30:00 1995 Yukihiro Matsumoto (matz@ix-02) Thu Feb 9 16:18:37 1995 Yukihiro Matsumoto (matz@ix-02) + * version 0.66 + * parse.y: protect��begin���ѹ���begin..end���㳰���������Ǥʤ��� ʸ��̤Ȥ��Ƥ�Ư�����Ȥˤʤä��� Wed Feb 1 19:48:24 1995 Yukihiro Matsumoto (matz@ix-02) + * version 0.65 + * string.c(str_replace): �֤�������ʸ�����Ĺ���������������ꥳ �ԡ��ʤ��� @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:42:18 $ created at: Fri Aug 6 09:46:12 JST 1993 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ @@ -6,7 +6,7 @@ $Date: 1995/01/12 08:54:44 $ created at: Tue Aug 10 15:05:44 JST 1993 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ @@ -203,7 +203,7 @@ rb_include_module(class, module) Check_Type(module, T_MODULE); if (BUILTIN_TYPE(class) == T_CLASS) { - rb_clear_cache2(class); + rb_clear_cache(class); } while (module) { @@ -224,24 +224,6 @@ rb_include_module(class, module) } void -rb_add_method(class, mid, node, noex) - struct RClass *class; - ID mid; - NODE *node; - int noex; -{ - NODE *body; - - if (class == Qnil) class = (struct RClass*)C_Object; - if (st_lookup(class->m_tbl, mid, &body)) { - Warning("redefine %s", rb_id2name(mid)); - rb_clear_cache(body); - } - body = NEW_METHOD(node, noex); - st_insert(class->m_tbl, mid, body); -} - -void rb_define_method(class, name, func, argc) struct RClass *class; char *name; @@ -6,7 +6,7 @@ $Date: 1994/10/14 06:19:05 $ created at: Thu Aug 26 14:39:48 JST 1993 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:30:37 $ created at: Fri Jan 6 10:10:36 JST 1995 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:42:24 $ created at: Mon Jan 24 15:59:52 JST 1994 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:42:26 $ created at: Mon Nov 22 18:51:18 JST 1993 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ @@ -614,7 +614,6 @@ Init_Dict() rb_define_method(C_Dict,"has_key", Fdic_has_key, 1); rb_define_method(C_Dict,"has_value", Fdic_has_value, 1); - envtbl = obj_alloc(C_Object); rb_define_single_method(envtbl,"[]", Fgetenv, 1); rb_define_single_method(envtbl,"[]=", Fsetenv, 2); @@ -624,7 +623,5 @@ Init_Dict() rb_include_module(CLASS_OF(envtbl), M_Enumerable); rb_define_variable("$ENV", &envtbl, Qnil, rb_readonly_hook, 0); - - rb_define_private_method(C_Kernel, "getenv", Fgetenv, 1); - rb_define_private_method(C_Kernel, "setenv", Fsetenv, 2); + rb_define_const(C_Kernel, "ENV", envtbl); } @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:42:28 $ created at: Wed Jan 5 09:51:01 JST 1994 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ @@ -6,7 +6,7 @@ $Date: 1994/12/09 01:28:23 $ created at: Tue Jan 18 17:05:06 JST 1994 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:42:29 $ created at: Fri Oct 1 15:15:19 JST 1993 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ @@ -30,4 +30,6 @@ struct SCOPE { extern int rb_in_eval; +extern struct RClass *the_class; + #endif /* ENV_H */ @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:42:31 $ created at: Mon Aug 9 16:11:34 JST 1993 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ @@ -6,7 +6,7 @@ $Date: 1995/01/12 08:54:45 $ created at: Thu Jun 10 14:22:17 JST 1993 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ @@ -19,7 +19,8 @@ #include <setjmp.h> #include "st.h" -void rb_clear_cache(); +static void rb_clear_cache_body(); +static void rb_clear_cache_entry(); /* #define TEST /* prints cache miss */ #ifdef TEST @@ -40,6 +41,27 @@ struct cache_entry { /* method hash table. */ static struct cache_entry cache[CACHE_SIZE]; +void +rb_add_method(class, mid, node, noex) + struct RClass *class; + ID mid; + NODE *node; + int noex; +{ + NODE *body; + + if (class == Qnil) class = (struct RClass*)C_Object; + if (st_lookup(class->m_tbl, mid, &body)) { + Warning("redefine %s", rb_id2name(mid)); + rb_clear_cache_body(body); + } + else { + rb_clear_cache_entry(class, mid); + } + body = NEW_METHOD(node, noex); + st_insert(class->m_tbl, mid, body); +} + static NODE* search_method(class, id, origin) struct RClass *class, **origin; @@ -116,7 +138,10 @@ rb_alias(class, name, def) if (st_lookup(class->m_tbl, name, &old)) { Warning("redefine %s", rb_id2name(name)); - rb_clear_cache(old->nd_body); + rb_clear_cache_body(body); + } + else { + rb_clear_cache_entry(class, name); } st_insert(class->m_tbl, name, @@ -158,8 +183,8 @@ rb_method_boundp(class, id) return FALSE; } -void -rb_clear_cache(body) +static void +rb_clear_cache_body(body) NODE *body; { struct cache_entry *ent, *end; @@ -174,8 +199,23 @@ rb_clear_cache(body) } } +static void +rb_clear_cache_entry(class, mid) + struct RClass *class; + ID mid; +{ + struct cache_entry *ent; + + /* is it in the method cache? */ + ent = cache + EXPR1(class, mid); + if (ent->mid == mid && ent->class == class) { + ent->class = Qnil; + ent->mid = Qnil; + } +} + void -rb_clear_cache2(class) +rb_clear_cache(class) struct RClass *class; { struct cache_entry *ent, *end; @@ -285,6 +325,7 @@ static struct tag { #define EXEC_TAG() (setjmp(prot_tag->buf)) #define JUMP_TAG(val) { \ + Qself = prot_tag->self; \ the_env = prot_tag->env; \ iter = prot_tag->iter; \ longjmp(prot_tag->buf,(val)); \ @@ -305,7 +346,7 @@ static struct tag { #define IN_BLOCK 0x08 -static struct RClass *the_class; +struct RClass *the_class; struct class_link { struct RClass *class; struct class_link *prev; @@ -338,6 +379,8 @@ VALUE rb_apply(); VALUE rb_xstring(); void rb_fail(); +static void module_setup(); + static VALUE masign(); static void asign(); @@ -396,6 +439,8 @@ ruby_init(argc, argv, envp) PUSH_TAG(); PUSH_ITER(ITER_NOT); if ((state = EXEC_TAG()) == 0) { + rb_call_inits(); + the_class = (struct RClass*)C_Object; ruby_init0(argc, argv, envp); } POP_ITER(); @@ -448,7 +493,6 @@ ruby_run() PUSH_TAG(); PUSH_ITER(ITER_NOT); if ((state = EXEC_TAG()) == 0) { - the_class = (struct RClass*)C_Object; Eval(); } POP_ITER(); @@ -1038,8 +1082,9 @@ rb_eval(node) case NODE_CVAR: { - VALUE val = rb_const_get(node->nd_vid); + VALUE val; + val = rb_const_get(node->nd_rval->nd_clss, node->nd_vid); nd_set_type(node, NODE_CONST); node->nd_cval = val; return val; @@ -1114,7 +1159,9 @@ rb_eval(node) list = list->nd_next; } if (nd_type(node) == NODE_DREGX) { - return regexp_new(RSTRING(str)->ptr, RSTRING(str)->len); + VALUE re = regexp_new(RSTRING(str)->ptr, RSTRING(str)->len, + node->nd_cflag); + return re; } if (nd_type(node) == NODE_XSTR2) { return rb_xstring(str); @@ -1195,17 +1242,8 @@ rb_eval(node) class = rb_define_class_id(node->nd_cname, super); rb_const_set(the_class, node->nd_cname, class); - PUSH_CLASS(); - the_class = (struct RClass*)class; - PUSH_SELF((VALUE)the_class); - PUSH_TAG(); - if ((state = EXEC_TAG()) == 0) { - rb_eval(node->nd_body); - } - POP_TAG(); - POP_SELF(); - POP_CLASS(); - if (state) JUMP_TAG(state); + + module_setup(class, node->nd_body); return class; } @@ -1219,17 +1257,8 @@ rb_eval(node) module = rb_define_module_id(node->nd_cname); rb_const_set(the_class, node->nd_cname, module); - PUSH_CLASS(); - the_class = (struct RClass*)module; - PUSH_SELF((VALUE)the_class); - PUSH_TAG(); - if ((state = EXEC_TAG()) == 0) { - rb_eval(node->nd_body); - } - POP_TAG(); - POP_SELF(); - POP_CLASS(); - if (state) JUMP_TAG(state); + + module_setup(module, node->nd_body); return module; } @@ -1237,7 +1266,7 @@ rb_eval(node) { struct RClass *module; - module = (struct RClass*)rb_const_get(node->nd_modl); + module = (struct RClass*)rb_const_get(CLASS_OF(Qself), node->nd_modl); if (module == Qnil) { Fail("undefined module %s", rb_id2name(node->nd_modl)); } @@ -1251,6 +1280,49 @@ rb_eval(node) return Qnil; /* not reached */ } +static void +module_setup(module, node) + VALUE module; + NODE *node; +{ + int state; + + /* fill c-ref */ + node->nd_clss = module; + node = node->nd_body; + + PUSH_CLASS(); + the_class = (struct RClass*)module; + PUSH_SELF((VALUE)the_class); + PUSH_SCOPE(); + PUSH_TAG(); + + if (node->nd_cnt > 0) { + the_scope->local_vars = ALLOCA_N(VALUE, node->nd_cnt); + MEMZERO(the_scope->local_vars, VALUE, node->nd_cnt); + the_scope->local_tbl = node->nd_tbl; + } + else { + the_scope->local_vars = Qnil; + the_scope->local_tbl = Qnil; + } + + if ((state = EXEC_TAG()) == 0) { + rb_eval(node->nd_body); + } + + POP_TAG(); + if (!(the_scope->flags & SCOPE_MALLOCED)) { + the_scope->local_vars = Qnil; + the_scope->local_tbl = Qnil; + } + if (state != 0) JUMP_TAG(state); + POP_SCOPE(); + POP_SELF(); + POP_CLASS(); + if (state) JUMP_TAG(state); +} + VALUE obj_responds_to(obj, msg) VALUE obj; @@ -7,7 +7,7 @@ $Date: 1995/01/10 10:42:36 $ created at: Mon Nov 15 12:24:34 JST 1993 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ @@ -6,7 +6,7 @@ $Date: 1995/01/12 08:54:47 $ created at: Tue Oct 5 09:44:46 JST 1993 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ @@ -513,7 +513,7 @@ obj_free(obj) break; case T_MODULE: case T_CLASS: - rb_clear_cache2(obj); + rb_clear_cache(obj); st_free_table(obj->as.class.m_tbl); if (obj->as.object.iv_tbl) st_free_table(obj->as.object.iv_tbl); break; @@ -7,7 +7,7 @@ $Date: 1994/08/12 04:47:29 $ created at: Mon Jan 31 16:23:19 JST 1994 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:42:38 $ created at: Tue Dec 28 16:01:58 JST 1993 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:42:39 $ created at: Fri Oct 15 18:08:59 JST 1993 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ @@ -334,9 +334,8 @@ Fio_gets(obj) if (str) { fptr->lineno++; lineno = INT2FIX(fptr->lineno); - return rb_lastline = (VALUE)str; } - return Qnil; + return rb_lastline = (VALUE)str; } static VALUE @@ -936,22 +935,18 @@ rb_xstring(str) struct timeval *time_timeval(); -#ifdef STDSTDIO -# define READ_PENDING(fp) ((fp)->_cnt != 0) -#else -# ifdef __SLBF -# define READ_PENDING(fp) ((fp)->_r > 0) -# else -# ifdef __linux__ +#ifdef _STDIO_USES_IOSTREAM /* GNU libc */ # ifdef _other_gbase -# define READ_PENDING(fp) ((fp)->_IO_read_ptr < (fp)->_IO_read_end) +# define READ_DATA_PENDING(fp) ((fp)->_IO_read_ptr < (fp)->_IO_read_end) # else -# define READ_PENDING(fp) ((fp)->_gptr < (fp)->_egptr) +# define READ_DATA_PENDING(fp) ((fp)->_gptr < (fp)->_egptr) # endif -# else +#elif __SLBF +# define READ_DATA_PENDING(fp) (fp->_r > 0) +#elif STDSTDIO +# define READ_DATA_PENDING(fp) (fp->_cnt != 0) +#else --------------> You Lose <-------------- -# endif -# endif #endif static VALUE @@ -968,7 +963,7 @@ Fselect(argc, argv, obj) int i, max = 0, n; int interrupt = 0; - rb_scan_args(argc, argv, argv, "13", &read, &write, &except, &timeout); + rb_scan_args(argc, argv, "13", &read, &write, &except, &timeout); if (timeout) { tp = time_timeval(timeout); } @@ -986,7 +981,7 @@ Fselect(argc, argv, obj) for (i=0; i<RARRAY(read)->len; i++) { GetOpenFile(RARRAY(read)->ptr[i], fptr); FD_SET(fileno(fptr->f), rp); - if (READ_PENDING(fptr->f)) { /* check for buffered data */ + if (READ_DATA_PENDING(fptr->f)) { /* check for buffered data */ pending++; FD_SET(fileno(fptr->f), &pset); } @@ -1395,6 +1390,10 @@ Init_IO() rb_defout = rb_stdout; rb_define_variable("$>", &rb_defout, Qnil, io_defset, 0); + rb_define_const(C_Object, "STDIN", rb_stdin); + rb_define_const(C_Object, "STDOUT", rb_stdout); + rb_define_const(C_Object, "STDERR", rb_stderr); + argf = obj_alloc(C_Object); rb_define_variable("$<", &argf, Qnil, rb_readonly_hook, 0); rb_define_variable("$ARGF", &argf, Qnil, rb_readonly_hook, 0); @@ -7,7 +7,7 @@ $Date: 1994/08/12 11:06:42 $ created at: Fri Nov 12 16:47:09 JST 1993 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ @@ -6,7 +6,7 @@ $Date: 1994/11/01 08:28:03 $ created at: Tue Jan 25 14:12:56 JST 1994 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:42:41 $ created at: Fri May 28 15:14:02 JST 1993 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ @@ -70,6 +70,7 @@ enum node_type { NODE_UNDEF, NODE_CLASS, NODE_MODULE, + NODE_CREF, NODE_INC, NODE_DOT3, NODE_ATTRSET, @@ -165,73 +166,77 @@ typedef struct RNode { #define nd_super u3.id #define nd_modl u1.id +#define nd_clss u1.value #define nd_beg u1.node #define nd_end u2.node #define nd_state u3.state #define nd_rval u3.node -#define NEW_METHOD(n,x) newnode(NODE_METHOD,x,n,Qnil) +#define NEW_METHOD(n,x) newnode(NODE_METHOD,x,n,0) #define NEW_FBODY(n,i,o) newnode(NODE_FBODY,n,i,o) -#define NEW_DEFN(i,d,p) newnode(NODE_DEFN,p,i,d) -#define NEW_DEFS(r,i,d) newnode(NODE_DEFS,r,i,d) -#define NEW_CFUNC(f,c) newnode(NODE_CFUNC,f,c,Qnil) +#define NEW_DEFN(i,a,d,p) newnode(NODE_DEFN,p,i,NEW_RFUNC(a,d)) +#define NEW_DEFS(r,i,a,d) newnode(NODE_DEFS,r,i,NEW_RFUNC(a,d)) +#define NEW_CFUNC(f,c) newnode(NODE_CFUNC,f,c,0) #define NEW_RFUNC(b1,b2) NEW_SCOPE(block_append(b1,b2)) #define NEW_SCOPE(b) newnode(NODE_SCOPE,local_tbl(),(b),local_cnt(0)) -#define NEW_BLOCK(a) newnode(NODE_BLOCK,a,1,Qnil) +#define NEW_BLOCK(a) newnode(NODE_BLOCK,a,1,0) #define NEW_IF(c,t,e) newnode(NODE_IF,c,t,e) -#define NEW_EXNOT(c) newnode(NODE_EXNOT,c,Qnil,Qnil) -#define NEW_CASE(h,b) newnode(NODE_CASE,h,b,Qnil) +#define NEW_EXNOT(c) newnode(NODE_EXNOT,c,0,0) +#define NEW_CASE(h,b) newnode(NODE_CASE,h,b,0) #define NEW_WHEN(c,t,e) newnode(NODE_WHEN,c,t,e) -#define NEW_WHILE(c,b) newnode(NODE_WHILE,c,b,Qnil) -#define NEW_WHILE2(c,b) newnode(NODE_WHILE2,c,b,Qnil) +#define NEW_WHILE(c,b) newnode(NODE_WHILE,c,b,0) +#define NEW_WHILE2(c,b) newnode(NODE_WHILE2,c,b,0) #define NEW_FOR(v,i,b) newnode(NODE_FOR,v,b,i) #define NEW_ITER(v,i,b) newnode(NODE_ITER,v,b,i) #define NEW_BEGIN(b,ex,en) newnode(NODE_BEGIN,b,ex,en) -#define NEW_REDO() newnode(NODE_REDO,Qnil,Qnil,Qnil) -#define NEW_BREAK() newnode(NODE_BREAK,Qnil,Qnil,Qnil) -#define NEW_CONT() newnode(NODE_CONTINUE,Qnil,Qnil,Qnil) -#define NEW_RETRY() newnode(NODE_RETRY,Qnil,Qnil,Qnil) -#define NEW_RET(s) newnode(NODE_RETURN,s,Qnil,Qnil) -#define NEW_FAIL(s) newnode(NODE_FAIL,s,Qnil,Qnil) -#define NEW_YIELD(a) newnode(NODE_YIELD,a,Qnil,Qnil) +#define NEW_REDO() newnode(NODE_REDO,0,0,0) +#define NEW_BREAK() newnode(NODE_BREAK,0,0,0) +#define NEW_CONT() newnode(NODE_CONTINUE,0,0,0) +#define NEW_RETRY() newnode(NODE_RETRY,0,0,0) +#define NEW_RET(s) newnode(NODE_RETURN,s,0,0) +#define NEW_FAIL(s) newnode(NODE_FAIL,s,0,0) +#define NEW_YIELD(a) newnode(NODE_YIELD,a,0,0) #define NEW_LIST(a) NEW_ARRAY(a) -#define NEW_ARRAY(a) newnode(NODE_ARRAY,a,1,Qnil) -#define NEW_ZARRAY() newnode(NODE_ZARRAY,Qnil,Qnil,Qnil) -#define NEW_HASH(a) newnode(NODE_HASH,a,Qnil,Qnil) -#define NEW_AND(a,b) newnode(NODE_AND,a,b,Qnil) -#define NEW_OR(a,b) newnode(NODE_OR,a,b,Qnil) -#define NEW_NOT(a) newnode(NODE_NOT,Qnil,a,Qnil) -#define NEW_MASGN(l,r) newnode(NODE_MASGN,l,r,Qnil) +#define NEW_ARRAY(a) newnode(NODE_ARRAY,a,1,0) +#define NEW_ZARRAY() newnode(NODE_ZARRAY,0,0,0) +#define NEW_HASH(a) newnode(NODE_HASH,a,0,0) +#define NEW_AND(a,b) newnode(NODE_AND,a,b,0) +#define NEW_OR(a,b) newnode(NODE_OR,a,b,0) +#define NEW_NOT(a) newnode(NODE_NOT,0,a,0) +#define NEW_MASGN(l,r) newnode(NODE_MASGN,l,r,0) #define NEW_GASGN(v,val) newnode(NODE_GASGN,v,val,rb_global_entry(v)) #define NEW_LASGN(v,val) newnode(NODE_LASGN,v,val,local_cnt(v)) -#define NEW_IASGN(v,val) newnode(NODE_IASGN,v,val,Qnil) -#define NEW_CASGN(v,val) newnode(NODE_CASGN,v,val,Qnil) +#define NEW_IASGN(v,val) newnode(NODE_IASGN,v,val,0) +#define NEW_CASGN(v,val) newnode(NODE_CASGN,v,val,0) #define NEW_OP_ASGN1(p,id,a) newnode(NODE_OP_ASGN1,p,id,a) #define NEW_OP_ASGN2(r,i,val) newnode(NODE_OP_ASGN1,r,val,i) -#define NEW_GVAR(v) newnode(NODE_GVAR,v,Qnil,rb_global_entry(v)) -#define NEW_LVAR(v) newnode(NODE_LVAR,v,Qnil,local_cnt(v)) -#define NEW_LVAR2(v) newnode(NODE_LVAR2,v,Qnil,local_cnt(v)) -#define NEW_IVAR(v) newnode(NODE_IVAR,v,Qnil,Qnil) -#define NEW_CVAR(v) newnode(NODE_CVAR,v,Qnil,Qnil) -#define NEW_LIT(l) newnode(NODE_LIT,l,Qnil,Qnil) -#define NEW_STR(s) newnode(NODE_STR,s,Qnil,Qnil) -#define NEW_STR2(s) newnode(NODE_STR2,s,Qnil,Qnil) -#define NEW_XSTR(s) newnode(NODE_XSTR,s,Qnil,Qnil) -#define NEW_XSTR2(s) newnode(NODE_XSTR2,s,Qnil,Qnil) +#define NEW_GVAR(v) newnode(NODE_GVAR,v,0,rb_global_entry(v)) +#define NEW_LVAR(v) newnode(NODE_LVAR,v,0,local_cnt(v)) +#define NEW_LVAR2(v) newnode(NODE_LVAR2,v,0,0) +#define NEW_IVAR(v) newnode(NODE_IVAR,v,0,0) +#define NEW_CVAR(v) newnode(NODE_CVAR,v,0,cref_list) +#define NEW_LIT(l) newnode(NODE_LIT,l,0,0) +#define NEW_STR(s) newnode(NODE_STR,s,0,0) +#define NEW_STR2(s) newnode(NODE_STR2,s,0,0) +#define NEW_XSTR(s) newnode(NODE_XSTR,s,0,0) +#define NEW_XSTR2(s) newnode(NODE_XSTR2,s,0,0) #define NEW_CALL(r,m,a) newnode(NODE_CALL,r,m,a) -#define NEW_SUPER(a) newnode(NODE_SUPER,Qnil,Qnil,a) -#define NEW_ZSUPER() newnode(NODE_ZSUPER,Qnil,Qnil,Qnil) -#define NEW_ARGS(f,r) newnode(NODE_ARGS,Qnil,r,f) -#define NEW_ALIAS(n,o) newnode(NODE_ALIAS,Qnil,n,o) -#define NEW_UNDEF(i) newnode(NODE_UNDEF,Qnil,i,Qnil) -#define NEW_CLASS(n,b,s) newnode(NODE_CLASS,n,NEW_SCOPE(b),s) -#define NEW_MODULE(n,b) newnode(NODE_MODULE,n,NEW_SCOPE(b),Qnil) -#define NEW_INC(m) newnode(NODE_INC,m,Qnil,Qnil) +#define NEW_SUPER(a) newnode(NODE_SUPER,0,0,a) +#define NEW_ZSUPER() newnode(NODE_ZSUPER,0,0,0) +#define NEW_ARGS(f,r) newnode(NODE_ARGS,0,r,f) +#define NEW_ALIAS(n,o) newnode(NODE_ALIAS,0,n,o) +#define NEW_UNDEF(i) newnode(NODE_UNDEF,0,i,0) +#define NEW_CLASS(n,b,s) newnode(NODE_CLASS,n,NEW_CBODY(b),s) +#define NEW_MODULE(n,b) newnode(NODE_MODULE,n,NEW_CBODY(b),0) +#define NEW_CREF0() (cref_list=newnode(NODE_CREF,the_class,0,0)) +#define NEW_CREF(b) (cref_list=newnode(NODE_CREF,0,0,cref_list)) +#define NEW_CBODY(b) (cref_list->nd_body=NEW_SCOPE(b),cref_list) +#define NEW_INC(m) newnode(NODE_INC,m,0,0) #define NEW_DOT3(b,e) newnode(NODE_DOT3,b,e,0) -#define NEW_ATTRSET(a) newnode(NODE_ATTRSET,a,Qnil,Qnil) -#define NEW_SELF() newnode(NODE_SELF,Qnil,Qnil,Qnil) -#define NEW_NIL() newnode(NODE_NIL,Qnil,Qnil,Qnil) +#define NEW_ATTRSET(a) newnode(NODE_ATTRSET,a,0,0) +#define NEW_SELF() newnode(NODE_SELF,0,0,0) +#define NEW_NIL() newnode(NODE_NIL,0,0,0) NODE *newnode(); VALUE rb_method_booundp(); @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:42:42 $ created at: Fri Aug 13 18:33:09 JST 1993 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ @@ -6,7 +6,7 @@ $Date: 1995/01/12 08:54:49 $ created at: Thu Jul 15 12:01:24 JST 1993 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ @@ -6,7 +6,7 @@ $Date: 1994/12/09 09:40:22 $ created at: Thu Feb 10 15:17:05 JST 1994 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ @@ -47,8 +47,9 @@ static enum lex_state { EXPR_FNAME, /* ignore newline, +/- is a operator. */ } lex_state; -static ID cur_class = Qnil, cur_mid = Qnil; -static int in_module, in_single; +static int class_nest = 0; +static int in_single = 0; +static ID cur_mid = Qnil; static int value_expr(); static NODE *cond(); @@ -66,16 +67,20 @@ static NODE *asignable(); static NODE *aryset(); static NODE *attrset(); -static void push_local(); -static void pop_local(); -static int local_cnt(); -static int local_id(); -static ID *local_tbl(); +static void local_push(); +static void local_pop(); +static int local_cnt(); +static int local_id(); +static ID *local_tbl(); + +#define cref_push() NEW_CREF(0) +static void cref_pop(); +static NODE *cref_list; struct global_entry* rb_global_entry(); -static void init_top_local(); -static void setup_top_local(); +static void top_local_init(); +static void top_local_setup(); %} %union { @@ -182,12 +187,12 @@ static void setup_top_local(); %% program : { lex_state = EXPR_BEG; - init_top_local(); + top_local_init(); } compexpr { eval_tree = block_append(eval_tree, $2); - setup_top_local(); + top_local_setup(); } compexpr : exprs opt_term @@ -719,6 +724,7 @@ primary : literal | primary '{' opt_iter_var '|' compexpr rbrace { if (nd_type($1) == NODE_LVAR + || nd_type($1) == NODE_LVAR2 || nd_type($1) == NODE_CVAR) { $1 = NEW_CALL(Qnil, $1->nd_vid, Qnil); } @@ -787,59 +793,61 @@ primary : literal if (cur_mid || in_single) Error("class definition in method body"); - cur_class = $2; - push_local(); + class_nest++; + cref_push(); + local_push(); } compexpr END { $$ = NEW_CLASS($2, $5, $3); - pop_local(); - cur_class = Qnil; + local_pop(); + cref_pop(); + class_nest--; } | MODULE CONSTANT { if (cur_mid || in_single) Error("module definition in method body"); - cur_class = $2; - in_module = 1; - push_local(); + class_nest++; + cref_push(); + local_push(); } compexpr END { $$ = NEW_MODULE($2, $4); - pop_local(); - cur_class = Qnil; - in_module = 0; + local_pop(); + cref_pop(); + class_nest--; } | DEF fname { if (cur_mid || in_single) Error("nested method definition"); cur_mid = $2; - push_local(); + local_push(); } f_arglist compexpr END { - $$ = NEW_DEFN($2, NEW_RFUNC($4, $5), cur_class?0:1); - pop_local(); + $$ = NEW_DEFN($2, $4, $5, class_nest?1:0); + local_pop(); cur_mid = Qnil; } | DEF singleton '.' fname { value_expr($2); in_single++; - push_local(); + local_push(); } f_arglist compexpr END { - $$ = NEW_DEFS($2, $4, NEW_RFUNC($6, $7)); - pop_local(); + $$ = NEW_DEFS($2, $4, $6, $7); + local_pop(); in_single--; } @@ -1084,7 +1092,6 @@ rbracket : ']' { yyerrok; } rbrace : '}' { yyerrok; } comma : ',' { yyerrok; } %% - #include <ctype.h> #include <sys/types.h> #include "regex.h" @@ -1221,8 +1228,7 @@ parse_regx() return DREGEXP; } else { - yylval.val = regexp_new(tok(), toklen()); - if (casefold) FL_SET(yylval.val, FL_USER1); + yylval.val = regexp_new(tok(), toklen(), casefold); return REGEXP; } case -1: @@ -1560,24 +1566,24 @@ retry: return '|'; case '+': - if (lex_state == EXPR_BEG || lex_state == EXPR_MID) { - c = nextc(); - pushback(); - if (isdigit(c)) { - goto start_num; - } - lex_state = EXPR_BEG; - return UPLUS; - } - else if (lex_state == EXPR_FNAME) { + if (lex_state == EXPR_FNAME) { if ((c = nextc()) == '@') { return UPLUS; } pushback(); return '+'; } + c = nextc(); + if (lex_state != EXPR_END) { + pushback(); + if (isdigit(c)) { + goto start_num; + } + lex_state = EXPR_BEG; + return UMINUS; + } lex_state = EXPR_BEG; - if ((c = nextc()) == '=') { + if (c == '=') { yylval.id = '+'; return OP_ASGN; } @@ -1585,8 +1591,15 @@ retry: return '+'; case '-': - if (lex_state == EXPR_BEG || lex_state == EXPR_MID) { - c = nextc(); + if (lex_state == EXPR_FNAME) { + if ((c = nextc()) == '@') { + return UMINUS; + } + pushback(); + return '-'; + } + c = nextc(); + if (lex_state != EXPR_END) { pushback(); if (isdigit(c)) { c = '-'; @@ -1595,15 +1608,8 @@ retry: lex_state = EXPR_BEG; return UMINUS; } - else if (lex_state == EXPR_FNAME) { - if ((c = nextc()) == '@') { - return UMINUS; - } - pushback(); - return '-'; - } lex_state = EXPR_BEG; - if ((c = nextc()) == '=') { + if (c == '=') { yylval.id = '-'; return OP_ASGN; } @@ -2448,8 +2454,8 @@ attrset(recv, id, val) { value_expr(recv); value_expr(val); - - id &= ~ID_SCOPE_MASK; + + id &= ~ID_SCOPE_MASK; id |= ID_ATTRSET; return NEW_CALL(recv, id, NEW_LIST(val)); @@ -2555,7 +2561,7 @@ static struct local_vars { } *lvtbl; static void -push_local() +local_push() { struct local_vars *local; @@ -2567,7 +2573,7 @@ push_local() } static void -pop_local() +local_pop() { struct local_vars *local = lvtbl; @@ -2620,10 +2626,10 @@ local_id(id) } static void -init_top_local() +top_local_init() { if (lvtbl == Qnil) { - push_local(); + local_push(); } else if (the_scope->local_tbl) { lvtbl->cnt = the_scope->local_tbl[0]; @@ -2638,10 +2644,11 @@ init_top_local() else { lvtbl->tbl = Qnil; } + NEW_CREF0(); /* initialize constant c-ref */ } static void -setup_top_local() +top_local_setup() { int len = lvtbl->cnt; int i; @@ -2676,6 +2683,16 @@ setup_top_local() free(lvtbl->tbl); } } + cref_list = Qnil; +} + +static void +cref_pop() +{ + NODE *cref = cref_list; + + cref_list = cref_list->nd_next; + cref->nd_next = Qnil; } void @@ -2758,6 +2775,7 @@ Init_sym() int strcmp(); sym_tbl = st_init_table(strcmp, st_strhash); + rb_global_variable(&cref_list); } ID @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:42:47 $ created at: Tue Aug 10 14:30:50 JST 1993 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:42:48 $ created at: Fri Dec 24 16:39:21 JST 1993 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ @@ -6,7 +6,7 @@ $Date: 1994/12/06 09:30:12 $ created at: Thu Aug 19 17:46:47 JST 1993 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:42:49 $ created at: Mon Aug 9 18:24:49 JST 1993 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ @@ -84,7 +84,7 @@ str_cicmp(str1, str2) return str1->len - str2->len; } -Regexp* +static Regexp* make_regexp(s, len) char *s; int len; @@ -108,6 +108,7 @@ int len; if ((err = re_compile_pattern(s, (size_t)len, &(rp->pat))) != NULL) Fail("%s: /%s/", err, s); + return rp; } @@ -118,26 +119,27 @@ struct match { }; struct match last_match; +VALUE ignorecase; int -research(reg, str, start, ignorecase) +research(reg, str, start) struct RRegexp *reg; struct RString *str; int start; - int ignorecase; { int result; + int casefold = ignorecase; /* case-flag set for the object */ if (FL_TEST(reg, FL_USER1)) { - ignorecase = 1; + casefold = TRUE; } - if (ignorecase) + if (casefold) reg->ptr->pat.translate = casetable; else reg->ptr->pat.translate = NULL; - if (start >= str->len) return -1; + if (start > str->len) return -1; result = re_search(&(reg->ptr->pat), str->ptr, str->len, start, str->len - start, &(reg->ptr->regs)); @@ -290,14 +292,13 @@ const char *s; Fail(s); } -VALUE ignorecase; VALUE C_Regexp; static VALUE -regexp_new_1(class, s, len) +regexp_new_1(class, s, len, ci) VALUE class; char *s; - int len; + int len, ci; { NEWOBJ(re, struct RRegexp); OBJSETUP(re, class, T_REGEXP); @@ -307,15 +308,17 @@ regexp_new_1(class, s, len) memcpy(re->str, s, len); re->str[len] = '\0'; re->len = len; + + if (ci) FL_SET(re, FL_USER1); return (VALUE)re; } VALUE -regexp_new(s, len) +regexp_new(s, len, ci) char *s; - int len; + int len, ci; { - return regexp_new_1(C_Regexp, s, len); + return regexp_new_1(C_Regexp, s, len, ci); } static VALUE str_cache, reg_cache; @@ -329,7 +332,7 @@ re_regcomp(str) return reg_cache; str_cache = (VALUE)str; - return reg_cache = regexp_new(str->ptr, str->len); + return reg_cache = regexp_new(str->ptr, str->len, ignorecase); } VALUE @@ -340,7 +343,7 @@ Freg_match(re, str) int start; Check_Type(str, T_STRING); - start = research(re, str, 0, ignorecase); + start = research(re, str, 0); if (start == -1) { return Qnil; } @@ -357,7 +360,7 @@ Freg_match2(re) if (TYPE(rb_lastline) != T_STRING) Fail("$_ is not a string"); - start = research(re, rb_lastline, 0, ignorecase); + start = research(re, rb_lastline, 0); if (start == -1) { return Qnil; } @@ -371,27 +374,27 @@ Sreg_new(argc, argv, self) VALUE self; { VALUE src, reg; + int ci = 0; if (argc == 0 || argc > 2) { Fail("wrong # of argument"); } + if (argc == 2 && argv[1]) { + ci = 1; + } src = argv[0]; switch (TYPE(src)) { case T_STRING: - reg = regexp_new_1(self, RREGEXP(src)->ptr, RREGEXP(src)->len); + reg = regexp_new_1(self, RREGEXP(src)->ptr, RREGEXP(src)->len, ci); case T_REGEXP: - reg = regexp_new_1(self, RREGEXP(src)->str, RREGEXP(src)->len); + reg = regexp_new_1(self, RREGEXP(src)->str, RREGEXP(src)->len, ci); default: Check_Type(src, T_STRING); } - if (argc == 2 && argv[1]) { - FL_SET(reg, FL_USER1); - } - return Qnil; } @@ -429,7 +432,8 @@ static VALUE Freg_clone(re) struct RRegexp *re; { - return regexp_new_1(CLASS_OF(re), re->str, re->len); + int ci = FL_TEST(re, FL_USER1); + return regexp_new_1(CLASS_OF(re), re->str, re->len, ci); } VALUE @@ -7,7 +7,7 @@ $Date: 1994/08/12 04:47:52 $ created at: Thu Sep 30 14:18:32 JST 1993 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ @@ -1633,12 +1633,12 @@ re_compile_fastmap (bufp) #endif { case exactn: -#if 0 /* The original was: */ +#if 1 /* The original was: */ if (translate) fastmap[translate[p[1]]] = 1; else fastmap[p[1]] = 1; -#else /* The compiled pattern has already been translated. */ +#else /* The compiled pattern has already been translated. (not true for ruby) */ fastmap[p[1]] = 1; #endif break; @@ -1775,7 +1775,7 @@ re_compile_fastmap (bufp) for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--) if (p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH))) { -#if 0 /* The original was: */ +#if 1 /* The original was: */ if (translate) fastmap[translate[j]] = 1; else @@ -2911,7 +2911,9 @@ re_match_2 (pbufp, string1_arg, size1, string2_arg, size2, pos, regs, mstop) goto fail; continue; } - if ((unsigned char) translate[c] != (unsigned char) *p++) + /* compiled code translation needed for ruby */ + if ((unsigned char) translate[c] + != (unsigned char) translate[*p++]) goto fail; } while (--mcnt); @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:42:51 $ created at: Tue Aug 10 12:47:31 JST 1993 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ @@ -421,8 +421,6 @@ ruby_init0(argc, argv, envp) origargc = argc; origargv = argv; origenvp = envp; - rb_call_inits(); - rb_define_variable("$@", &errat, Qnil, Qnil, 0); errat = str_new2(argv[0]); rb_define_variable("$VERBOSE", &verbose, Qnil, Qnil, 0); @@ -6,7 +6,7 @@ $Date: 1995/01/12 08:54:52 $ created at: Thu Jun 10 14:26:32 JST 1993 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto *************************************************/ diff --git a/sample/MANIFEST b/sample/MANIFEST index c91c078e39..93c971b114 100644 --- a/sample/MANIFEST +++ b/sample/MANIFEST @@ -20,6 +20,7 @@ fib.pl fib.rb fib.scm freq.rb +from.rb fullpath.pl fullpath.rb gctest.rb diff --git a/sample/biorhythm.rb b/sample/biorhythm.rb index eb14ca7365..5a452e0078 100644 --- a/sample/biorhythm.rb +++ b/sample/biorhythm.rb @@ -76,9 +76,9 @@ end # parseArgs(0, nil, "vg", "D:", "sdate", "date:", "birthday:", "days:") -printf($stderr, "\n") -printf($stderr, "Biorhythm (c) 1987-1994 V3.0\n") -printf($stderr, "\n") +printf(STDERR, "\n") +printf(STDERR, "Biorhythm (c) 1987-1994 V3.0\n") +printf(STDERR, "\n") if ($OPT_D) dtmp = Time.now.strftime("%Y%m%d") jh = dtmp[0,4].to_i @@ -94,11 +94,11 @@ else if ($OPT_birthday) dtmp = $OPT_birthday else - printf($stderr, "Birthday (YYYYMMDD) : ") - dtmp = $stdin.gets.chop + printf(STDERR, "Birthday (YYYYMMDD) : ") + dtmp = STDIN.gets.chop end if (dtmp.length != 8) - printf($stderr, "BAD Input Birthday!!\n") + printf(STDERR, "BAD Input Birthday!!\n") exit() end jg = dtmp[0,4].to_i @@ -112,8 +112,8 @@ else elsif ($OPT_date) dtmp = $OPT_date else - printf($stderr, "Date [<RETURN> for Systemdate] (YYYYMMDD) : ") - dtmp = $stdin.gets.chop + printf(STDERR, "Date [<RETURN> for Systemdate] (YYYYMMDD) : ") + dtmp = STDIN.gets.chop end if (dtmp.length != 8) dtmp = Time.now.strftime("%Y%m%d") @@ -127,8 +127,8 @@ else elsif ($OPT_g) ausgabeart = "g" else - printf($stderr, "Values for today or Graph (v/g) [default g] : ") - ausgabeart = $stdin.gets.chop + printf(STDERR, "Values for today or Graph (v/g) [default g] : ") + ausgabeart = STDIN.gets.chop end end if (ausgabeart == "v") @@ -151,8 +151,8 @@ else if ($OPT_D) ktage = 9 else - printf($stderr, "Graph for how many days [default 10] : ") - ktage = $stdin.gets.chop + printf(STDERR, "Graph for how many days [default 10] : ") + ktage = STDIN.gets.chop if (ktage == "") ktage = 9 else diff --git a/sample/cbreak.rb b/sample/cbreak.rb index 5d2d849512..cbb15d2f41 100644 --- a/sample/cbreak.rb +++ b/sample/cbreak.rb @@ -15,7 +15,7 @@ end def set_cbreak (on) tty = "\0" * 256 - $stdin.ioctl(TIOCGETP, tty) + STDIN.ioctl(TIOCGETP, tty) ttys = tty.unpack("C4 S") if on ttys[4] |= CBREAK @@ -25,7 +25,7 @@ def set_cbreak (on) ttys[4] |= ECHO end tty = ttys.pack("C4 S") - $stdin.ioctl(TIOCSETP, tty) + STDIN.ioctl(TIOCSETP, tty) end cbreak(); diff --git a/sample/clnt.rb b/sample/clnt.rb index a687d12211..d2c71ec563 100644 --- a/sample/clnt.rb +++ b/sample/clnt.rb @@ -2,7 +2,7 @@ # usage: ruby clnt.rb [host] port host=(if $ARGV.length == 2; $ARGV.shift; else "localhost"; end) print("Trying ", host, " ...") -$stdout.flush +STDOUT.flush s = TCPsocket.open(host, $ARGV.shift) print(" done\n") print("addr: ", s.addr.join(":"), "\n") diff --git a/sample/from.rb b/sample/from.rb new file mode 100644 index 0000000000..f6602943af --- /dev/null +++ b/sample/from.rb @@ -0,0 +1,100 @@ +#! /usr/local/bin/ruby + +$= = TRUE + +module ParseDate + MONTHS = { + 'jan' => 1, 'feb' => 2, 'mar' => 3, 'apr' => 4, + 'may' => 5, 'jun' => 6, 'jul' => 7, 'aug' => 8, + 'sep' => 9, 'oct' =>10, 'nov' =>11, 'dec' =>12 } + MONTHPAT = MONTHS.keys.join('|') + DAYPAT = 'mon|tue|wed|thu|fri|sat|sun' + + def ParseDate.parsedate(date) + if date.sub(/(#{DAYPAT})/i, ' ') + dayofweek = $1 + end + if date.sub(/\s+(\d+:\d+(:\d+)?)/, ' ') + time = $1 + end + if date =~ /19\d\d/ + year = $& + end + if date.sub(/\s*(\d+)\s+(#{MONTHPAT})\S*\s+/, ' ') + dayofmonth = $1 + monthname = $2 + elsif date.sub(/\s*(#{MONTHPAT})\S*\s+(\d+)\s+/, ' ') + monthname = $1 + dayofmonth = $2 + elsif date.sub(/\s*(#{MONTHPAT})\S*\s+(\d+)\D+/, ' ') + monthname = $1 + dayofmonth = $2 + elsif date.sub(/\s*(\d\d?)\/(\d\d?)/, ' ') + month = $1 + dayofmonth = $2 + end + if monthname + month = MONTHS[monthname.tolower] + end + if ! year && date =~ /\d\d/ + year = $& + end + return year, month, dayofmonth + end + +end + + def parsedate(date) + ParseDate.parsedate(date) + end + +# include ParseDate + +if $ARGV[0] == '-w' + wait = TRUE + $ARGV.shift +end + +$ARGV[0] = '/usr/spool/mail/' + ENV['USER'] if $ARGV.length == 0 + +$outcount = 0; +def fromout(date, from, subj) + y, m, d = parsedate(date) + printf "%-2d/%02d/%02d [%.28s] %.40s\n", y, m, d, from, subj + $outcount += 1 +end + +while TRUE + fields = {} + while gets() + $_.chop + continue if /^From / # skip From-line + break if /^[ \t]*$/ # end of header + if /^(\S+):\s*(.*)/ + fields[attr = $1] = $2 + elsif attr + sub(/^\s*/, '') + fields[attr] += "\n" + $_ + end + end + + break if ! $_ + + fromout fields['Date'], fields['From'], fields['Subject'] + + while gets() +# print $_ + break if /^From / + end + + break if ! $_ +end + +if $outcount == 0 + print "You have no mail.\n" + sleep 2 if wait +elsif wait + system "stty cbreak -echo" + getc() + system "stty cooked echo" +end diff --git a/sample/io.rb b/sample/io.rb index c3c1a47b28..c12e4f4498 100644 --- a/sample/io.rb +++ b/sample/io.rb @@ -1,7 +1,7 @@ # IO test # usage: ruby io.rb file.. -home = getenv("HOME") +home = ENV["HOME"] home.sub("m", "&&") print(home, "\n") print(home.reverse, "\n") diff --git a/sample/ruby-mode.el b/sample/ruby-mode.el index 20e1abebc9..aa91be330d 100644 --- a/sample/ruby-mode.el +++ b/sample/ruby-mode.el @@ -321,12 +321,12 @@ An end of a defun is found by moving forward from the beginning of one." (defun ruby-reindent-then-newline-and-indent () (interactive "*") - (save-excursion - (delete-region (point) (progn (skip-chars-backward " \t") (point)))) (insert ?\n) (save-excursion (forward-line -1) - (indent-according-to-mode)) + (indent-according-to-mode) + (end-of-line) + (delete-region (point) (progn (skip-chars-backward " \t") (point)))) (indent-according-to-mode)) (defun ruby-encomment-region (beg end) diff --git a/sample/svr.rb b/sample/svr.rb index 91faa56dd8..23b2bf71f6 100644 --- a/sample/svr.rb +++ b/sample/svr.rb @@ -2,7 +2,9 @@ # usage: ruby svr.rb gs = TCPserver.open(0) -printf("server port is on %d\n", gs.port) +addr = gs.addr +addr.shift +printf("server is on %d\n", addr.join(":")) socks = [gs] while TRUE @@ -10,7 +12,9 @@ while TRUE if nsock == nil; continue end for s in nsock[0] if s == gs - socks.push(s.accept) + ns = s.accept + socks.push(ns) + print(s, " is accepted\n") else if s.eof print(s, " is gone\n") diff --git a/sample/time.rb b/sample/time.rb index b0ef065ce3..715d98ac9e 100755 --- a/sample/time.rb +++ b/sample/time.rb @@ -5,4 +5,4 @@ system(cmd) e = Time.now ut, st, cut, cst = Time.times total = (e - b).to_f -printf $stderr, "%11.1f real %11.1f user %11.1f sys\n", total, cut, cst +printf STDERR, "%11.1f real %11.1f user %11.1f sys\n", total, cut, cst diff --git a/sample/trojan.rb b/sample/trojan.rb index b42fd166a8..2024da0908 100644 --- a/sample/trojan.rb +++ b/sample/trojan.rb @@ -1,5 +1,5 @@ #! /usr/local/bin/ruby -path = $ENV['PATH'].split(/:/) +path = ENV['PATH'].split(/:/) for dir in path if File.d(dir) @@ -86,8 +86,8 @@ tab)�� CR(carriage return)������(form feed)�Ǥ��롥����(newline)������ a + b -�Τ褦�˹Ԥ���������ǽ��ꡤ���ιԤ�³�����Ȥ�����ʾ�����������ζ� -�ڤ�Ȥ��Ƥ�ǧ������롥 +�Τ褦�˹Ԥ���������ǽ��ꡤ���ιԤ�³�����Ȥ������(�Ǹ�������ʸ�� +���黻�Ҥ��뤤��`,'�Ǥ���)������������ζ��ڤ�Ȥ���ǧ������롥 * �ץ������ @@ -96,19 +96,17 @@ tab)�� CR(carriage return)������(form feed)�Ǥ��롥����(newline)������ print "hello world!\n" �ץ������ϼ����¤٤���ΤǤ��롥���ȼ��δ֤ϥ��ߥ�����(`;')�ޤ��ϲ� -�ԤǶ��ڤ���(��)�� - -�� �������ιԤ˷�³���뤳�Ȥ�����ʻ��ˤϲ��Ԥϼ��ζ��ڤ�ˤʤ�ʤ��� +�ԤǶ��ڤ��롥 * �� -Ruby�Ǥ�nil����������ʳ�������ɾ������롥C��Perl �ʤɤȤϰۤʤꡤ0�� +Ruby�Ǥ�nil����������ʳ�������ɾ������롥C��Perl�ʤɤȤϰۤʤꡤ0�� ""(��ʸ����)�ϵ��Ȥ�ɾ������ʤ��Τǵ���Ĥ��뤳�ȡ� ** ʸ���� - "..." # �Хå�����å���β����ѿ�Ÿ������ - '...' # �Хå�����å���β��ʤ�(\\��\'�ϲ�᤹��) +���֥륯������(`"')�dz��줿ʸ����ϥХå�����å����³��ʸ�����ʲ� +�Τ褦�˲�ᤵ��롥 �Хå�����å��嵭ˡ @@ -125,17 +123,14 @@ Ruby�Ǥ�nil����������ʳ�������ɾ������롥C��Perl �ʤɤȤϰۤʤꡤ0�� \^c ����ȥ�����ʸ��(c��ASCIIʸ��) \C-c ����ȥ�����ʸ��(Ʊ��) \M-c �ʸ��(c|0x80) - \����ʳ� ʸ�����Τ�� - -ʸ���������ʸ���֥������Ȥ���������Τǡ�ʸ��������Ƥ��� -�����Ƥ��Ȥ�Ȥ�ʸ������Ѥ��ʤ��� + \x ʸ��x���Τ�� -�ѿ�Ÿ�� +�ޤ���`#'�ˤ���ѿ�Ÿ����Ԥ��롥���������륯������(`'')�dz��� +��ʸ����ϡ�`\\'(�Хå�����å��夽�Τ��)��`\''(���륯������)��� +���ơ�ʸ�������Ȥβ���Ԥ�ʤ��� -���֥륯������(`"')�ǰϤޤ줿ʸ���������ɽ������Ǥ� `#{�ѿ�̾}'�Ȥ� -���������ѿ������Ƥ�Ÿ�����뤳�Ȥ��Ǥ��롥�ѿ����ѿ�����(`$',`@')�ǻ� -�ޤ���ˤ�`#�ѿ�̾'�Ȥ��������Ǥ�Ÿ���Ǥ��롥ʸ��`#'��³��ʸ���� -`{',`$',`@'�Ǥʤ���С����Τޤ�`#'�Ȥ��Ʋ�ᤵ��롥 +ʸ���������ʸ���֥������Ȥ���������Τǡ�ʸ��������Ƥ��� +�����Ƥ⡤��Ȥ�Ȥ�ʸ������Ѥ��ʤ��� ** ���ޥ�ɽ��� @@ -146,7 +141,8 @@ Ruby�Ǥ�sh�Τ褦�˥��ޥ�ɤμ¹Է�̤�ʸ�����ƥ��Τ褦�˻Ȥ����Ȥ� ** ����ɽ���� - /.../[i] +`/'�ǰϤޤ줿ʸ���������ɽ����ɽ���������`/'�θ����ʸ��`i'��Ϳ���� +�줿���ˤϡ���������ɽ���ϥޥå�������ʸ����ʸ���ζ��̤ʤ��� ^ ��Ƭ $ ���� @@ -168,8 +164,7 @@ Ruby�Ǥ�sh�Τ褦�˥��ޥ�ɤμ¹Է�̤�ʸ�����ƥ��Τ褦�˻Ȥ����Ȥ� | ���� ( ) ����ɽ����ޤȤ�� -����¾��ʸ�����Ʊ���Хå�����å��嵭ˡ���ѿ�Ÿ����ͭ���Ǥ��롥����ɽ -���θ����i���Ĥ������ˤ���ʸ����ʸ���ΰ㤤��̵�뤹�롥 +����¾��ʸ�����Ʊ���Хå�����å��嵭ˡ���ѿ�Ÿ����ͭ���Ǥ��롥 ** �磻��ɥ����ɼ� @@ -182,6 +177,14 @@ Ruby�Ǥ�sh�Τ褦�˥��ޥ�ɤμ¹Է�̤�ʸ�����ƥ��Τ褦�˻Ȥ����Ȥ� ����¾��ʸ�����Ʊ���Хå�����å��嵭ˡ���ѿ�Ÿ����ͭ���Ǥ��롥 +** �ѿ�Ÿ�� + +���֥륯������(`"')�ǰϤޤ줿ʸ�������ޥ��ʸ��������ɽ�������� +�ӥ磻��ɥ����ɼ�����Ǥ�`#{�ѿ�̾}'�Ȥ����������ѿ������Ƥ�Ÿ������ +���Ȥ��Ǥ��롥�ѿ����ѿ�����(`$',`@')�ǻϤޤ���ˤ�`#�ѿ�̾'�Ȥ����� +���Ǥ�Ÿ���Ǥ��롥ʸ��`#'��³��ʸ���� `{',`$',`@'�Ǥʤ���С����Τޤ� +ʸ��`#'�Ȥ��Ʋ�ᤵ��롥 + ** ���ͥ�ƥ�� 123 ���� @@ -237,11 +240,11 @@ Ruby���ѿ��ϥ�������(ͭ���ϰ�)�ȼ�̿(ͭ������)�ˤ�ä�4�����ʬ�व�졤 FOOBAR -��ʸ���ǻϤޤ뼱�̻ҤϤϥ��饹����ؤΥ��������Ǥ��ꡤ���Υ��饹������ -�Υ��֥��饹�Υ������黲�ȤǤ��롥��������ؤϥȥåץ�٥롤�� -�ʤ����åɤ�����Ǥ����٥�ǤΤ�������ǽ�Ǥ��롥�����ѿ��ϥ��饹 -�֤��ͤ���ͭ���졤��������������ͤ��ѹ����뤳�Ȥ��Ǥ��ʤ������饹��� -�μ�̿�ϥ��饹�μ�̿���������� +��ʸ���ǻϤޤ뼱�̻Ҥϥ��饹����ؤΥ��������Ǥ��ꡤ���Υ��饹�����Ƥ� +���֥��饹�Υ���������ǻ��ȤǤ��롥����ؤ������ϥȥåץ�٥롤���ʤ� +����åɤ�����Ǥ����٥�ǤΤ߲�ǽ�Ǥ��롥�����ѿ��ϥ��饹�֤��ͤ� +��ͭ���졤��������������ͤ��ѹ����뤳�Ȥ��Ǥ��ʤ������饹����μ�̿�� +���饹�μ�̿���������� ���饹����ϼ�ưŪ��������������Τǡ����饹̾������Ǥ��롥 @@ -254,8 +257,10 @@ Ruby���ѿ��ϥ�������(ͭ���ϰ�)�ȼ�̿(ͭ������)�ˤ�ä�4�����ʬ�व�졤 ��ʸ���ޤ���`_'�ǻϤޤ뼱�̻Ҥϥ��������ѿ��ؤΥ��������Ǥ��롥����� ����ʤ����������ѿ����ͤ�nil�Ǥ��� -���������ѿ��Υ������פϼ�̿�⤽�Υ֥��å��ν���ޤ�(�ȥåץ�٥�Υ��� -�����ѿ��ϥץ������ν�λ�ޤ�)�Ǥ��롥 +���������ѿ��Υ������פϥ֥��å����ϰ���(��å���Ǥϥ�åɤν��� +�ޤǡ����饹/�⥸�塼�������ǤϤ�������ν���ޤ�)�Ǥ��롥��̿�⤽�� +�֥��å��ν���ޤ�(�ȥåץ�٥�Υ��������ѿ��ϥץ������ν�λ�ޤ�)�� +���롥 *** �����ѿ� @@ -274,7 +279,6 @@ Ruby���ѿ��ϥ�������(ͭ���ϰ�)�ȼ�̿(ͭ������)�ˤ�ä�4�����ʬ�व�졤 ��: (1+2)*3 - (foo();bar()) ���ϳ�̤ˤ�äƥ��롼�ԥ��뤳�Ȥ��Ǥ��롥 @@ -352,10 +356,12 @@ Ruby���ѿ��ϥ�������(ͭ���ϰ�)�ȼ�̿(ͭ������)�ˤ�ä�4�����ʬ�व�졤 foo -1 # ���������ѿ�foo - 1 �쥷���Ф���ꤷ����åɸƤӽФ��ǤϤξ�������1�Ĥ�ʤ����ˤ��� -���ά�Ǥ��롥 +���ά�Ǥ���(�쥷���Ф���ꤷ�ʤ���硤��̤�Ĥ��ʤ��ȥ��������ѿ��� +���ȤȤ��Ʋ�ᤵ���)�� -��å�̾�Ȥ��Ƥ�Ǥ�դμ��̻Ҥ��Ѥ��뤳�Ȥ��Ǥ��롥�ѿ�̾�Ȥϼ��̻Ҥ� -̾�����֤��㤦�Τǽ�ʣ���Ƥ��ʤ��� +��å�̾�Ȥ��Ƥ�Ǥ�դμ��̻Ҥ��Ѥ��뤳�Ȥ��Ǥ��롥�ǽ��ʸ������ʸ�� +�Ǥ⾮ʸ���Ǥ��ʤ����ѿ�̾�Ȥϼ��̻Ҥ�̾�����֤��㤦�Τǽ�ʣ���Ƥ� +����ʤ��� ���饹���ʸ�γ��ǻ��ꤵ�줿��åɤȥ��饹Module��unexport��åɤ� ���ꤵ�줿��åɤϴؿ�Ū��åɤȸƤФ졤�ؿ������Ǥ����ƤӽФ����� @@ -516,9 +522,9 @@ Ruby���ѿ��ϥ�������(ͭ���ϰ�)�ȼ�̿(ͭ������)�ˤ�ä�4�����ʬ�व�졤 �������Ǥ�����( ��1 `[' ��2.. `]' `=' ��n) - ��1. `[]=' (��2..) + ��1. `[]=' (��2.., ��n) -����ʳ���2��黻��(�� �黻�� ��) +����ʳ���2��黻��(��1 �黻�� ��2) ��1. �黻�� (��2) @@ -535,9 +541,9 @@ Ruby���ѿ��ϥ�������(ͭ���ϰ�)�ȼ�̿(ͭ������)�ˤ�ä�4�����ʬ�व�졤 ��.. ] end -���Ƚ�Ǽ�����1�����ξ��˼�1��ɾ�����롥����ʳ��ξ��ϼ�2��ɾ���� -�롥Ruby��if����else if�Ǥ�elif�Ǥ�ʤ�elsif��if��Ϣ³��Ԥʤ����Ȥ��� -�դ��뤳�ȡ� +���Ƚ�Ǽ���Ruby��if����else if�Ǥ�elif�Ǥ�ʤ�elsif��if��Ϣ³��Ԥʤ� +���Ȥ����դ��뤳�ȡ���郎��Ω���Ƽ¹Ԥ��������ͤ��֤����¹Ԥ��ʤ��ä� +�����ͤ�nil�� if�ξ��Ƚ�����μ��Ǥ�ʸ���������ɽ����ƥ��ϼ���$_=~ ��ƥ��פ� ��ά�Ǥ���Ȥߤʤ���롥 @@ -613,9 +619,8 @@ or��ξ�դμ��Ǥ�ʸ���������ɽ����ƥ��ϼ���$_=~ ��ƥ��פξ�ά�� ��1�����ˤʤ�ޤǤϵ����֤������θ�ϼ�2�������֤��ޤǤϿ����֤�����2 �����ˤʤ�о��֤ϵ�����롥 -�黻��`...'��ξ�դϾ�P�Ǥ��ꡤ���� `...'��ξ�դμ��Ǥ�ʸ��������� -ɽ����ƥ��ϼ���$_=~ ��ƥ��פξ�ά�������������$.==����פξ�ά -�Ȳ�ᤵ��롥 +`...'��ξ�դμ��Ǥ�ʸ���������ɽ����ƥ��ϼ���$_=~ ��ƥ��פξ�ά�� +��������ϡ�$.==����פξ�ά�Ȳ�ᤵ��롥 ** NOT �� @@ -626,7 +631,6 @@ or��ξ�դμ��Ǥ�ʸ���������ɽ����ƥ��ϼ���$_=~ ��ƥ��פξ�ά�� `!'���Ǥ�ʸ���������ɽ����ƥ��ϼ���$_=~ ��ƥ��פξ�ά�Ǥ���Ȥ� �ʤ���롥 - ��1 `!=' ��2 ��!(��1 == ��2)�פξ�ά�� @@ -663,9 +667,6 @@ while�ξ��Ƚ�����μ��Ǥ�ʸ���������ɽ����ƥ��ϼ���$_=~ ��ƥ��� ���ƥ졼���θƤӽФ��ϰʲ��ι�ʸ�ǹԤʤ��롥 -���ƥ졼���Ȥ����湽¤(�ä˥롼��)����ݲ��Τ�����Ѥ������åɤ� -���Ǥ��롥���ƥ졼���θƤӽФ��ϰʲ��ι�ʸ�ǹԤʤ��롥 - �� `{' ���ռ�.. `|' ��.. `}' �ּ��פ�֥��å��Ȥ������ꤷ���ּ��פΥ�åɤƥ졼���Ȥ���ɾ���� @@ -673,7 +674,7 @@ while�ξ��Ƚ�����μ��Ǥ�ʸ���������ɽ����ƥ��ϼ���$_=~ ��ƥ��� �쥷���Ф�ɽ�����䡤�����μ��ϥ��ƥ졼���Ȥ��ƤϸƤӽФ���ʤ����ּ��� ��ʣ���μ���ޤ�����ơ������ƥ졼���Ȥ��ƽ�˸ƤФ�롥 -���ƥ졼�����yield�����¹Ԥ����ȡ������ǻ��ꤵ�줿�ͤ�do���ǻ��ꤵ +���ƥ졼�����yield�����¹Ԥ����ȡ������ǻ��ꤵ�줿�ͤ����ռ��ǻ��ꤵ �줿�ѿ����������졤�֥��å����¹Ԥ���롥�֥��å��μ¹Ԥ���λ����Ȥ� ���ͤ� yield�����ͤȤ����֤���롥�����åɤ����ƥ졼���Ȥ��ƸƤӽ� ���줿���ɤ����ϥ�å�iterator_p()������ͤ��Τ뤳�Ȥ��Ǥ��롥��ˤ� @@ -714,11 +715,12 @@ yield�ΰ����γ�̤�ۣ��Ǥʤ��¤��ά�Ǥ��롥 �㳰��ȯ�������롥��å�������Ϳ����줿���ˤ�ȯ�������������ե����� ̾�����ֹ���ƥ��ѿ�`$@'�ˡ���å�������`$!'�˥��åȤ��롥 -fail�ΰ����γ�̤�ۣ��Ǥʤ��¤��ά�Ǥ��롥 +fail�ΰ����γ�̤Ͼ�ά�Ǥ��롥 ** BEGIN -ʣ���μ���ޤȤ�뤿���begin�������롥begin���η����ϰʲ����̤�Ǥ��롥 +ʣ���μ���ޤȤ�뤿����㳰�����Τ����begin�������롥begin���η����� +�ʲ����̤�Ǥ��롥 begin ��.. @@ -729,10 +731,10 @@ fail�ΰ����γ�̤�ۣ��Ǥʤ��¤��ά�Ǥ��롥 end begin�����ͤϰ��ֺǸ��ɾ�����줿�����ͤǤ��롥begin���ν������ȯ���� -�������㳰��resque�����ͤ��뤳�Ȥ�����롥���ξ����ͤ�resque���Ǻ� -���ɾ�����������ͤǤ��롥����ensure�¸�ߤ������begin����λ���� -����ɬ��(���ェλ�������Ǥʤ����㳰, return, break, continue, redo�ʤ� -�ˤ��æ�ФǤ�)ensure��μ���ɾ�����롥 +�������㳰��resque�����ͤ��뤳�Ȥ�����롥���ξ�����begin�����ͤ� +��resque���ǺǸ��ɾ�����������ͤǤ��롥����ensure�¸�ߤ������ +begin����λ��������ɬ��(���ェλ�������Ǥʤ����㳰, return, break, +continue, redo�ʤɤˤ��æ�ФǤ�)ensure��μ���ɾ�����롥 ** RETURN @@ -750,6 +752,7 @@ break �ϥ롼�פ�æ�Ф��롥C�Ȱ㤤��break�Ϥ�äȤ���¦�Υ롼�פ�æ�Ф� ����Ѥ����������case ��ȴ������Ѥϻ����ʤ��� ** CONTINUE + continue continue�Ϥ�äȤ���¦�Υ롼�פμ��η����֤���Ϥ�롥 @@ -776,8 +779,7 @@ begin����resque��ǻȤ���begin����Ϥᤫ��¹Ԥ��롥�㳰������Ԥʤä� ������� end -���饹̾��Ǥ�դμ��̻ҤǤ���(��ʸ���ǻϤ�뤳�Ȥ�侩����)�����饹��� -�Υͥ��ȤϤǤ��ʤ��Τ�¾���������Ǥϥ��饹������Ǥ��ʤ��� +���饹̾����ʸ���ǻϤޤ뼱�̻ҤǤ��롥 ** �⥸�塼����� @@ -787,8 +789,7 @@ begin����resque��ǻȤ���begin����Ϥᤫ��¹Ԥ��롥�㳰������Ԥʤä� ������� end -�⥸�塼��̾����ʸ���ǻϤޤ뼱�̻ҤǤ��롥���饹Ʊ�͡��⥸�塼������� -�ͥ��ȤǤ��ʤ��� +�⥸�塼��̾����ʸ���ǻϤޤ뼱�̻ҤǤ��롥 ** ��å���� @@ -830,23 +831,22 @@ begin����resque��ǻȤ���begin����Ϥᤫ��¹Ԥ��롥�㳰������Ԥʤä� ��ɬ�פ����롥�̾��å�����Ȥϰۤʤꡤ�ðۥ�åɤϥ�å������� �Ǥ�ͥ��Ȥ���������뤳�Ȥ��Ǥ��롥 -�ðۥ�åɤ��̾�ϷѾ������ʤ������㳰�Ȥ��ƥ��饹���ðۥ�åɤϤ� -�Υ��֥��饹�ˤ�Ѿ�����롥�����ؤ���Х��饹���ðۥ�åɤ�¾�Υ��� -�������Ȼظ������ƥ�ˤ����륯�饹��åɤ�Ư���롥 +�ðۥ�åɤ��̾�ϷѾ����ʤ������㳰�Ȥ��ƥ��饹���ðۥ�åɤϤ��� +���֥��饹�ˤ�Ѿ�����롥�����ؤ���Х��饹���ðۥ�åɤ�¾�Υ��֥��� +���Ȼظ������ƥ�ˤ����륯�饹��åɤ�Ư���롥 ** INCLUDE �⥸�塼��롼�ɤ��뤳�Ȥˤ�äơ����饹�ޤ��ϥ⥸�塼��˵�ǽ -���ɲäǤ��롥�⥸�塼��롼�ɤ�����硤���Υ⥸�塼��(����� -���Υ⥸�塼�뤬���˥��롼�ɤ��Ƥ���⥸�塼��)�����ƤΥ�åɤ� -�����Ѥ����̤Τ�������Х��롼�ɤϸ��ꤵ�줿¿�ŷѾ��Ȥ����롥 - -¾�Υ⥸�塼��롼�ɤ��빽���ϰʲ����̤�Ǥ��롥 +���ɲäǤ��롥���ߤ������Υ��饹�ޤ��ϥ⥸�塼��(�ȥåץ�٥�Ǥ� +Object���饹)�˻��ꤷ���⥸�塼��롼�ɤ��빽���ϰʲ����̤�� +���롥 include �⥸�塼��̾ [`,' �⥸�塼��̾..] -���ߤ������Υ��饹�ޤ��ϥ⥸�塼��(�ȥåץ�٥�Ǥ�Object���饹)�˻� -�ꤷ���⥸�塼��롼�ɤ��롥 +�⥸�塼��롼�ɤ���ȡ����Υ⥸�塼��(����Ӥ��Υ⥸�塼�뤬 +���˥��롼�ɤ��Ƥ���⥸�塼��)�����ƤΥ�åɤ�����Ѥ����̤Τ� +������Х��롼�ɤϸ��ꤵ�줿¿�ŷѾ�(Mixin)�Ȥ����롥 ** ALIAS @@ -855,8 +855,8 @@ begin����resque��ǻȤ���begin����Ϥᤫ��¹Ԥ��롥�㳰������Ԥʤä� alias ��å�̾1 ��å�̾2 ��̾���դ���줿��åɤϡ����λ����ǤΥ�å����������Ѥ������Υ� -���åɤ����������Ƥ⡤�Ť���åɤ��ƤӽФ��줿�Τ�����Ʊ��Ư���� -�롥 +���åɤ����������Ƥ⡤��������θŤ���åɤ��ƤӽФ��줿�Τ�����Ʊ +��Ư���롥 ** UNDEF @@ -866,10 +866,10 @@ begin����resque��ǻȤ���begin����Ϥᤫ��¹Ԥ��롥�㳰������Ԥʤä� ���ꤷ����åɤ��������ä��� -def�ˤ����̾�����undef�ˤ��������ä���Ȥ��ȥ��饹�Υ��ե��� -�����ѡ����饹����Ω���ѹ����뤳�Ȥ��Ǥ��롥����������åɤ�self -�˥�å����������äƤ�����⤢��Τǡ��褯���դ��ʤ��ȴ�¸�Υ�å� -��ư��ʤ��ʤ��ǽ�������롥 +def�ˤ����̾�����undef�ˤ��������ä��ˤ�äƥ��饹�Υ��ե��� +�����ѡ����饹����Ω���ѹ����뤳�Ȥ��Ǥ��롥����������åɤ�self + �˥�å����������äƤ�����⤢��Τǡ��褯���դ��ʤ��ȴ�¸�Υ�� +�ɤ�ư��ʤ��ʤ��ǽ�������롥 * �Ȥ߹��ߴؿ� @@ -922,10 +922,6 @@ Ruby�ˤϸ�̩�ʰ�̣�Ǥϴؿ��Ϥʤ���Kernel���饹�δؿ���åɤ�(���Ƥ� ɸ�����Ϥ����ʸ�����Ф�������ͤ��ɤ߹����ʸ����ʸ�������� (ASCII)��ɽ��Fixnum�Ǥ��롥 - getenv(name) - - name�˳�������Ķ��ѿ�����Ф���$ENV[name]��Ʊ���� - gets() �����Ȥ���Ϳ����줿�ե�����(�ʤ����ɸ������)�ǹ�������벾�� @@ -1028,11 +1024,6 @@ Ruby�ˤϸ�̩�ʰ�̣�Ǥϴؿ��Ϥʤ���Kernel���饹�δؿ���åɤ�(���Ƥ� nil�������Ǥʤ��Ȥ���3���Ǥ�������֤������γ����Ǥ�����/����/ �㳰�Ԥ��Υ��֥������Ȥ����ǤȤ��ƻ��ġ� - setenv(name, value) - - name�ǻ��ꤵ���Ķ��ѿ���value�˥��åȤ��롥$ENV[name]=value - ��Ʊ��Ư���롥 - sleep([sec]) sec�ä����ץ������μ¹Ԥ���ߤ��롥sec����ά���줿��硤�ץ� @@ -1175,10 +1166,6 @@ Ruby�ˤϸ�̩�ʰ�̣�Ǥϴؿ��Ϥʤ���Kernel���饹�δؿ���åɤ�(���Ƥ� $DEBUG `-d'�ե饰�ξ���(������)�� - $ENV �Ķ��ѿ��˥�����������Ϣ������ʸ������Ȥ���Ϳ�� - ����б�����Ķ��ѿ����ͤ������롥�Ķ��ѿ���¸�ߤ��� - ������nil���֤롥 - $FILENAME ���ۥե�����`$<'�Ǹ����ɤ߹������(��å�gets()���� �ɤ�Ǥ���)�ե�����̾��$<.filename��Ʊ���� @@ -1190,9 +1177,6 @@ Ruby�ˤϸ�̩�ʰ�̣�Ǥϴؿ��Ϥʤ���Kernel���饹�δؿ���åɤ�(���Ƥ� $VERBOSE `-v'�ե饰�ξ���(������) - $VERSION ruby�ΥС�������ʸ���� - - TRUE t FALSE nil @@ -1212,6 +1196,16 @@ Ruby�ˤϸ�̩�ʰ�̣�Ǥϴؿ��Ϥʤ���Kernel���饹�δؿ���åɤ�(���Ƥ� �ϴ����ˤ�Ʊ���ǤϤʤ���FALSE�˴ؤ��Ƥϡ����Τ褦����������� �ʤ��� + STDIN ɸ������ + STDOUT ɸ����� + STDERR ɸ�२�顼���� + + ENV �Ķ��ѿ��˥�����������Ϣ������ʸ������Ȥ���Ϳ�� + ����б�����Ķ��ѿ����ͤ������롥�Ķ��ѿ���¸�ߤ��� + ������nil���֤롥 + + VERSION ruby�ΥС�������ʸ���� + * �Ȥ߹��ߥ��饹�ȥ⥸�塼�� ** Array(���饹) @@ -3867,9 +3861,9 @@ Ruby�θ�����ͤϿ�¿���θ���αƶ�������Ƥ���. �ʲ��ˤ�����ΤϤ��μ� C, Perl, CLU, Sather, CLOS, Eiffel, Icon, tcl, AWK, bourne shell, Smalltalk, Emacs Lisp. -�ޤ�ruby�θ�����ͤ���ꤹ�뤿��˶��Ϥ��Ʋ����ä�������ʲ��ˤ����� +�ޤ�ruby�θ�����ͤ���ꤹ�뤿��˶��Ϥ��Ʋ����ä�������ʲ��ˤ����롥 - ���ͷ�����������������ƣ���Ϻ����¼���Σţá��غ�������DEC�� + ���ͷ�����������������ƣ���Ϻ����¼���Σţá��غ������ܣģţá� ���ʤ����ֺ�.�ٻ���(�ɾ�ά)�� ------------------------------------------------------- Local variables: @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:42:59 $ created at: Fri Oct 15 10:39:26 JST 1993 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:43:01 $ created at: Mon Aug 9 17:12:58 JST 1993 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ @@ -358,7 +358,6 @@ Fstr_cmp(str1, str2) return INT2FIX(result); } -Regexp * make_regexp(); VALUE Freg_match(); extern VALUE C_Glob; @@ -376,7 +375,7 @@ Fstr_match(x, y) case T_STRING: reg = re_regcomp(y); - start = research(reg, x, 0, ignorecase); + start = research(reg, x, 0); if (start == -1) { return FALSE; } @@ -403,7 +402,7 @@ Fstr_match2(str) Fail("$_ is not a string"); reg = re_regcomp(str); - start = research(reg, rb_lastline, 0, ignorecase); + start = research(reg, rb_lastline, 0); if (start == -1) { return Qnil; } @@ -451,7 +450,7 @@ Fstr_index(argc, argv, str) switch (TYPE(sub)) { case T_REGEXP: - pos = research(sub, str, pos, ignorecase); + pos = research(sub, str, pos); break; case T_STRING: @@ -684,7 +683,7 @@ str_sub(str, pat, val, once) int beg, end, offset, n; for (offset=0, n=0; - (beg=research(pat, str, offset, ignorecase)) >= 0; + (beg=research(pat, str, offset)) >= 0; offset=RREGEXP(pat)->ptr->regs.start[0]+STRLEN(val)) { end = RREGEXP(pat)->ptr->regs.end[0]-1; sub = re_regsub(val); @@ -1034,14 +1033,14 @@ static VALUE Fstr_toupper(str) struct RString *str; { - return Fstr_upcase(str_new(str_new(str->ptr, str->len))); + return Fstr_upcase(str_new(str->ptr, str->len)); } static VALUE Fstr_tolower(str) struct RString *str; { - return Fstr_downcase(str_new(str_new(str->ptr, str->len))); + return Fstr_downcase(str_new(str->ptr, str->len)); } struct tr { @@ -1343,7 +1342,7 @@ Fstr_split(argc, argv, str) #define LMATCH spat->ptr->regs.start #define RMATCH spat->ptr->regs.end - while ((end = research(spat, str, start, ignorecase)) >= 0) { + while ((end = research(spat, str, start)) >= 0) { if (start == end && LMATCH[0] == RMATCH[0]) { if (last_null == 1) { if (ismbchar(str->ptr[beg])) @@ -4,7 +4,7 @@ $Author: matz $ $Date: 1995/01/10 10:43:02 $ - created at: Tue Mar 22 18:44:30 JST 1994 + created at: Tue Mar 22 18:44:30 JST 1995 ************************************************/ @@ -6,7 +6,7 @@ $Date: 1994/12/06 09:30:28 $ created at: Tue Dec 28 14:31:59 JST 1993 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ diff --git a/variable.c b/variable.c index 9ac538c37e..b65a1fc05e 100644 --- a/variable.c +++ b/variable.c @@ -335,22 +335,29 @@ rb_ivar_set(id, val) } VALUE -rb_const_get(id) +rb_const_get(class, id) + struct RClass *class; ID id; { - struct RClass *class = (struct RClass*)CLASS_OF(Qself); VALUE value; while (class) { if (class->iv_tbl && st_lookup(class->iv_tbl, id, &value)) { return value; } - class = class->super; + if (BUILTIN_TYPE(class) == T_MODULE) { + class = RCLASS(C_Object); + } + else { + class = class->super; + } } /* pre-defined class */ if (st_lookup(class_tbl, id, &value)) return value; + /* here comes autoload code in the future. */ + Fail("Uninitialized constant %s", rb_id2name(id)); /* not reached */ } @@ -366,6 +373,8 @@ rb_const_bound(class, id) } class = class->super; } + if (st_lookup(class_tbl, id, Qnil)) + return TRUE; return FALSE; } @@ -7,7 +7,7 @@ $Date: 1995/01/12 08:54:54 $ created at: Thu Sep 30 20:08:01 JST 1993 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1995 Yukihiro Matsumoto ************************************************/ @@ -15,14 +15,11 @@ #include "version.h" #include <stdio.h> -static VALUE rb_version; - -VALUE rb_readonly_hook(); +extern VALUE C_Kernel; Init_version() { - rb_version = str_new2(RUBY_VERSION); - rb_define_variable("$VERSION", &rb_version, Qnil, rb_readonly_hook, 0); + rb_define_const(C_Kernel, "VERSION", str_new2(RUBY_VERSION)); } show_version() @@ -32,6 +29,6 @@ show_version() show_copyright() { - fprintf(stderr, "ruby - Copyright (C) 1994 Yukihiro Matsumoto\n"); + fprintf(stderr, "ruby - Copyright (C) 1995 Yukihiro Matsumoto\n"); exit(0); } @@ -1,2 +1,2 @@ -#define RUBY_VERSION "0.67" -#define VERSION_DATE "95/02/21" +#define RUBY_VERSION "0.68" +#define VERSION_DATE "95/02/23" |