* parse.y (lambda): Perl6 style -> lambda expression. [NEW]

[VERY EXPERIMENTAL]

* gc.c (id2ref): must not assign pointers to long int.  use
  LONG_LONG instead if SIZEOF_LONG < SIZEOF_VOIDP.
  [ruby-talk:149645]

* ruby.h: use LONG_LONG to simplify the change.
  [ruby-talk:149645]

* dir.c (dir_each): rewinddir(3) before iteration.
  [ruby-talk:149628]

* eval.c (rb_f_throw): replace all '0x%lx' by '%p'.
  [ruby-talk:149553]

* missing/vsnprintf.c (BSD_vfprintf): '%p' need to handle 64bit
  size pointer.  [ruby-talk:149553]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8847 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2005-07-27 07:27:19 +00:00
Родитель 2ea2d95e81
Коммит 759a63b6a3
14 изменённых файлов: 315 добавлений и 144 удалений

Просмотреть файл

@ -1,3 +1,30 @@
Wed Jul 27 16:25:59 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* parse.y (lambda): Perl6 style -> lambda expression. [NEW]
[VERY EXPERIMENTAL]
Wed Jul 27 10:43:14 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* gc.c (id2ref): must not assign pointers to long int. use
LONG_LONG instead if SIZEOF_LONG < SIZEOF_VOIDP.
[ruby-talk:149645]
* ruby.h: use LONG_LONG to simplify the change.
[ruby-talk:149645]
Wed Jul 27 10:59:02 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* dir.c (dir_each): rewinddir(3) before iteration.
[ruby-talk:149628]
Wed Jul 27 02:34:58 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_f_throw): replace all '0x%lx' by '%p'.
[ruby-talk:149553]
* missing/vsnprintf.c (BSD_vfprintf): '%p' need to handle 64bit
size pointer. [ruby-talk:149553]
Tue Jul 26 22:41:28 2005 Minero Aoki <aamine@loveruby.net>
* ext/ripper/lib/ripper/sexp.rb: new method Ripper.sexp_raw.

1
dir.c
Просмотреть файл

@ -543,6 +543,7 @@ dir_each(dir)
struct dirent *dp;
GetDIR(dir, dirp);
rewinddir(dirp->dir);
for (dp = readdir(dirp->dir); dp != NULL; dp = readdir(dirp->dir)) {
rb_yield(rb_tainted_str_new(dp->d_name, NAMLEN(dp)));
if (dirp->dir == NULL) dir_closed();

Просмотреть файл

@ -280,7 +280,7 @@ rb_check_type(x, t)
}
type++;
}
rb_bug("unknown type 0x%x (0x%x given)", t, TYPE(x));
rb_bug("unknown type 0x%x (%p given)", t, TYPE(x));
}
}

176
eval.c
Просмотреть файл

@ -198,6 +198,7 @@ typedef jmp_buf rb_jmpbuf_t;
VALUE rb_cProc;
static VALUE rb_cBinding;
static VALUE proc_invoke _((VALUE,VALUE,VALUE,VALUE));
static VALUE proc_lambda _((void));
static VALUE rb_f_binding _((VALUE));
static void rb_f_END _((void));
static VALUE rb_f_block_given_p _((void));
@ -1104,6 +1105,7 @@ static VALUE module_setup _((VALUE,NODE*));
static VALUE massign _((VALUE,NODE*,VALUE,int));
static void assign _((VALUE,NODE*,VALUE,int));
static void formal_assign _((VALUE, NODE*, int, VALUE*, VALUE*));
typedef struct event_hook {
rb_event_hook_func_t func;
@ -2826,13 +2828,13 @@ unknown_node(node)
{
ruby_current_node = 0;
if (node->flags == 0) {
rb_bug("terminated node (0x%lx)", (long)node);
rb_bug("terminated node (%p)", node);
}
else if (BUILTIN_TYPE(node) != T_NODE) {
rb_bug("not a node 0x%02lx (0x%lx)", BUILTIN_TYPE(node), (long)node);
rb_bug("not a node 0x%02lx (%p)", BUILTIN_TYPE(node), node);
}
else {
rb_bug("unknown node type %d (0x%lx)", nd_type(node), (long)node);
rb_bug("unknown node type %d (%p)", nd_type(node), node);
}
}
@ -3113,9 +3115,21 @@ rb_eval(self, n)
result = block_pass(self, node);
break;
case NODE_LAMBDA:
PUSH_TAG(PROT_LOOP);
PUSH_BLOCK(node->nd_var, node->nd_body);
state = EXEC_TAG();
PUSH_ITER(ITER_PRE);
ruby_iter->iter = ruby_frame->iter = ITER_CUR;
result = proc_lambda();
POP_ITER();
POP_BLOCK();
POP_TAG();
break;
case NODE_ITER:
case NODE_FOR:
case NODE_LAMBDA:
{
PUSH_TAG(PROT_LOOP);
PUSH_BLOCK(node->nd_var, node->nd_body);
@ -4872,6 +4886,12 @@ rb_yield_0(val, self, klass, flags, avalue)
}
massign(self, var, val, lambda);
}
else if (nd_type(var) == NODE_ARGS) {
if (!avalue) {
val = svalue_to_mrhs(val, var->nd_head);
}
formal_assign(self, var, RARRAY(val)->len, RARRAY(val)->ptr, 0);
}
else {
int len = 0;
if (avalue) {
@ -5694,6 +5714,74 @@ call_cfunc(func, recv, len, argc, argv)
return Qnil; /* not reached */
}
static void
formal_assign(recv, node, argc, argv, local_vars)
VALUE recv;
NODE *node;
int argc;
VALUE *argv;
VALUE *local_vars;
{
int i;
if (nd_type(node) != NODE_ARGS) {
rb_bug("no argument-node");
}
i = node->nd_frml ? RARRAY(node->nd_frml)->len : 0;
if (i > argc) {
rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", argc, i);
}
if (!node->nd_rest) {
int nopt = i;
NODE *optnode = node->nd_opt;
while (optnode) {
nopt++;
optnode = optnode->nd_next;
}
if (nopt < argc) {
rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", argc, nopt);
}
}
if (local_vars) {
if (i > 0) {
/* +2 for $_ and $~ */
MEMCPY(local_vars+2, argv, VALUE, i);
}
}
else {
int j;
VALUE a = node->nd_frml;
for (j=0; j<i; j++) {
dvar_asgn_curr(SYM2ID(RARRAY(a)->ptr[j]), argv[j]);
}
}
argv += i; argc -= i;
if (node->nd_opt) {
NODE *opt = node->nd_opt;
while (opt && argc) {
assign(recv, opt->nd_head, *argv, 1);
argv++; argc--;
opt = opt->nd_next;
}
if (opt) {
rb_eval(recv, opt);
}
}
if (node->nd_rest && !NIL_P(node->nd_rest)) {
VALUE v;
if (argc > 0)
v = rb_ary_new4(argc,argv);
else
v = rb_ary_new2(0);
assign(recv, node->nd_rest, v, 1);
}
}
static VALUE
rb_call0(klass, recv, id, oid, argc, argv, body, nosuper)
VALUE klass, recv;
@ -5824,7 +5912,6 @@ rb_call0(klass, recv, id, oid, argc, argv, body, nosuper)
if ((state = EXEC_TAG()) == 0) {
NODE *node = 0;
int i;
if (nd_type(body) == NODE_ARGS) {
node = body;
@ -5835,60 +5922,10 @@ rb_call0(klass, recv, id, oid, argc, argv, body, nosuper)
body = body->nd_next;
}
if (node) {
if (nd_type(node) != NODE_ARGS) {
rb_bug("no argument-node");
formal_assign(recv, node, argc, argv, local_vars);
if (node->nd_rest) {
ruby_frame->argc = -(ruby_frame->argc - argc)-1;
}
i = node->nd_cnt;
if (i > argc) {
rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", argc, i);
}
if ((long)node->nd_rest == -1) {
int opt = i;
NODE *optnode = node->nd_opt;
while (optnode) {
opt++;
optnode = optnode->nd_next;
}
if (opt < argc) {
rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)",
argc, opt);
}
ruby_frame->argc = opt;
}
if (local_vars) {
if (i > 0) {
/* +2 for $_ and $~ */
MEMCPY(local_vars+2, argv, VALUE, i);
}
argv += i; argc -= i;
if (node->nd_opt) {
NODE *opt = node->nd_opt;
while (opt && argc) {
assign(recv, opt->nd_head, *argv, 1);
argv++; argc--;
opt = opt->nd_next;
}
if (opt) {
rb_eval(recv, opt);
}
}
if ((long)node->nd_rest >= 0) {
VALUE v;
if (argc > 0)
v = rb_ary_new4(argc,argv);
else
v = rb_ary_new2(0);
ruby_scope->local_vars[node->nd_rest] = v;
}
}
}
if ((long)node->nd_rest >= 0) {
ruby_frame->argc = -(ruby_frame->argc - argc)-1;
}
if (event_hooks) {
@ -5950,7 +5987,7 @@ rb_call(klass, recv, mid, argc, argv, scope)
struct cache_entry *ent;
if (!klass) {
rb_raise(rb_eNotImpError, "method `%s' called on terminated object (0x%lx)",
rb_raise(rb_eNotImpError, "method `%s' called on terminated object (%p)",
rb_id2name(mid), recv);
}
/* is it in the method cache? */
@ -8664,16 +8701,15 @@ proc_to_s(self)
struct BLOCK *data;
NODE *node;
char *cname = rb_obj_classname(self);
const int w = (SIZEOF_LONG * CHAR_BIT) / 4;
VALUE str;
Data_Get_Struct(self, struct BLOCK, data);
if ((node = data->frame.node) || (node = data->body)) {
str = rb_sprintf("#<%s:0x%.*lx@%s:%d>", cname, w, (VALUE)data->body,
str = rb_sprintf("#<%s:%p@%s:%d>", cname, data->body,
node->nd_file, nd_line(node));
}
else {
str = rb_sprintf("#<%s:0x%.*lx>", cname, w, (VALUE)data->body);
str = rb_sprintf("#<%s:%p>", cname, data->body);
}
if (OBJ_TAINTED(self)) OBJ_TAINT(str);
@ -9291,7 +9327,7 @@ rb_node_arity(body)
body = body->nd_head;
if (!body) return 0;
n = body->nd_cnt;
if (body->nd_opt || body->nd_rest != -1)
if (body->nd_opt || body->nd_rest)
n = -n-1;
return n;
default:
@ -10613,7 +10649,7 @@ rb_thread_deadlock()
char msg[21+SIZEOF_LONG*2];
VALUE e;
sprintf(msg, "Thread(0x%lx): deadlock", curr_thread->thread);
sprintf(msg, "Thread(%p): deadlock", curr_thread->thread);
e = rb_exc_new2(rb_eFatal, msg);
if (curr_thread == main_thread) {
rb_exc_raise(e);
@ -10915,13 +10951,13 @@ rb_thread_schedule()
TRAP_END;
}
FOREACH_THREAD_FROM(curr, th) {
warn_printf("deadlock 0x%lx: %s:",
warn_printf("deadlock %p: %s:",
th->thread, thread_status_name(th->status));
if (th->wait_for & WAIT_FD) warn_printf("F(%d)", th->fd);
if (th->wait_for & WAIT_SELECT) warn_printf("S");
if (th->wait_for & WAIT_TIME) warn_printf("T(%f)", th->delay);
if (th->wait_for & WAIT_JOIN)
warn_printf("J(0x%lx)", th->join ? th->join->thread : 0);
warn_printf("J(%p)", th->join ? th->join->thread : 0);
if (th->wait_for & WAIT_PID) warn_printf("P");
if (!th->wait_for) warn_printf("-");
warn_printf(" %s - %s:%d\n",
@ -11157,10 +11193,10 @@ rb_thread_join(th, limit)
if (rb_thread_critical) rb_thread_deadlock();
if (!rb_thread_dead(th)) {
if (th == curr_thread)
rb_raise(rb_eThreadError, "thread 0x%lx tried to join itself",
rb_raise(rb_eThreadError, "thread %p tried to join itself",
th->thread);
if ((th->wait_for & WAIT_JOIN) && th->join == curr_thread)
rb_raise(rb_eThreadError, "Thread#join: deadlock 0x%lx - mutual join(0x%lx)",
rb_raise(rb_eThreadError, "Thread#join: deadlock %p - mutual join(%p)",
curr_thread->thread, th->thread);
if (curr_thread->status == THREAD_TO_KILL)
last_status = THREAD_TO_KILL;
@ -12773,7 +12809,7 @@ rb_thread_inspect(thread)
const char *status = thread_status_name(th->status);
VALUE str;
str = rb_sprintf("#<%s:0x%lx %s>", cname, thread, status);
str = rb_sprintf("#<%s:%p %s>", cname, thread, status);
OBJ_INFECT(str, thread);
return str;
@ -13310,7 +13346,7 @@ rb_f_throw(argc, argv)
break;
}
if (tt->tag == PROT_THREAD) {
rb_raise(rb_eThreadError, "uncaught throw `%s' in thread 0x%lx",
rb_raise(rb_eThreadError, "uncaught throw `%s' in thread %p",
rb_id2name(SYM2ID(tag)),
curr_thread);
}

Просмотреть файл

@ -61,6 +61,7 @@ class Ripper
:def => 3,
:defined => 1,
:defs => 5,
:do_block => 1,
:do_block => 2,
:dot2 => 2,
:dot3 => 2,
@ -76,6 +77,7 @@ class Ripper
:if_mod => 2,
:ifop => 3,
:iter_block => 2,
:lambda => 2,
:massign => 2,
:method_add_arg => 2,
:mlhs_add => 2,
@ -382,6 +384,10 @@ class Ripper
a
end
def on_do_block(a)
a
end
def on_do_block(a, b)
a
end
@ -442,6 +448,10 @@ class Ripper
a
end
def on_lambda(a, b)
a
end
def on_massign(a, b)
a
end

22
gc.c
Просмотреть файл

@ -771,6 +771,7 @@ gc_mark_children(ptr, lev)
case NODE_RESCUE:
case NODE_RESBODY:
case NODE_CLASS:
case NODE_ARGS:
gc_mark((VALUE)obj->as.node.u2.node, lev);
/* fall through */
case NODE_BLOCK: /* 1,3 */
@ -838,7 +839,6 @@ gc_mark_children(ptr, lev)
case NODE_NEXT:
case NODE_YIELD:
case NODE_COLON2:
case NODE_ARGS:
case NODE_SPLAT:
case NODE_TO_ARY:
case NODE_SVALUE:
@ -984,7 +984,7 @@ gc_mark_children(ptr, lev)
break;
default:
rb_bug("rb_gc_mark(): unknown data type 0x%lx(0x%lx) %s",
rb_bug("rb_gc_mark(): unknown data type %p(%p) %s",
obj->as.basic.flags & T_MASK, obj,
is_pointer_to_heap(obj) ? "corrupted object" : "non object");
}
@ -1236,7 +1236,7 @@ obj_free(obj)
break;
default:
rb_bug("gc_sweep(): unknown data type 0x%lx(%ld)", obj,
rb_bug("gc_sweep(): unknown data type %p(%ld)", obj,
RANY(obj)->as.basic.flags & T_MASK);
}
}
@ -1871,10 +1871,18 @@ static VALUE
id2ref(obj, id)
VALUE obj, id;
{
unsigned long ptr, p0;
#if SIZEOF_LONG == SIZEOF_VOIDP
#define NUM2PTR(x) NUM2ULONG(x)
#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
#define NUM2PTR(x) NUM2ULL(x)
#endif
VALUE ptr;
void *p0;
rb_secure(4);
p0 = ptr = NUM2ULONG(id);
ptr = NUM2PTR(id);
p0 = (void *)ptr;
if (ptr == Qtrue) return Qtrue;
if (ptr == Qfalse) return Qfalse;
if (ptr == Qnil) return Qnil;
@ -1885,10 +1893,10 @@ id2ref(obj, id)
ptr = id ^ FIXNUM_FLAG; /* unset FIXNUM_FLAG */
if (!is_pointer_to_heap((void *)ptr)|| BUILTIN_TYPE(ptr) >= T_BLOCK) {
rb_raise(rb_eRangeError, "0x%lx is not id value", p0);
rb_raise(rb_eRangeError, "%p is not id value", p0);
}
if (BUILTIN_TYPE(ptr) == 0 || RBASIC(ptr)->klass == 0) {
rb_raise(rb_eRangeError, "0x%lx is recycled object", p0);
rb_raise(rb_eRangeError, "%p is recycled object", p0);
}
return (VALUE)ptr;
}

2
io.c
Просмотреть файл

@ -44,7 +44,7 @@
#endif
#include <sys/types.h>
#if !defined(DJGPP) && !defined(_WIN32) && !defined(__human68k__)
#if defined(HAVE_SYS_IOCTL_H) && !defined(DJGPP) && !defined(_WIN32) && !defined(__human68k__)
#include <sys/ioctl.h>
#endif
#if defined(HAVE_FCNTL_H) || defined(_WIN32)

Просмотреть файл

@ -789,14 +789,19 @@ fp_begin: _double = va_arg(ap, double);
* defined manner.''
* -- ANSI X3J11
*/
#ifdef _HAVE_LLP64_
uqval = (u_long)va_arg(ap, void *);
flags = (flags) | QUADINT | HEXPREFIX;
#else
ulval = (u_long)va_arg(ap, void *);
base = 16;
xdigs = "0123456789abcdef";
#ifdef _HAVE_SANE_QUAD_
flags = (flags & ~QUADINT) | HEXPREFIX;
#else /* _HAVE_SANE_QUAD_ */
flags = (flags) | HEXPREFIX;
#endif /* _HAVE_SANE_QUAD_ */
#endif
base = 16;
xdigs = "0123456789abcdef";
ch = 'x';
goto nosign;
case 's':

5
node.h
Просмотреть файл

@ -208,8 +208,8 @@ typedef struct RNode {
#define nd_lit u1.value
#define nd_frml u1.node
#define nd_rest u2.argc
#define nd_frml u3.value
#define nd_rest u2.node
#define nd_opt u1.node
#define nd_recv u1.node
@ -258,6 +258,7 @@ typedef struct RNode {
#define NEW_UNTIL(c,b,n) NEW_NODE(NODE_UNTIL,c,b,n)
#define NEW_FOR(v,i,b) NEW_NODE(NODE_FOR,v,b,i)
#define NEW_ITER(v,i,b) NEW_NODE(NODE_ITER,v,b,i)
#define NEW_LAMBDA(a,b) NEW_NODE(NODE_LAMBDA,a,b,0)
#define NEW_BREAK(s) NEW_NODE(NODE_BREAK,s,0,0)
#define NEW_NEXT(s) NEW_NODE(NODE_NEXT,s,0,0)
#define NEW_REDO() NEW_NODE(NODE_REDO,0,0,0)

Просмотреть файл

@ -300,7 +300,7 @@ rb_any_to_s(obj)
char *cname = rb_obj_classname(obj);
VALUE str;
str = rb_sprintf("#<%s:0x%lx>", cname, obj);
str = rb_sprintf("#<%s:%p>", cname, obj);
if (OBJ_TAINTED(obj)) OBJ_TAINT(str);
return str;
@ -384,7 +384,7 @@ rb_obj_inspect(obj)
char *c;
c = rb_obj_classname(obj);
str = rb_sprintf("-<%s:0x%lx", c, obj);
str = rb_sprintf("-<%s:%p", c, obj);
return rb_exec_recursive(inspect_obj, obj, str);
}
return rb_funcall(obj, rb_intern("to_s"), 0, 0);

185
parse.y
Просмотреть файл

@ -505,15 +505,15 @@ static void ripper_compile_error _((struct parser_params*, const char *fmt, ...)
%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
%type <node> mrhs superclass block_call block_command
%type <node> f_arglist f_args f_optarg f_opt f_block_arg opt_f_block_arg
%type <node> f_arglist f_args f_rest_arg f_optarg f_opt f_block_arg opt_f_block_arg
%type <node> assoc_list assocs assoc undef_list backref string_dvar
%type <node> for_var block_var opt_block_var block_var_def block_param
%type <node> opt_bv_decl bv_decls bv_decl
%type <node> opt_bv_decl bv_decls bv_decl lambda f_larglist lambda_body
%type <node> brace_block cmd_brace_block do_block lhs none fitem
%type <node> mlhs mlhs_head mlhs_basic mlhs_entry mlhs_item mlhs_node
%type <id> fsym variable sym symbol operation operation2 operation3
%type <id> cname fname op f_rest_arg
%type <num> f_norm_arg f_arg
%type <id> cname fname op f_norm_arg
%type <val> f_arg
/*%%%*/
/*%
%type <val> program reswords then do dot_or_colon
@ -544,6 +544,8 @@ static void ripper_compile_error _((struct parser_params*, const char *fmt, ...)
%token tLBRACE_ARG /* { */
%token tSTAR /* * */
%token tAMPER /* & */
%token tLAMBDA /* -> */
%token tLAMBDA_ARG /* -> */
%token tSYMBEG tSTRING_BEG tXSTRING_BEG tREGEXP_BEG tWORDS_BEG tQWORDS_BEG
%token tSTRING_DBEG tSTRING_DVAR tSTRING_END
@ -1033,11 +1035,6 @@ expr : command_call
$$ = dispatch2(unary, ID2SYM('!'), $2);
%*/
}
| do_block
{
$$ = $1;
nd_set_type($$, NODE_LAMBDA);
}
| arg
;
@ -2531,29 +2528,6 @@ primary : literal
$$ = dispatch1(hash, escape_Qundef($2));
%*/
}
| tLBRACE
{
/*%%%*/
$<vars>$ = dyna_push();
$<num>1 = ruby_sourceline;
/*%
%*/
}
block_var_def {$<vars>$ = ruby_dyna_vars;}
compstmt
'}'
{
/*%%%*/
$3->nd_body = block_append($3->nd_body,
dyna_init($5, $<vars>4));
$$ = $3;
nd_set_type($3, NODE_LAMBDA);
nd_set_line($$, $<num>1);
dyna_pop($<vars>2);
/*%
$$ = dispatch2(brace_block, escape_Qundef($3), $5);
%*/
}
| kRETURN
{
/*%%%*/
@ -2619,6 +2593,11 @@ primary : literal
$$ = dispatch2(iter_block, $1, $2);
%*/
}
| tLAMBDA
lambda
{
$$ = $2;
}
| kIF expr_value then
compstmt
if_tail
@ -3185,6 +3164,84 @@ bv_decl : tIDENTIFIER
}
;
lambda : {
/*%%%*/
$<vars>$ = dyna_push();
/*%
%*/
}
f_larglist
{
lex_state = EXPR_END;
$<vars>$ = ruby_dyna_vars;
}
lambda_body
{
/*%%%*/
$$ = NEW_LAMBDA($2, $4);
dyna_pop($<vars>1);
/*%
$$ = dispatch2(lambda, $2, $4);
%*/
}
;
f_larglist : '(' f_args rparen
{
/*%%%*/
$$ = $2;
/*%
$$ = dispatch1(paren, $2);
%*/
}
| f_arg opt_terms
{
/*%%%*/
$$ = NEW_ARGS($1, 0, 0);
/*%
$$ = dispatch4(params, $1, Qnil, Qnil, Qnil);
%*/
}
| f_arg ',' f_rest_arg opt_terms
{
/*%%%*/
$$ = NEW_ARGS($1, 0, $3);
/*%
$$ = dispatch4(params, $1, Qnil, $3, Qnil);
%*/
}
| f_rest_arg opt_terms
{
/*%%%*/
$$ = NEW_ARGS(0, 0, $1);
/*%
$$ = dispatch4(params, Qnil, Qnil, $1, Qnil);
%*/
}
| /* none */
{
/*%%%*/
$$ = NEW_ARGS(0, 0, 0);
/*%
$$ = dispatch4(params, Qnil, Qnil, Qnil, Qnil);
%*/
}
;
lambda_body : '{'
compstmt
'}'
{
$$ = $2;
}
| kDO
compstmt
kEND
{
$$ = $2;
}
;
do_block : kDO_BLOCK
{
/*%%%*/
@ -3375,6 +3432,17 @@ brace_block : '{'
$$ = dispatch2(do_block, escape_Qundef($3), $5);
%*/
}
| tLAMBDA_ARG
lambda
{
/*%%%*/
$$ = $2;
nd_set_type($$, NODE_ITER);
/*%
$$ = $2;
$$ = dispatch1(do_block, $2);
%*/
}
;
case_body : kWHEN when_args then
@ -3922,7 +3990,7 @@ f_args : f_arg ',' f_optarg ',' f_rest_arg opt_f_block_arg
| f_arg ',' f_optarg opt_f_block_arg
{
/*%%%*/
$$ = block_append(NEW_ARGS($1, $3, -1), $4);
$$ = block_append(NEW_ARGS($1, $3, 0), $4);
/*%
$$ = dispatch4(params, $1, $3, Qnil, escape_Qundef($4));
%*/
@ -3938,7 +4006,7 @@ f_args : f_arg ',' f_optarg ',' f_rest_arg opt_f_block_arg
| f_arg opt_f_block_arg
{
/*%%%*/
$$ = block_append(NEW_ARGS($1, 0, -1), $2);
$$ = block_append(NEW_ARGS($1, 0, 0), $2);
/*%
$$ = dispatch4(params, $1, Qnil, Qnil, escape_Qundef($2));
%*/
@ -3954,7 +4022,7 @@ f_args : f_arg ',' f_optarg ',' f_rest_arg opt_f_block_arg
| f_optarg opt_f_block_arg
{
/*%%%*/
$$ = block_append(NEW_ARGS(0, $1, -1), $2);
$$ = block_append(NEW_ARGS(0, $1, 0), $2);
/*%
$$ = dispatch4(params, Qnil, $1, Qnil, escape_Qundef($2));
%*/
@ -3970,7 +4038,7 @@ f_args : f_arg ',' f_optarg ',' f_rest_arg opt_f_block_arg
| f_block_arg
{
/*%%%*/
$$ = block_append(NEW_ARGS(0, 0, -1), $1);
$$ = block_append(NEW_ARGS(0, 0, 0), $1);
/*%
$$ = dispatch4(params, Qnil, Qnil, Qnil, $1);
%*/
@ -3978,7 +4046,7 @@ f_args : f_arg ',' f_optarg ',' f_rest_arg opt_f_block_arg
| /* none */
{
/*%%%*/
$$ = NEW_ARGS(0, 0, -1);
$$ = NEW_ARGS(0, 0, 0);
/*%
$$ = dispatch4(params, Qnil, Qnil, Qnil, Qnil);
%*/
@ -4024,8 +4092,13 @@ f_norm_arg : tCONSTANT
yyerror("formal argument must be local variable");
else if (local_id($1))
yyerror("duplicate argument name");
local_cnt($1);
$$ = 1;
if (dyna_in_block()) {
dyna_var($1);
}
else {
local_cnt($1);
}
$$ = $1;
/*%
$$ = $1;
%*/
@ -4033,18 +4106,11 @@ f_norm_arg : tCONSTANT
;
f_arg : f_norm_arg
/*%c%*/
/*%c
{ $$ = rb_ary_new3(1, $1); }
%*/
{ $$ = rb_ary_new3(1, ID2SYM($1)); }
| f_arg ',' f_norm_arg
{
/*%%%*/
$$ += 1;
/*%
$$ = $1;
rb_ary_push($$, $3);
%*/
rb_ary_push($$, ID2SYM($3));
}
;
@ -4092,7 +4158,7 @@ f_rest_arg : restarg_mark tIDENTIFIER
yyerror("rest argument must be local variable");
else if (local_id($2))
yyerror("duplicate rest argument name");
$$ = local_cnt($2);
$$ = assignable($2, 0);
/*%
$$ = dispatch1(restparam, $2);
%*/
@ -4100,7 +4166,7 @@ f_rest_arg : restarg_mark tIDENTIFIER
| restarg_mark
{
/*%%%*/
$$ = local_append((ID)0);
$$ = (NODE*)Qnil;
/*%
$$ = dispatch1(restparam, Qnil);
%*/
@ -6000,6 +6066,19 @@ parser_yylex(parser)
lex_state = EXPR_BEG;
return tOP_ASGN;
}
if (c == '>') {
enum lex_state_e state = lex_state;
lex_state = EXPR_ARG;
switch (state) {
case EXPR_CMDARG:
case EXPR_ENDARG:
case EXPR_ARG:
case EXPR_END:
return tLAMBDA_ARG;
default:
return tLAMBDA;
}
}
if (IS_BEG() ||
(IS_ARG() && space_seen && !ISSPACE(c))) {
if (IS_ARG()) arg_ambiguous();
@ -8692,7 +8771,7 @@ ripper_validate_object(self, x)
if (FIXNUM_P(x)) return x;
if (SYMBOL_P(x)) return x;
if (!rb_is_pointer_to_heap(x))
rb_raise(rb_eArgError, "invalid pointer: 0x%x", x);
rb_raise(rb_eArgError, "invalid pointer: %p", x);
switch (TYPE(x)) {
case T_STRING:
case T_OBJECT:
@ -8701,9 +8780,9 @@ ripper_validate_object(self, x)
case T_FLOAT:
return x;
case T_NODE:
rb_raise(rb_eArgError, "NODE given: 0x%x", x);
rb_raise(rb_eArgError, "NODE given: %p", x);
default:
rb_raise(rb_eArgError, "wrong type of ruby object: 0x%x (%s)",
rb_raise(rb_eArgError, "wrong type of ruby object: %p (%s)",
x, rb_obj_classname(x));
}
return x;

7
ruby.h
Просмотреть файл

@ -81,11 +81,8 @@ extern "C" {
typedef unsigned long VALUE;
typedef unsigned long ID;
#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
typedef unsigned long long VALUE;
typedef unsigned long long ID;
#elif SIZEOF___INT64 == SIZEOF_VOIDP
typedef unsigned __int64 VALUE;
typedef unsigned __int64 ID;
typedef unsigned LONG_LONG VALUE;
typedef unsigned LONG_LONG ID;
#else
# error ---->> ruby requires sizeof(void*) == sizeof(long) to be compiled. <<----
#endif

Просмотреть файл

@ -838,6 +838,13 @@ fmt_setup(buf, c, flags, width, prec)
#undef feof
#undef ferror
#undef fileno
#if SIZEOF_LONG < SIZEOF_VOIDP
# if SIZEOF_LONG_LONG == SIZEOF_VOIDP
# define _HAVE_SANE_QUAD_
# define _HAVE_LLP64_
# define u_quad_t unsigned LONG_LONG
# endif
#endif
#include "missing/vsnprintf.c"
static int

Просмотреть файл

@ -205,7 +205,7 @@ rb_class_path(klass)
s = rb_class2name(RBASIC(klass)->klass);
}
}
path = rb_sprintf("#<%s:0x%lx>", s, klass);
path = rb_sprintf("#<%s:%p>", s, klass);
rb_ivar_set(klass, tmp_classpath, path);
return path;