1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
matz 2001-03-06 08:17:54 +00:00
parent 4a7d313e4a
commit a36e0c78c9
20 changed files with 171 additions and 314 deletions

View file

@ -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()

View file

@ -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

1
ToDo
View file

@ -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

102
eval.c
View file

@ -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;
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);
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;
}
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();
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;
}
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();
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;
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);
@ -6362,6 +6358,23 @@ proc_eq(self, other)
return Qfalse;
}
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;
@ -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

View file

@ -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 */

View file

@ -1,3 +1,5 @@
/* public domain rewrite of finite(3) */
int
finite(n)
double n;

View file

@ -1,3 +1,5 @@
/* public domain rewrite of isinf(3) */
#ifdef __osf__
#define _IEEE 1

View file

@ -1,3 +1,5 @@
/* public domain rewrite of isnan(3) */
#ifdef _MSC_VER
#include <float.h>

View file

@ -1,7 +1,4 @@
/*
* memcmp --- compare memories.
*
*/
/* public domain rewrite of memcmp(3) */
int
memcmp(s1,s2,len)

View file

@ -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;
}

View file

@ -1,3 +1,5 @@
/* os/2 compatibility functions -- follows Ruby's lisence */
#include "ruby.h"
#include <stdio.h>
#include <stdlib.h>

View file

@ -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);
}

View file

@ -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;
char *save = 0;
for (; *str; str++)
if (*str == c)
save = str;
return (char *) save;
while (*s) {
if (*s == c)
save = s;
s++;
}
return save;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
char *hend;
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.
*/
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;
}

View file

@ -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;
long result;
char *p = nptr;
/*
* Skip any leading blanks.
*/
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);
}
if ((result == 0) && (endPtr != 0) && (*endPtr == p)) {
*endPtr = string;
else {
if (*p == '+') p++;
result = strtoul(p, endptr, base);
}
if (endptr != 0 && *endptr == p) {
*endptr = nptr;
}
return result;
}

View file

@ -1,3 +1,5 @@
/* x68 compatibility functions -- follows Ruby's lisence */
#include "config.h"
#if !HAVE_SELECT

10
parse.y
View file

@ -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();

View file

@ -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