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

* parse.y (expr_value, arg_value, primary_value): value_expr()

check in place.

* eval.c (block_pass): "&nil" should clear block given.

* dir.c (push_braces): remove MAXPATHLEN dependency.

* dir.c (dir_s_globd): ditto.

* dln.c (init_funcname): ditto.

* dln.c (load_1): ditto.

* dln.c (dln_load): ditto.

* configure.in: add GNU/Hurd switches.

* pack.c (pack_pack): allows comment in template strings.

* pack.c (pack_unpack): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2082 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2002-02-18 09:52:48 +00:00
parent 3432cecf24
commit 7de72c4858
10 changed files with 246 additions and 188 deletions

View file

@ -3,6 +3,33 @@ Mon Feb 18 14:06:28 2002 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
* misc/ruby-mode.el (ruby-block-hanging-re): rescue block was too
indented.
Mon Feb 18 13:56:44 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* parse.y (expr_value, arg_value, primary_value): value_expr()
check in place.
* eval.c (block_pass): "&nil" should clear block given.
Mon Feb 18 02:05:56 2002 Wolfgang Jahrling <wolfgang@pro-linux.de>
* dir.c (push_braces): remove MAXPATHLEN dependency.
* dir.c (dir_s_globd): ditto.
* dln.c (init_funcname): ditto.
* dln.c (load_1): ditto.
* dln.c (dln_load): ditto.
* configure.in: add GNU/Hurd switches.
Fri Feb 15 17:44:26 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* pack.c (pack_pack): allows comment in template strings.
* pack.c (pack_unpack): ditto.
Sun Feb 17 23:41:37 2002 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
* mkconfig.rb (Config::expand): expand ${} too.
@ -36,6 +63,7 @@ Thu Feb 16 02:11:08 2002 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
* misc/ruby-mode.el (ruby-font-lock-keywords): fontify
instance/class/global variables start with '_'.
>>>>>>> 1.742
Fri Feb 15 14:40:38 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_eval): replace rb_cvar_declare() by rb_cvar_set().

View file

@ -610,6 +610,9 @@ if test "$with_dln_a_out" != yes; then
rb_cv_dlopen=yes ;;
linux*) LDSHARED="$CC -shared"
rb_cv_dlopen=yes ;;
gnu*) LDSHARED="$CC -shared"
rb_cv_dlopen=yes
LDFLAGS="-rdynamic" ;;
freebsd*) LDSHARED="$CC -shared"
if test "$rb_cv_binary_elf" = yes; then
LDFLAGS="-rdynamic"
@ -741,6 +744,8 @@ fi
case "$target_os" in
linux*)
STRIP='strip -S -x';;
gnu*)
STRIP='strip -S -x';;
nextstep*)
STRIP='strip -A -n';;
openstep*)
@ -882,6 +887,10 @@ if test "$enable_shared" = 'yes'; then
LIBRUBY_DLDFLAGS='-Wl,-soname,lib$(RUBY_INSTALL_NAME).so.$(MAJOR).$(MINOR)'
LIBRUBY_ALIASES='lib$(RUBY_INSTALL_NAME).so.$(MAJOR).$(MINOR) lib$(RUBY_INSTALL_NAME).so'
;;
gnu*)
LIBRUBY_DLDFLAGS='-Wl,-soname,lib$(RUBY_INSTALL_NAME).so.$(MAJOR).$(MINOR)'
LIBRUBY_ALIASES='lib$(RUBY_INSTALL_NAME).so.$(MAJOR).$(MINOR) lib$(RUBY_INSTALL_NAME).so'
;;
freebsd*)
SOLIBS='$(LIBS)'
LIBRUBY_SO='lib$(RUBY_INSTALL_NAME).so.$(MAJOR)$(MINOR)'

View file

@ -12,6 +12,49 @@
#define RUBY
#if !defined(__STDC__) && !defined(_MSC_VER)
# define volatile
#endif
#ifdef __cplusplus
# ifndef HAVE_PROTOTYPES
# define HAVE_PROTOTYPES 1
# endif
# ifndef HAVE_STDARG_PROTOTYPES
# define HAVE_STDARG_PROTOTYPES 1
# endif
#endif
#undef _
#ifdef HAVE_PROTOTYPES
# define _(args) args
#else
# define _(args) ()
#endif
#undef __
#ifdef HAVE_STDARG_PROTOTYPES
# define __(args) args
#else
# define __(args) ()
#endif
#ifdef __cplusplus
#define ANYARGS ...
#else
#define ANYARGS
#endif
#define xmalloc ruby_xmalloc
#define xcalloc ruby_xcalloc
#define xrealloc ruby_xrealloc
#define xfree ruby_xfree
void *xmalloc _((long));
void *xcalloc _((long,long));
void *xrealloc _((void*,long));
void xfree _((void*));
#if SIZEOF_LONG_LONG > 0
# define HAVE_LONG_LONG
# define LONG_LONG long long

19
dir.c
View file

@ -841,7 +841,7 @@ push_braces(ary, s)
VALUE ary;
char *s;
{
char buffer[MAXPATHLEN], *buf = buffer;
char *buf;
char *p, *t, *b;
char *lbrace, *rbrace;
int nest = 0;
@ -866,8 +866,7 @@ push_braces(ary, s)
if (lbrace) {
int len = strlen(s);
if (len >= MAXPATHLEN)
buf = xmalloc(len + 1);
buf = xmalloc(len + 1);
memcpy(buf, s, lbrace-s);
b = buf + (lbrace-s);
p = lbrace;
@ -881,8 +880,7 @@ push_braces(ary, s)
strcpy(b+(p-t), rbrace+1);
push_braces(ary, buf);
}
if (buf != buffer)
free(buf);
free(buf);
}
else {
push_globs(ary, s);
@ -896,7 +894,7 @@ dir_s_glob(dir, str)
VALUE dir, str;
{
char *p, *pend;
char buffer[MAXPATHLEN], *buf;
char *buf;
char *t;
int nest;
VALUE ary = 0;
@ -905,11 +903,7 @@ dir_s_glob(dir, str)
if (!rb_block_given_p()) {
ary = rb_ary_new();
}
if (RSTRING(str)->len >= MAXPATHLEN) {
buf = xmalloc(RSTRING(str)->len + 1);
} else {
buf = buffer;
}
buf = xmalloc(RSTRING(str)->len + 1);
p = RSTRING(str)->ptr;
pend = p + RSTRING(str)->len;
@ -936,8 +930,7 @@ dir_s_glob(dir, str)
}
/* else unmatched braces */
}
if (buf != buffer)
free(buf);
free(buf);
if (ary) {
return ary;
}

47
dln.c
View file

@ -14,6 +14,10 @@
#include "defines.h"
#include "dln.h"
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#ifdef __CHECKER__
#undef HAVE_DLOPEN
#undef USE_DLN_A_OUT
@ -96,7 +100,7 @@ int eaccess();
static void
init_funcname(buf, file)
char *buf;
char **buf;
char *file;
{
char *p, *slash;
@ -109,8 +113,15 @@ init_funcname(buf, file)
if (*p == '/') slash = p;
#endif
snprintf(buf, MAXPATHLEN, FUNCNAME_PATTERN, slash + 1);
for (p = buf; *p; p++) { /* Delete suffix if it exists */
/* This assumes that systems without length limitation for file names
provide asprintf(). This shouldn't be too unlikely. */
#ifdef MAXPATHLEN
*buf = xmalloc(MAXPATHLEN);
snprintf(*buf, MAXPATHLEN, FUNCNAME_PATTERN, slash + 1);
#else
asprintf(buf, FUNCNAME_PATTERN, slash + 1);
#endif
for (p = *buf; *p; p++) { /* Delete suffix if it exists */
if (*p == '.') {
*p = '\0'; break;
}
@ -622,7 +633,6 @@ load_1(fd, disp, need_init)
struct nlist *sym;
struct nlist *end;
int init_p = 0;
char buf[MAXPATHLEN];
if (load_header(fd, &hdr, disp) == -1) return -1;
if (INVALID_OBJECT(hdr)) {
@ -835,12 +845,13 @@ load_1(fd, disp, need_init)
if (need_init) {
int len;
char **libs_to_be_linked = 0;
char *buf;
if (undef_tbl->num_entries > 0) {
if (load_lib(libc) == -1) goto err_exit;
}
init_funcname(buf, need_init);
init_funcname(&buf, need_init);
len = strlen(buf);
for (sym = syms; sym<end; sym++) {
@ -855,6 +866,7 @@ load_1(fd, disp, need_init)
}
}
}
free (buf);
if (libs_to_be_linked && undef_tbl->num_entries > 0) {
while (*libs_to_be_linked) {
load_lib(*libs_to_be_linked);
@ -1226,12 +1238,12 @@ dln_load(file)
HINSTANCE handle;
char winfile[MAXPATHLEN];
void (*init_fct)();
char buf[MAXPATHLEN];
char *buf;
if (strlen(file) >= MAXPATHLEN) rb_loaderror("filename too long");
/* Load the file as an object one */
init_funcname(buf, file);
init_funcname(&buf, file);
strcpy(winfile, file);
@ -1244,6 +1256,8 @@ dln_load(file)
if ((init_fct = (void(*)())GetProcAddress(handle, buf)) == NULL) {
rb_loaderror("%s - %s\n%s", dln_strerror(), buf, file);
}
free(buf);
/* Call the init code */
(*init_fct)();
return handle;
@ -1255,9 +1269,9 @@ dln_load(file)
return 0;
#else
char buf[MAXPATHLEN];
char *buf;
/* Load the file as an object one */
init_funcname(buf, file);
init_funcname(&buf, file);
#ifdef USE_DLN_DLOPEN
#define DLN_DEFINED
@ -1277,12 +1291,15 @@ dln_load(file)
goto failed;
}
if ((init_fct = (void(*)())dlsym(handle, buf)) == NULL) {
init_fct = (void(*)())dlsym(handle, buf);
free(buf);
if (init_fct == NULL) {
dlclose(handle);
goto failed;
}
/* Call the init code */
(*init_fct)();
return handle;
}
#endif /* USE_DLN_DLOPEN */
@ -1301,6 +1318,7 @@ dln_load(file)
rb_loaderror("%s - %s", strerror(errno), file);
}
shl_findsym(&lib, buf, TYPE_PROCEDURE, (void*)&init_fct);
free(buf)
if (init_fct == NULL) {
shl_findsym(&lib, buf, TYPE_UNDEFINED, (void*)&init_fct);
if (init_fct == NULL) {
@ -1359,6 +1377,7 @@ dln_load(file)
if(rld_lookup(NULL, buf, &init_address) == 0) {
rb_loaderror("Failed to lookup Init function %.200s", file);
}
free(buf);
/* Cannot call *init_address directory, so copy this value to
funtion pointer */
@ -1372,7 +1391,7 @@ dln_load(file)
int dyld_result;
NSObjectFileImage obj_file; /* handle, but not use it */
/* "file" is module file name .
"buf" is initial function name with "_" . */
"buf" is pointer to initial function name with "_" . */
void (*init_fct)();
@ -1393,6 +1412,7 @@ dln_load(file)
/* NSLookupAndBindSymbol require function name with "_" !! */
init_fct = NSAddressOfSymbol(NSLookupAndBindSymbol(buf));
free(buf);
(*init_fct)();
return (void*)init_fct;
@ -1433,14 +1453,17 @@ dln_load(file)
if ((B_BAD_IMAGE_ID == err_stat) || (B_BAD_INDEX == err_stat)) {
unload_add_on(img_id);
free(buf);
rb_loaderror("Failed to lookup Init function %.200s", file);
}
else if (B_NO_ERROR != err_stat) {
char errmsg[] = "Internal of BeOS version. %.200s (symbol_name = %s)";
unload_add_on(img_id);
free(buf);
rb_loaderror(errmsg, strerror(err_stat), buf);
}
free(buf);
/* call module initialize function. */
(*init_fct)();
return (void*)img_id;
@ -1485,10 +1508,10 @@ dln_load(file)
/* Locate the address of the correct init function */
c2pstr(buf);
err = FindSymbol(connID, buf, &symAddr, &class);
free(buf);
if (err) {
rb_loaderror("Unresolved symbols - %s" , file);
}
init_fct = (void (*)())symAddr;
(*init_fct)();
return (void*)init_fct;

View file

@ -1,3 +1,11 @@
: Array#pack, String#unpack
allows comment in template strings.
: Array#pack, String#unpack
new templates 'q' and 'Q' for 64bit integer (signed and unsigned respectively).
: Array#fill
takes block to get the values to fill.

15
eval.c
View file

@ -2323,17 +2323,18 @@ rb_eval(self, n)
case NODE_WHILE:
PUSH_TAG(PROT_NONE);
result = Qnil;
switch (state = EXEC_TAG()) {
case 0:
ruby_sourceline = nd_line(node);
if (node->nd_state && !RTEST(result = rb_eval(self, node->nd_cond)))
if (node->nd_state && !RTEST(rb_eval(self, node->nd_cond)))
goto while_out;
do {
while_redo:
rb_eval(self, node->nd_body);
while_next:
;
} while (RTEST(result = rb_eval(self, node->nd_cond)));
} while (RTEST(rb_eval(self, node->nd_cond)));
break;
case TAG_REDO:
@ -2355,16 +2356,17 @@ rb_eval(self, n)
case NODE_UNTIL:
PUSH_TAG(PROT_NONE);
result = Qnil;
switch (state = EXEC_TAG()) {
case 0:
if (node->nd_state && RTEST(result = rb_eval(self, node->nd_cond)))
if (node->nd_state && RTEST(rb_eval(self, node->nd_cond)))
goto until_out;
do {
until_redo:
rb_eval(self, node->nd_body);
until_next:
;
} while (!RTEST(result = rb_eval(self, node->nd_cond)));
} while (!RTEST(rb_eval(self, node->nd_cond)));
break;
case TAG_REDO:
@ -6598,7 +6600,10 @@ block_pass(self, node)
volatile int safe = ruby_safe_level;
if (NIL_P(block)) {
return rb_eval(self, node->nd_iter);
PUSH_ITER(ITER_NOT);
result = rb_eval(self, node->nd_iter);
POP_ITER();
return result;
}
if (rb_obj_is_kind_of(block, rb_cMethod)) {
block = method_proc(block);

18
pack.c
View file

@ -363,6 +363,13 @@ pack_pack(ary, fmt)
#endif
if (ISSPACE(type)) continue;
if (type == '#') {
while (p < pend) {
if (*p == '\n') continue;
p++;
}
break;
}
if (*p == '_' || *p == '!') {
char *natstr = "sSiIlL";
@ -1070,11 +1077,20 @@ pack_unpack(str, fmt)
ary = rb_ary_new();
while (p < pend) {
type = *p++;
#ifdef NATINT_PACK
natint = 0;
#endif
if (ISSPACE(type)) continue;
if (type == '#') {
while (p < pend) {
if (*p == '\n') continue;
p++;
}
break;
}
star = 0;
type = *p++;
if (*p == '_' || *p == '!') {
char *natstr = "sSiIlL";

204
parse.y
View file

@ -213,6 +213,7 @@ static void top_local_setup();
%type <node> singleton string
%type <val> literal numeric
%type <node> compstmt stmts stmt expr arg primary command command_call method_call
%type <node> expr_value arg_value primary_value block_call_value
%type <node> if_tail opt_else case_body cases rescue exc_list exc_var ensure
%type <node> args when_args call_args call_args2 open_args paren_args opt_paren_args
%type <node> command_args aref_args opt_block_arg block_arg var_ref var_lhs
@ -356,21 +357,18 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem
yyerror("undef within method");
$$ = $2;
}
| stmt kIF_MOD expr
| stmt kIF_MOD expr_value
{
value_expr($3);
$$ = NEW_IF(cond($3), $1, 0);
fixpos($$, $3);
}
| stmt kUNLESS_MOD expr
| stmt kUNLESS_MOD expr_value
{
value_expr($3);
$$ = NEW_UNLESS(cond($3), $1, 0);
fixpos($$, $3);
}
| stmt kWHILE_MOD expr
| stmt kWHILE_MOD expr_value
{
value_expr($3);
if ($1 && nd_type($1) == NODE_BEGIN) {
$$ = NEW_WHILE(cond($3), $1->nd_body, 0);
}
@ -378,9 +376,8 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem
$$ = NEW_WHILE(cond($3), $1, 1);
}
}
| stmt kUNTIL_MOD expr
| stmt kUNTIL_MOD expr_value
{
value_expr($3);
if ($1 && nd_type($1) == NODE_BEGIN) {
$$ = NEW_UNTIL(cond($3), $1->nd_body, 0);
}
@ -450,7 +447,7 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem
$$ = 0;
}
}
| primary '[' aref_args ']' tOP_ASGN command_call
| primary_value '[' aref_args ']' tOP_ASGN command_call
{
NODE *tmp, *args = NEW_LIST($6);
@ -465,7 +462,7 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem
$$ = NEW_OP_ASGN1($1, $5, args);
fixpos($$, $1);
}
| primary '.' tIDENTIFIER tOP_ASGN command_call
| primary_value '.' tIDENTIFIER tOP_ASGN command_call
{
if ($4 == tOROP) {
$4 = 0;
@ -476,7 +473,7 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem
$$ = NEW_OP_ASGN2($1, $3, $4, $5);
fixpos($$, $1);
}
| primary '.' tCONSTANT tOP_ASGN command_call
| primary_value '.' tCONSTANT tOP_ASGN command_call
{
if ($4 == tOROP) {
$4 = 0;
@ -487,7 +484,7 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem
$$ = NEW_OP_ASGN2($1, $3, $4, $5);
fixpos($$, $1);
}
| primary tCOLON2 tIDENTIFIER tOP_ASGN command_call
| primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_call
{
if ($4 == tOROP) {
$4 = 0;
@ -509,7 +506,6 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem
}
| mlhs '=' mrhs
{
value_expr($3);
$1->nd_value = $3;
$$ = $1;
}
@ -540,7 +536,6 @@ expr : kRETURN call_args
}
| kNOT expr
{
value_expr($2);
$$ = NEW_NOT(cond($2));
}
| '!' command_call
@ -549,18 +544,22 @@ expr : kRETURN call_args
}
| arg
expr_value : expr
{
value_expr($$);
$$ = $1;
}
command_call : command
| block_command
block_command : block_call
| block_call '.' operation2 command_args
| block_call_value '.' operation2 command_args
{
value_expr($1);
$$ = new_call($1, $3, $4);
}
| block_call tCOLON2 operation2 command_args
| block_call_value tCOLON2 operation2 command_args
{
value_expr($1);
$$ = new_call($1, $3, $4);
}
@ -569,15 +568,13 @@ command : operation command_args
$$ = new_fcall($1, $2);
fixpos($$, $2);
}
| primary '.' operation2 command_args
| primary_value '.' operation2 command_args
{
value_expr($1);
$$ = new_call($1, $3, $4);
fixpos($$, $1);
}
| primary tCOLON2 operation2 command_args
| primary_value tCOLON2 operation2 command_args
{
value_expr($1);
$$ = new_call($1, $3, $4);
fixpos($$, $1);
}
@ -650,19 +647,19 @@ mlhs_node : variable
{
$$ = assignable($1, 0);
}
| primary '[' aref_args ']'
| primary_value '[' aref_args ']'
{
$$ = aryset($1, $3);
}
| primary '.' tIDENTIFIER
| primary_value '.' tIDENTIFIER
{
$$ = attrset($1, $3);
}
| primary tCOLON2 tIDENTIFIER
| primary_value tCOLON2 tIDENTIFIER
{
$$ = attrset($1, $3);
}
| primary '.' tCONSTANT
| primary_value '.' tCONSTANT
{
$$ = attrset($1, $3);
}
@ -676,19 +673,19 @@ lhs : variable
{
$$ = assignable($1, 0);
}
| primary '[' aref_args ']'
| primary_value '[' aref_args ']'
{
$$ = aryset($1, $3);
}
| primary '.' tIDENTIFIER
| primary_value '.' tIDENTIFIER
{
$$ = attrset($1, $3);
}
| primary tCOLON2 tIDENTIFIER
| primary_value tCOLON2 tIDENTIFIER
{
$$ = attrset($1, $3);
}
| primary '.' tCONSTANT
| primary_value '.' tCONSTANT
{
$$ = attrset($1, $3);
}
@ -795,7 +792,7 @@ arg : lhs '=' arg
$$ = 0;
}
}
| primary '[' aref_args ']' tOP_ASGN arg
| primary_value '[' aref_args ']' tOP_ASGN arg
{
NODE *tmp, *args = NEW_LIST($6);
@ -810,7 +807,7 @@ arg : lhs '=' arg
$$ = NEW_OP_ASGN1($1, $5, args);
fixpos($$, $1);
}
| primary '.' tIDENTIFIER tOP_ASGN arg
| primary_value '.' tIDENTIFIER tOP_ASGN arg
{
if ($4 == tOROP) {
$4 = 0;
@ -821,7 +818,7 @@ arg : lhs '=' arg
$$ = NEW_OP_ASGN2($1, $3, $4, $5);
fixpos($$, $1);
}
| primary '.' tCONSTANT tOP_ASGN arg
| primary_value '.' tCONSTANT tOP_ASGN arg
{
if ($4 == tOROP) {
$4 = 0;
@ -832,7 +829,7 @@ arg : lhs '=' arg
$$ = NEW_OP_ASGN2($1, $3, $4, $5);
fixpos($$, $1);
}
| primary tCOLON2 tIDENTIFIER tOP_ASGN arg
| primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg
{
if ($4 == tOROP) {
$4 = 0;
@ -1003,7 +1000,6 @@ arg : lhs '=' arg
}
| arg '?' arg ':' arg
{
value_expr($1);
$$ = NEW_IF(cond($1), $3, $5);
fixpos($$, $1);
}
@ -1012,6 +1008,12 @@ arg : lhs '=' arg
$$ = $1;
}
arg_value : arg
{
value_expr($1);
$$ = $1;
}
aref_args : none
| command opt_nl
{
@ -1064,9 +1066,8 @@ call_args : command
{
$$ = arg_blk_pass($1, $2);
}
| args ',' tSTAR arg opt_block_arg
| args ',' tSTAR arg_value opt_block_arg
{
value_expr($4);
$$ = arg_concat($1, $4);
$$ = arg_blk_pass($$, $5);
}
@ -1075,9 +1076,8 @@ call_args : command
$$ = NEW_LIST(NEW_HASH($1));
$$ = arg_blk_pass($$, $2);
}
| assocs ',' tSTAR arg opt_block_arg
| assocs ',' tSTAR arg_value opt_block_arg
{
value_expr($4);
$$ = arg_concat(NEW_LIST(NEW_HASH($1)), $4);
$$ = arg_blk_pass($$, $5);
}
@ -1092,32 +1092,27 @@ call_args : command
$$ = arg_concat(list_append($1, NEW_HASH($3)), $6);
$$ = arg_blk_pass($$, $7);
}
| tSTAR arg opt_block_arg
| tSTAR arg_value opt_block_arg
{
value_expr($2);
$$ = arg_blk_pass(NEW_RESTARGS($2), $3);
}
| block_arg
call_args2 : arg ',' args opt_block_arg
call_args2 : arg_value ',' args opt_block_arg
{
$$ = arg_blk_pass(list_concat(NEW_LIST($1),$3), $4);
}
| arg ',' block_arg
| arg_value ',' block_arg
{
$$ = arg_blk_pass($1, $3);
}
| arg ',' tSTAR arg opt_block_arg
| arg_value ',' tSTAR arg_value opt_block_arg
{
value_expr($1);
value_expr($4);
$$ = arg_concat(NEW_LIST($1), $4);
$$ = arg_blk_pass($$, $5);
}
| arg ',' args ',' tSTAR arg opt_block_arg
| arg_value ',' args ',' tSTAR arg_value opt_block_arg
{
value_expr($1);
value_expr($6);
$$ = arg_concat(list_concat($1,$3), $6);
$$ = arg_blk_pass($$, $7);
}
@ -1126,41 +1121,33 @@ call_args2 : arg ',' args opt_block_arg
$$ = NEW_LIST(NEW_HASH($1));
$$ = arg_blk_pass($$, $2);
}
| assocs ',' tSTAR arg opt_block_arg
| assocs ',' tSTAR arg_value opt_block_arg
{
value_expr($4);
$$ = arg_concat(NEW_LIST(NEW_HASH($1)), $4);
$$ = arg_blk_pass($$, $5);
}
| arg ',' assocs opt_block_arg
| arg_value ',' assocs opt_block_arg
{
$$ = list_append(NEW_LIST($1), NEW_HASH($3));
$$ = arg_blk_pass($$, $4);
}
| arg ',' args ',' assocs opt_block_arg
| arg_value ',' args ',' assocs opt_block_arg
{
value_expr($1);
value_expr($6);
$$ = list_append(list_concat(NEW_LIST($1),$3), NEW_HASH($5));
$$ = arg_blk_pass($$, $6);
}
| arg ',' assocs ',' tSTAR arg opt_block_arg
| arg_value ',' assocs ',' tSTAR arg_value opt_block_arg
{
value_expr($1);
value_expr($6);
$$ = arg_concat(list_append(NEW_LIST($1), NEW_HASH($3)), $6);
$$ = arg_blk_pass($$, $7);
}
| arg ',' args ',' assocs ',' tSTAR arg opt_block_arg
| arg_value ',' args ',' assocs ',' tSTAR arg_value opt_block_arg
{
value_expr($1);
value_expr($8);
$$ = arg_concat(list_append(list_concat(NEW_LIST($1), $3), NEW_HASH($5)), $8);
$$ = arg_blk_pass($$, $9);
}
| tSTAR arg opt_block_arg
| tSTAR arg_value opt_block_arg
{
value_expr($2);
$$ = arg_blk_pass(NEW_RESTARGS($2), $3);
}
| block_arg
@ -1190,9 +1177,8 @@ open_args : call_args
$$ = $2;
}
block_arg : tAMPER arg
block_arg : tAMPER arg_value
{
value_expr($2);
$$ = NEW_BLOCK_PASS($2);
}
@ -1202,20 +1188,17 @@ opt_block_arg : ',' block_arg
}
| none
args : arg
args : arg_value
{
value_expr($1);
$$ = NEW_LIST($1);
}
| args ',' arg
| args ',' arg_value
{
value_expr($3);
$$ = list_append($1, $3);
}
mrhs : arg
mrhs : arg_value
{
value_expr($1);
$$ = $1;
}
| mrhs_basic
@ -1223,19 +1206,16 @@ mrhs : arg
$$ = NEW_REXPAND($1);
}
mrhs_basic : args ',' arg
mrhs_basic : args ',' arg_value
{
value_expr($3);
$$ = list_append($1, $3);
}
| args ',' tSTAR arg
| args ',' tSTAR arg_value
{
value_expr($4);
$$ = arg_concat($1, $4);
}
| tSTAR arg
| tSTAR arg_value
{
value_expr($2);
$$ = $2;
}
@ -1286,18 +1266,16 @@ primary : literal
{
$$ = $2;
}
| primary tCOLON2 tCONSTANT
| primary_value tCOLON2 tCONSTANT
{
value_expr($1);
$$ = NEW_COLON2($1, $3);
}
| tCOLON3 cname
{
$$ = NEW_COLON3($2);
}
| primary '[' aref_args ']'
| primary_value '[' aref_args ']'
{
value_expr($1);
$$ = NEW_CALL($1, tAREF, $3);
}
| tLBRACK aref_args ']'
@ -1321,7 +1299,6 @@ primary : literal
}
| kYIELD '(' call_args ')'
{
value_expr($3);
$$ = NEW_YIELD(ret_args($3));
}
| kYIELD '(' ')'
@ -1352,45 +1329,40 @@ primary : literal
$$ = $2;
fixpos($$, $1);
}
| kIF expr then
| kIF expr_value then
compstmt
if_tail
kEND
{
value_expr($2);
$$ = NEW_IF(cond($2), $4, $5);
fixpos($$, $2);
}
| kUNLESS expr then
| kUNLESS expr_value then
compstmt
opt_else
kEND
{
value_expr($2);
$$ = NEW_UNLESS(cond($2), $4, $5);
fixpos($$, $2);
}
| kWHILE {COND_PUSH(1);} expr do {COND_POP();}
| kWHILE {COND_PUSH(1);} expr_value do {COND_POP();}
compstmt
kEND
{
value_expr($3);
$$ = NEW_WHILE(cond($3), $6, 1);
fixpos($$, $3);
}
| kUNTIL {COND_PUSH(1);} expr do {COND_POP();}
| kUNTIL {COND_PUSH(1);} expr_value do {COND_POP();}
compstmt
kEND
{
value_expr($3);
$$ = NEW_UNTIL(cond($3), $6, 1);
fixpos($$, $3);
}
| kCASE expr opt_terms
| kCASE expr_value opt_terms
case_body
kEND
{
value_expr($2);
$$ = NEW_CASE($2, $4);
fixpos($$, $2);
}
@ -1398,11 +1370,10 @@ primary : literal
{
$$ = $3;
}
| kFOR block_var kIN {COND_PUSH(1);} expr do {COND_POP();}
| kFOR block_var kIN {COND_PUSH(1);} expr_value do {COND_POP();}
compstmt
kEND
{
value_expr($5);
$$ = NEW_FOR($2, $5, $8);
fixpos($$, $2);
}
@ -1493,7 +1464,6 @@ primary : literal
}
| kDEF singleton dot_or_colon {lex_state = EXPR_FNAME;} fname
{
value_expr($2);
in_single++;
local_push();
lex_state = EXPR_END; /* force for args */
@ -1534,6 +1504,12 @@ primary : literal
$$ = NEW_RETRY();
}
primary_value : primary
{
value_expr($1);
$$ = $1;
}
then : term
| kTHEN
| term kTHEN
@ -1542,11 +1518,10 @@ do : term
| kDO_COND
if_tail : opt_else
| kELSIF expr then
| kELSIF expr_value then
compstmt
if_tail
{
value_expr($2);
$$ = NEW_IF(cond($2), $4, $5);
fixpos($$, $2);
}
@ -1606,37 +1581,38 @@ block_call : command do_block
$$ = $2;
fixpos($$, $2);
}
| block_call '.' operation2 opt_paren_args
| block_call_value '.' operation2 opt_paren_args
{
value_expr($1);
$$ = new_call($1, $3, $4);
}
| block_call tCOLON2 operation2 opt_paren_args
| block_call_value tCOLON2 operation2 opt_paren_args
{
value_expr($1);
$$ = new_call($1, $3, $4);
}
block_call_value : block_call
{
value_expr($$);
$$ = $1;
}
method_call : operation paren_args
{
$$ = new_fcall($1, $2);
fixpos($$, $2);
}
| primary '.' operation2 opt_paren_args
| primary_value '.' operation2 opt_paren_args
{
value_expr($1);
$$ = new_call($1, $3, $4);
fixpos($$, $1);
}
| primary tCOLON2 operation2 paren_args
| primary_value tCOLON2 operation2 paren_args
{
value_expr($1);
$$ = new_call($1, $3, $4);
fixpos($$, $1);
}
| primary tCOLON2 operation3
| primary_value tCOLON2 operation3
{
value_expr($1);
$$ = new_call($1, $3, 0);
}
| kSUPER paren_args
@ -1685,14 +1661,12 @@ case_body : kWHEN when_args then
}
when_args : args
| args ',' tSTAR arg
| args ',' tSTAR arg_value
{
value_expr($4);
$$ = list_append($1, NEW_WHEN($4, 0, 0));
}
| tSTAR arg
| tSTAR arg_value
{
value_expr($2);
$$ = NEW_LIST(NEW_WHEN($2, 0, 0));
}
@ -1813,7 +1787,7 @@ superclass : term
{
lex_state = EXPR_BEG;
}
expr term
expr_value term
{
$$ = $3;
}
@ -1898,7 +1872,7 @@ f_arg : f_norm_arg
$$ += 1;
}
f_opt : tIDENTIFIER '=' arg
f_opt : tIDENTIFIER '=' arg_value
{
if (!is_local_id($1))
yyerror("formal argument must be local variable");
@ -1952,6 +1926,7 @@ singleton : var_ref
}
else {
$$ = $1;
value_expr($$);
}
}
| '(' {lex_state = EXPR_BEG;} expr opt_nl ')'
@ -1967,6 +1942,7 @@ singleton : var_ref
case NODE_ZARRAY:
yyerror("can't define single method for literals.");
default:
value_expr($3);
break;
}
$$ = $3;
@ -1991,7 +1967,7 @@ assocs : assoc
$$ = list_concat($1, $3);
}
assoc : arg tASSOC arg
assoc : arg_value tASSOC arg_value
{
$$ = list_append(NEW_LIST($1), $3);
}

43
ruby.h
View file

@ -48,39 +48,6 @@ extern "C" {
#define ISXDIGIT(c) (ISASCII(c) && isxdigit((unsigned char)(c)))
#endif
#if !defined(__STDC__) && !defined(_MSC_VER)
# define volatile
#endif
#ifdef __cplusplus
# ifndef HAVE_PROTOTYPES
# define HAVE_PROTOTYPES 1
# endif
# ifndef HAVE_STDARG_PROTOTYPES
# define HAVE_STDARG_PROTOTYPES 1
# endif
#endif
#undef _
#ifdef HAVE_PROTOTYPES
# define _(args) args
#else
# define _(args) ()
#endif
#undef __
#ifdef HAVE_STDARG_PROTOTYPES
# define __(args) args
#else
# define __(args) ()
#endif
#ifdef __cplusplus
#define ANYARGS ...
#else
#define ANYARGS
#endif
#ifndef NORETURN
# define NORETURN(x) x
#endif
@ -420,16 +387,6 @@ struct RBignum {
#define OBJ_FROZEN(x) FL_TEST((x), FL_FREEZE)
#define OBJ_FREEZE(x) FL_SET((x), FL_FREEZE)
#define xmalloc ruby_xmalloc
#define xcalloc ruby_xcalloc
#define xrealloc ruby_xrealloc
#define xfree ruby_xfree
void *xmalloc _((long));
void *xcalloc _((long,long));
void *xrealloc _((void*,long));
void xfree _((void*));
#define ALLOC_N(type,n) (type*)xmalloc(sizeof(type)*(n))
#define ALLOC(type) (type*)xmalloc(sizeof(type))
#define REALLOC_N(var,type,n) (var)=(type*)xrealloc((char*)(var),sizeof(type)*(n))