diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-03-06 08:17:54 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-03-06 08:17:54 +0000 |
commit | a36e0c78c90917c4d5cc78f67b3808913795f264 (patch) | |
tree | 81deaaa0cacb33bd81163aac0a358755c85df2cd | |
parent | 4a7d313e4a263f5c2f2f42dd573fa612f0d0c0a7 (diff) | |
download | ruby-a36e0c78c90917c4d5cc78f67b3808913795f264.tar.gz |
* parse.y (primary): rescue and ensure clauses should be allowed
to appear in singleton method body.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1233 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | MANIFEST | 1 | ||||
-rw-r--r-- | ToDo | 1 | ||||
-rw-r--r-- | eval.c | 114 | ||||
-rw-r--r-- | missing/dir.h | 65 | ||||
-rw-r--r-- | missing/finite.c | 2 | ||||
-rw-r--r-- | missing/isinf.c | 2 | ||||
-rw-r--r-- | missing/isnan.c | 2 | ||||
-rw-r--r-- | missing/memcmp.c | 5 | ||||
-rw-r--r-- | missing/memmove.c | 32 | ||||
-rw-r--r-- | missing/os2.c | 2 | ||||
-rw-r--r-- | missing/strcasecmp.c | 6 | ||||
-rw-r--r-- | missing/strchr.c | 57 | ||||
-rw-r--r-- | missing/strerror.c | 8 | ||||
-rw-r--r-- | missing/strncasecmp.c | 5 | ||||
-rw-r--r-- | missing/strstr.c | 83 | ||||
-rw-r--r-- | missing/strtol.c | 89 | ||||
-rw-r--r-- | missing/x68.c | 2 | ||||
-rw-r--r-- | parse.y | 10 | ||||
-rw-r--r-- | version.h | 4 |
20 files changed, 177 insertions, 320 deletions
@@ -1,7 +1,14 @@ +Tue Mar 6 10:50:29 2001 Yukihiro Matsumoto <matz@ruby-lang.org> + + * parse.y (primary): rescue and ensure clauses should be allowed + to appear in singleton method body. + Mon Mar 5 17:25:13 2001 Yukihiro Matsumoto <matz@ruby-lang.org> * eval.c (proc_eq): compare Procs using blocktag equality. + * eval.c (proc_to_s): stringify according to block tag address. + Mon Mar 5 17:19:56 2001 WATANABE Hirofumi <eban@ruby-lang.org> * win32/win32.c (gettimeofday): use GetLocalTime() instead of ftime() @@ -163,7 +163,6 @@ misc/rubydb2x.el misc/rubydb3x.el missing/alloca.c missing/crypt.c -missing/dir.h missing/dup2.c missing/file.h missing/finite.c @@ -44,6 +44,7 @@ Hacking Interpreter * warn for inconsistent local variable usage (lv m and method m at the same time). * MicroRuby * Built-in Interactive Ruby. +* trap every method invocation, which can be enabled by e.g. trap_call :method. Standard Libraries @@ -1457,56 +1457,52 @@ ev_const_get(cref, id) } cbase = cbase->nd_next; } -#if 1 - return rb_const_get(ruby_class, id); -#else return rb_const_get(cref->nd_clss, id); -#endif } - static VALUE - ev_const_set(cref, id, val) - NODE *cref; - ID id; - VALUE val; - { - NODE *cbase = cref; - - 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_const_assign(cbase->nd_clss, id, val); - return val; - } - - static VALUE - rb_mod_nesting() - { - NODE *cbase = RNODE(ruby_frame->cbase); - VALUE ary = rb_ary_new(); - - while (cbase && cbase->nd_clss != rb_cObject) { - rb_ary_push(ary, cbase->nd_clss); - cbase = cbase->nd_next; - } - return ary; - } - - static VALUE - rb_mod_s_constants() - { - NODE *cbase = RNODE(ruby_frame->cbase); - VALUE ary = rb_ary_new(); - - while (cbase && cbase->nd_clss != rb_cObject) { - rb_mod_const_at(cbase->nd_clss, ary); - cbase = cbase->nd_next; +static VALUE +ev_const_set(cref, id, val) + NODE *cref; + ID id; + VALUE val; +{ + NODE *cbase = cref; + + 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_const_assign(cbase->nd_clss, id, val); + return val; +} + +static VALUE +rb_mod_nesting() +{ + NODE *cbase = RNODE(ruby_frame->cbase); + VALUE ary = rb_ary_new(); + + while (cbase && cbase->nd_clss != rb_cObject) { + rb_ary_push(ary, cbase->nd_clss); + cbase = cbase->nd_next; + } + return ary; +} + +static VALUE +rb_mod_s_constants() +{ + NODE *cbase = RNODE(ruby_frame->cbase); + VALUE ary = rb_ary_new(); + + while (cbase && cbase->nd_clss != rb_cObject) { + rb_mod_const_at(cbase->nd_clss, ary); + cbase = cbase->nd_next; } rb_mod_const_of(ruby_cbase, ary); @@ -6363,6 +6359,23 @@ proc_eq(self, other) } static VALUE +proc_to_s(self, other) + VALUE self, other; +{ + struct BLOCK *data; + char *cname = rb_class2name(CLASS_OF(self)); + VALUE str; + + Data_Get_Struct(self, struct BLOCK, data); + str = rb_str_new(0, strlen(cname)+6+16+1); /* 6:tags 16:addr 1:eos */ + sprintf(RSTRING(str)->ptr, "#<%s:0x%lx>", cname, data->tag); + RSTRING(str)->len = strlen(RSTRING(str)->ptr); + if (OBJ_TAINTED(self)) OBJ_TAINT(str); + + return str; +} + +static VALUE block_pass(self, node) VALUE self; NODE *node; @@ -6780,6 +6793,7 @@ Init_Proc() rb_define_method(rb_cProc, "arity", proc_arity, 0); rb_define_method(rb_cProc, "[]", proc_call, -2); rb_define_method(rb_cProc, "==", proc_eq, 1); + rb_define_method(rb_cProc, "to_s", proc_to_s, 0); rb_define_global_function("proc", rb_f_lambda, 0); rb_define_global_function("lambda", rb_f_lambda, 0); rb_define_global_function("binding", rb_f_binding, 0); @@ -7181,15 +7195,15 @@ void rb_thread_fd_close(fd) int fd; { - rb_thread_t th, curr = curr_thread; + rb_thread_t th; - FOREACH_THREAD_FROM(curr, th) { + FOREACH_THREAD(th) { if ((th->wait_for & WAIT_FD) && fd == th->fd) { VALUE exc = rb_exc_new2(rb_eIOError, "stream closed"); rb_thread_raise(1, &exc, th); } } - END_FOREACH_FROM(curr, th); + END_FOREACH(th); } static void diff --git a/missing/dir.h b/missing/dir.h deleted file mode 100644 index 830239b3ea..0000000000 --- a/missing/dir.h +++ /dev/null @@ -1,65 +0,0 @@ -/* $RCSfile: dir.h,v $$Revision: 4.0.1.1 $$Date: 91/06/07 11:22:10 $ - * - * (C) Copyright 1987, 1990 Diomidis Spinellis. - * - * You may distribute under the terms of either the GNU General Public - * License or the Artistic License, as specified in the README file. - * - * $Log: dir.h,v $ - * Revision 4.0.1.1 91/06/07 11:22:10 lwall - * patch4: new copyright notice - * - * Revision 4.0 91/03/20 01:34:20 lwall - * 4.0 baseline. - * - * Revision 3.0.1.1 90/03/27 16:07:08 lwall - * patch16: MSDOS support - * - * Revision 1.1 90/03/18 20:32:29 dds - * Initial revision - * - * - */ - -/* - * defines the type returned by the directory(3) functions - */ - -#ifndef __DIR_INCLUDED -#define __DIR_INCLUDED - -#if !defined __MINGW32__ -/*Directory entry size */ -#ifdef DIRSIZ -#undef DIRSIZ -#endif -#define DIRSIZ(rp) (sizeof(struct direct)) - -/* - * Structure of a directory entry - */ -struct direct { - ino_t d_ino; /* inode number (not used by MS-DOS) */ - int d_namlen; /* Name length */ - char d_name[256]; /* file name */ -}; - -struct _dir_struc { /* Structure used by dir operations */ - char *start; /* Starting position */ - char *curr; /* Current position */ - long size; /* Size of string table */ - long nfiles; /* number if filenames in table */ - struct direct dirstr; /* Directory structure to return */ -}; - -typedef struct _dir_struc DIR; /* Type returned by dir operations */ - -DIR *cdecl opendir(char *filename); -struct direct *readdir(DIR *dirp); -long telldir(DIR *dirp); -void seekdir(DIR *dirp,long loc); -void rewinddir(DIR *dirp); -void closedir(DIR *dirp); - -#endif -#endif /* __DIR_INCLUDED */ diff --git a/missing/finite.c b/missing/finite.c index 07fe3263e9..f91035a8cd 100644 --- a/missing/finite.c +++ b/missing/finite.c @@ -1,3 +1,5 @@ +/* public domain rewrite of finite(3) */ + int finite(n) double n; diff --git a/missing/isinf.c b/missing/isinf.c index e0cd6ac1a2..38772ba4f1 100644 --- a/missing/isinf.c +++ b/missing/isinf.c @@ -1,3 +1,5 @@ +/* public domain rewrite of isinf(3) */ + #ifdef __osf__ #define _IEEE 1 diff --git a/missing/isnan.c b/missing/isnan.c index 3c56765807..df424c2e61 100644 --- a/missing/isnan.c +++ b/missing/isnan.c @@ -1,3 +1,5 @@ +/* public domain rewrite of isnan(3) */ + #ifdef _MSC_VER #include <float.h> diff --git a/missing/memcmp.c b/missing/memcmp.c index 762eaf5260..9edc9c13b9 100644 --- a/missing/memcmp.c +++ b/missing/memcmp.c @@ -1,7 +1,4 @@ -/* - * memcmp --- compare memories. - * - */ +/* public domain rewrite of memcmp(3) */ int memcmp(s1,s2,len) diff --git a/missing/memmove.c b/missing/memmove.c index 09e64702b6..7961c5c0e6 100644 --- a/missing/memmove.c +++ b/missing/memmove.c @@ -1,24 +1,20 @@ -/* - * memmove --- move memories. - * - * We supply this routine for those systems that aren't standard yet. - */ +/* public domain rewrite of memcmp(3) */ char * memmove (dst, src, n) - char *dst, *src; - int n; + char *dst, *src; + int n; { - char *ret = dst; + char *ret = dst; - if (src < dst) { - src += n; - dst += n; - while (n--) - *--dst = *--src; - } - else if (dst < src) - while (n--) - *dst++ = *src++; - return ret; + if (src < dst) { + src += n; + dst += n; + while (n--) + *--dst = *--src; + } + else if (dst < src) + while (n--) + *dst++ = *src++; + return ret; } diff --git a/missing/os2.c b/missing/os2.c index aeb181f648..57798ab54c 100644 --- a/missing/os2.c +++ b/missing/os2.c @@ -1,3 +1,5 @@ +/* os/2 compatibility functions -- follows Ruby's lisence */ + #include "ruby.h" #include <stdio.h> #include <stdlib.h> diff --git a/missing/strcasecmp.c b/missing/strcasecmp.c index ba7bf78ea4..fddb8385be 100644 --- a/missing/strcasecmp.c +++ b/missing/strcasecmp.c @@ -1,12 +1,16 @@ +/* public domain rewrite of strcasecmp(3) */ + #include <ctype.h> int strcasecmp(p1, p2) char *p1, *p2; { - for ( ; *p1 && *p2; p1++, p2++) { + while (*p1 && *p2) { if (toupper(*p1) != toupper(*p2)) return toupper(*p1) - toupper(*p2); + p1++; + p2++; } return strlen(p1) - strlen(p2); } diff --git a/missing/strchr.c b/missing/strchr.c index 50714c9942..82f3cc96b0 100644 --- a/missing/strchr.c +++ b/missing/strchr.c @@ -1,45 +1,30 @@ -/* - * strchr --- search a string for a character - * - * We supply this routine for those systems that aren't standard yet. - */ - -#include <stdio.h> +/* public domain rewrite of strchr(3) and strrchr(3) */ char * -strchr(str, c) -register const char *str, c; +strchr(s, c) + char *s; + int c; { - if (c == '\0') { - /* thanks to Mike Brennan ... */ - do { - if (*str == c) - return (char *) str; - } while (*str++); - } else { - for (; *str; str++) - if (*str == c) - return (char *) str; - } - - return NULL; + if (c == 0) return s + strlen(s); + while (*s) { + if (*s == c) + return s; + s++; + } + return 0; } -/* - * strrchr --- find the last occurrence of a character in a string - * - * We supply this routine for those systems that aren't standard yet. - */ - char * -strrchr(str, c) -register const char *str, c; +strrchr(s, c) + char *s; + int c; { - register const char *save = NULL; - - for (; *str; str++) - if (*str == c) - save = str; + char *save = 0; - return (char *) save; + while (*s) { + if (*s == c) + save = s; + s++; + } + return save; } diff --git a/missing/strerror.c b/missing/strerror.c index 44013b3892..c1bf6feff8 100644 --- a/missing/strerror.c +++ b/missing/strerror.c @@ -1,6 +1,4 @@ -/* - * strerror.c --- Map an integer error number into a printable string. - */ +/* public domain rewrite of strerror(3) */ extern int sys_nerr; extern char *sys_errlist[]; @@ -11,9 +9,9 @@ char * strerror(error) int error; { - if ((error <= sys_nerr) && (error > 0)) { + if (error <= sys_nerr && error > 0) { return sys_errlist[error]; } - sprintf (msg, "Unknown error (%d)", error); + sprintf(msg, "Unknown error (%d)", error); return msg; } diff --git a/missing/strncasecmp.c b/missing/strncasecmp.c index c136703415..a4cc5828b8 100644 --- a/missing/strncasecmp.c +++ b/missing/strncasecmp.c @@ -1,3 +1,5 @@ +/* public domain rewrite of strncasecmp(3) */ + #include <ctype.h> int @@ -6,13 +8,14 @@ strncasecmp(p1, p2, len) char *p2; int len; { - for (; len != 0; len--, p1++, p2++) { + while (len != 0) { if (toupper(*p1) != toupper(*p2)) { return toupper(*p1) - toupper(*p2); } if (*p1 == '\0') { return 0; } + len--; p1++; p2++; } return 0; } diff --git a/missing/strstr.c b/missing/strstr.c index c54349983e..1673518f06 100644 --- a/missing/strstr.c +++ b/missing/strstr.c @@ -1,73 +1,26 @@ -/* - * strstr.c -- - * - * Source code for the "strstr" library routine. - * - * Copyright 1988-1991 Regents of the University of California - * Permission to use, copy, modify, and distribute this - * software and its documentation for any purpose and without - * fee is hereby granted, provided that the above copyright - * notice appears in all copies. The University of California - * makes no representations about the suitability of this - * software for any purpose. It is provided "as is" without - * express or implied warranty. - */ - -#ifndef lint -static char rcsid[] = "$Header$ SPRITE (Berkeley)"; -#endif /* not lint */ - -/* - *---------------------------------------------------------------------- - * - * strstr -- - * - * Locate the first instance of a substring in a string. - * - * Results: - * If string contains substring, the return value is the - * location of the first matching instance of substring - * in string. If string doesn't contain substring, the - * return value is 0. Matching is done on an exact - * character-for-character basis with no wildcards or special - * characters. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ +/* public domain rewrite of strstr(3) */ char * -strstr(string, substring) - register char *string; /* String to search. */ - char *substring; /* Substring to try to find in string. */ +strstr(haystack, needle) + char *haystack, *needle; { - register char *a, *b; - - /* First scan quickly through the two strings looking for a - * single-character match. When it's found, then compare the - * rest of the substring. - */ + char *hend; + char *a, *b; - b = substring; - if (*b == 0) { - return string; - } - for ( ; *string != 0; string += 1) { - if (*string != *b) { - continue; - } - a = string; - while (1) { - if (*b == 0) { - return string; - } - if (*a++ != *b++) { - break; + if (*needle == 0) return haystack; + hend = haystack + strlen(haystack) - strlen(needle) + 1; + while (haystack < hend) { + if (*haystack == *needle) { + a = haystack; + b = needle; + for (;;) { + if (*b == 0) return haystack; + if (*a++ != *b++) { + break; + } } } - b = substring; + haystack++; } - return (char *) 0; + return 0; } diff --git a/missing/strtol.c b/missing/strtol.c index 4941f43b91..e94aa54ca0 100644 --- a/missing/strtol.c +++ b/missing/strtol.c @@ -1,84 +1,29 @@ -/* - * strtol.c -- - * - * Source code for the "strtol" library procedure. - * - * Copyright 1988 Regents of the University of California - * Permission to use, copy, modify, and distribute this - * software and its documentation for any purpose and without - * fee is hereby granted, provided that the above copyright - * notice appear in all copies. The University of California - * makes no representations about the suitability of this - * software for any purpose. It is provided "as is" without - * express or implied warranty. - */ +/* public domain rewrite of strtol(3) */ #include <ctype.h> - -/* - *---------------------------------------------------------------------- - * - * strtol -- - * - * Convert an ASCII string into an integer. - * - * Results: - * The return value is the integer equivalent of string. If endPtr - * is non-NULL, then *endPtr is filled in with the character - * after the last one that was part of the integer. If string - * doesn't contain a valid integer value, then zero is returned - * and *endPtr is set to string. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -long int -strtol(string, endPtr, base) - char *string; /* String of ASCII digits, possibly - * preceded by white space. For bases - * greater than 10, either lower- or - * upper-case digits may be used. - */ - char **endPtr; /* Where to store address of terminating - * character, or NULL. */ - int base; /* Base for conversion. Must be less - * than 37. If 0, then the base is chosen - * from the leading characters of string: - * "0x" means hex, "0" means octal, anything - * else means decimal. - */ +long +strtol(nptr, endptr, base) + char *nptr; + char **endptr; + int base; { - register char *p; - int result; - - /* - * Skip any leading blanks. - */ + long result; + char *p = nptr; - p = string; while (isspace(*p)) { - p += 1; + p++; } - - /* - * Check for a sign. - */ - if (*p == '-') { - p += 1; - result = -(strtoul(p, endPtr, base)); - } else { - if (*p == '+') { - p += 1; - } - result = strtoul(p, endPtr, base); + p++; + result = -strtoul(p, endptr, base); + } + else { + if (*p == '+') p++; + result = strtoul(p, endptr, base); } - if ((result == 0) && (endPtr != 0) && (*endPtr == p)) { - *endPtr = string; + if (endptr != 0 && *endptr == p) { + *endptr = nptr; } return result; } diff --git a/missing/x68.c b/missing/x68.c index 9a8f0a2a9c..08bce8778c 100644 --- a/missing/x68.c +++ b/missing/x68.c @@ -1,3 +1,5 @@ +/* x68 compatibility functions -- follows Ruby's lisence */ + #include "config.h" #if !HAVE_SELECT @@ -1353,8 +1353,18 @@ primary : literal } f_arglist compstmt + rescue + opt_else + ensure kEND { + if ($9) $8 = NEW_RESCUE($8, $9, $10); + else if ($10) { + rb_warn("else without rescue is useless"); + $8 = block_append($8, $10); + } + if ($11) $8 = NEW_ENSURE($8, $11); + $$ = NEW_DEFS($2, $5, $7, $8); fixpos($$, $2); local_pop(); @@ -1,4 +1,4 @@ #define RUBY_VERSION "1.7.0" -#define RUBY_RELEASE_DATE "2001-03-05" +#define RUBY_RELEASE_DATE "2001-03-06" #define RUBY_VERSION_CODE 170 -#define RUBY_RELEASE_CODE 20010305 +#define RUBY_RELEASE_CODE 20010306 |