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

* ext/racc/cparse/cparse.c: sync with original source code, rev 1.6.

* ext/racc/cparse/cparse.c: do not use rb_iterate to give a block to the method, use rb_block_call instead. [ruby-dev:28445]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10449 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
aamine 2006-07-02 09:43:11 +00:00
parent 62a7c8fb13
commit cafdfd306e
2 changed files with 47 additions and 48 deletions

View file

@ -1,3 +1,11 @@
Sun Jul 2 18:42:27 2006 Minero Aoki <aamine@loveruby.net>
* ext/racc/cparse/cparse.c: sync with original source code, rev
1.6.
* ext/racc/cparse/cparse.c: do not use rb_iterate to give a block
to the method, use rb_block_call instead. [ruby-dev:28445]
Sun Jul 2 11:22:03 2006 Tanaka Akira <akr@m17n.org>
* io.c (io_reopen): STDOUT.reopen(filename, "w+") didn't work.

View file

@ -1,25 +1,23 @@
/*
cparse.c -- racc runtime core
cparse.c -- Racc Runtime Core
Copyright (c) 1999-2003 Minero Aoki <aamine@loveruby.net>
Copyright (c) 1999-2006 Minero Aoki
This library is free software.
You can distribute/modify this program under the same terms of ruby.
$raccId: cparse.c,v 1.3 2003/11/03 12:20:54 aamine Exp $
$originalId: cparse.c,v 1.6 2006/07/02 09:34:14 aamine Exp $
*/
#include "ruby.h"
#include <stdio.h>
/* -----------------------------------------------------------------------
Important Constants
----------------------------------------------------------------------- */
#define RACC_VERSION "1.4.4"
#define RACC_VERSION "1.4.5"
#define DEFAULT_TOKEN -1
#define ERROR_TOKEN 1
@ -29,7 +27,6 @@
#define vERROR_TOKEN INT2FIX(ERROR_TOKEN)
#define vFINAL_TOKEN INT2FIX(FINAL_TOKEN)
/* -----------------------------------------------------------------------
File Local Variables
----------------------------------------------------------------------- */
@ -41,8 +38,6 @@ static ID id_yydebug;
static ID id_nexttoken;
static ID id_onerror;
static ID id_noreduce;
static ID id_catch;
static VALUE sym_raccjump;
static ID id_errstatus;
static ID id_d_shift;
@ -52,40 +47,39 @@ static ID id_d_read_token;
static ID id_d_next_state;
static ID id_d_e_pop;
/* -----------------------------------------------------------------------
Utils
----------------------------------------------------------------------- */
/* For backward compatibility */
#ifndef ID2SYM
# define ID2SYM(i) ULONG2NUM(i)
#endif
#ifndef SYM2ID
# define SYM2ID(v) ((ID)NUM2ULONG(v))
#endif
#ifndef SYMBOL_P
# define SYMBOL_P(v) FIXNUM_P(v)
#endif
#ifndef LONG2NUM
# define LONG2NUM(i) INT2NUM(i)
#endif
#if RUBY_VERSION_CODE >= 190
# define HAVE_RB_BLOCK_CALL 1
#endif
static ID value_to_id _((VALUE v));
static inline long num_to_long _((VALUE n));
#ifdef ID2SYM
# define id_to_value(i) ID2SYM(i)
#else
# define id_to_value(i) ULONG2NUM(i)
#endif
static ID
value_to_id(VALUE v)
{
#ifndef SYMBOL_P
# define SYMBOL_P(v) FIXNUM_P(v)
#endif
if (! SYMBOL_P(v)) {
rb_raise(rb_eTypeError, "not symbol");
}
#ifdef SYM2ID
return SYM2ID(v);
#else
return (ID)NUM2ULONG(v);
#endif
}
#ifndef LONG2NUM
# define LONG2NUM(i) INT2NUM(i)
#endif
static inline long
num_to_long(VALUE n)
{
@ -95,7 +89,6 @@ num_to_long(VALUE n)
#define AREF(s, idx) \
((0 <= idx && idx < RARRAY(s)->len) ? RARRAY(s)->ptr[idx] : Qnil)
/* -----------------------------------------------------------------------
Parser Stack Interfaces
----------------------------------------------------------------------- */
@ -129,7 +122,6 @@ cut_stack_tail(VALUE stack, long len)
#define GET_TAIL(s, len) get_stack_tail(s, len)
#define CUT_TAIL(s, len) cut_stack_tail(s, len)
/* -----------------------------------------------------------------------
struct cparse_params
----------------------------------------------------------------------- */
@ -187,7 +179,6 @@ struct cparse_params {
long i; /* table index */
};
/* -----------------------------------------------------------------------
Parser Main Routines
----------------------------------------------------------------------- */
@ -213,7 +204,6 @@ static void extract_user_token _((struct cparse_params *v,
VALUE block_args, VALUE *tok, VALUE *val));
static void shift _((struct cparse_params* v, long act, VALUE tok, VALUE val));
static int reduce _((struct cparse_params* v, long act));
static VALUE catch_iter _((VALUE dummy));
static VALUE reduce0 _((VALUE block_args, VALUE data, VALUE self));
#ifdef DEBUG
@ -260,12 +250,13 @@ racc_yyparse(VALUE parser, VALUE lexer, VALUE lexmid, VALUE arg, VALUE sysdebug)
return v->retval;
}
#ifdef HAVE_RB_BLOCK_CALL
static void
call_lexer(struct cparse_params *v)
{
rb_iterate(lexer_iter, v->value_v, lexer_i, v->value_v);
rb_block_call(v->lexer, v->lexmid, 0, NULL, lexer_i, v->value_v);
}
#else
static VALUE
lexer_iter(VALUE data)
{
@ -276,6 +267,13 @@ lexer_iter(VALUE data)
return Qnil;
}
static void
call_lexer(struct cparse_params *v)
{
rb_iterate(lexer_iter, v->value_v, lexer_i, v->value_v);
}
#endif
static VALUE
lexer_i(VALUE block_args, VALUE data, VALUE self)
{
@ -313,7 +311,8 @@ assert_integer(VALUE n)
}
static void
initialize_params(struct cparse_params *v, VALUE parser, VALUE arg, VALUE lexer, VALUE lexmid)
initialize_params(struct cparse_params *v,
VALUE parser, VALUE arg, VALUE lexer, VALUE lexmid)
{
v->value_v = Data_Wrap_Struct(CparseParams, 0, 0, v);
@ -364,7 +363,8 @@ initialize_params(struct cparse_params *v, VALUE parser, VALUE arg, VALUE lexer,
}
static void
extract_user_token(struct cparse_params *v, VALUE block_args, VALUE *tok, VALUE *val)
extract_user_token(struct cparse_params *v, VALUE block_args,
VALUE *tok, VALUE *val)
{
if (NIL_P(block_args)) {
/* EOF */
@ -631,17 +631,11 @@ reduce(struct cparse_params *v, long act)
{
VALUE code;
v->ruleno = -act * 3;
code = rb_iterate(catch_iter, Qnil, reduce0, v->value_v);
code = rb_catch("racc_jump", reduce0, v->value_v);
v->errstatus = num_to_long(rb_ivar_get(v->parser, id_errstatus));
return NUM2INT(code);
}
static VALUE
catch_iter(VALUE dummy)
{
return rb_funcall(rb_mKernel, id_catch, 1, sym_raccjump);
}
static VALUE
reduce0(VALUE val, VALUE data, VALUE self)
{
@ -649,7 +643,7 @@ reduce0(VALUE val, VALUE data, VALUE self)
VALUE reduce_to, reduce_len, method_id;
long len;
ID mid;
VALUE tmp, tmp_t, tmp_v;
VALUE tmp, tmp_t = Qundef, tmp_v = Qundef;
long i, k1, k2;
VALUE goto_state;
@ -748,13 +742,12 @@ reduce0(VALUE val, VALUE data, VALUE self)
goto transit;
}
/* -----------------------------------------------------------------------
Ruby Interface
----------------------------------------------------------------------- */
void
Init_cparse()
Init_cparse(void)
{
VALUE Racc, Parser;
ID id_racc = rb_intern("Racc");
@ -772,7 +765,7 @@ Init_cparse()
rb_define_const(Parser, "Racc_Runtime_Core_Version_C",
rb_str_new2(RACC_VERSION));
rb_define_const(Parser, "Racc_Runtime_Core_Id_C",
rb_str_new2("$raccId: cparse.c,v 1.3 2003/11/03 12:20:54 aamine Exp $"));
rb_str_new2("$originalId: cparse.c,v 1.6 2006/07/02 09:34:14 aamine Exp $"));
CparseParams = rb_define_class_under(Racc, "CparseParams", rb_cObject);
@ -782,9 +775,7 @@ Init_cparse()
id_nexttoken = rb_intern("next_token");
id_onerror = rb_intern("on_error");
id_noreduce = rb_intern("_reduce_none");
id_catch = rb_intern("catch");
id_errstatus = rb_intern("@racc_error_status");
sym_raccjump = id_to_value(rb_intern("racc_jump"));
id_d_shift = rb_intern("racc_shift");
id_d_reduce = rb_intern("racc_reduce");