* parse.y (rb_parser_malloc, rb_parser_free): manage parser stack on
heap. [ruby-list:41199] * parse.y (ripper_initialize): use rb_respond_to(). * ext/ripper/depend (check): get rid of re-generating ripper.y always. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9356 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1022702acf
commit
04bdcf8432
@ -1,3 +1,12 @@
|
|||||||
|
Sat Oct 8 18:57:52 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* parse.y (rb_parser_malloc, rb_parser_free): manage parser stack on
|
||||||
|
heap. [ruby-list:41199]
|
||||||
|
|
||||||
|
* parse.y (ripper_initialize): use rb_respond_to().
|
||||||
|
|
||||||
|
* ext/ripper/depend (check): get rid of re-generating ripper.y always.
|
||||||
|
|
||||||
Thu Oct 6 20:10:38 2005 Minero Aoki <aamine@loveruby.net>
|
Thu Oct 6 20:10:38 2005 Minero Aoki <aamine@loveruby.net>
|
||||||
|
|
||||||
* ext/strscan/strscan.c (strscan_free): remove useless code.
|
* ext/strscan/strscan.c (strscan_free): remove useless code.
|
||||||
|
@ -1,15 +1,18 @@
|
|||||||
GEN = $(srcdir)/tools/generate.rb
|
GEN = $(srcdir)/tools/generate.rb
|
||||||
SRC1 = $(hdrdir)/parse.y
|
SRC1 = $(hdrdir)/parse.y
|
||||||
SRC2 = $(srcdir)/eventids2.c
|
SRC2 = $(srcdir)/eventids2.c
|
||||||
|
BISON = bison
|
||||||
|
|
||||||
src: ripper.c eventids1.c eventids2table.c
|
src: ripper.c eventids1.c eventids2table.c
|
||||||
|
|
||||||
ripper.o: ripper.c $(hdrdir)/lex.c eventids1.c $(srcdir)/eventids2.c eventids2table.c
|
ripper.o: ripper.c $(hdrdir)/lex.c eventids1.c $(srcdir)/eventids2.c eventids2table.c
|
||||||
|
|
||||||
.y.c:
|
.y.c:
|
||||||
bison -t -v -o$@ $<
|
$(BISON) -t -v -o$@ $<
|
||||||
|
|
||||||
ripper.y: check $(srcdir)/tools/preproc.rb $(hdrdir)/parse.y
|
all static: check
|
||||||
|
|
||||||
|
ripper.y: $(srcdir)/tools/preproc.rb $(hdrdir)/parse.y
|
||||||
$(RUBY) $(srcdir)/tools/preproc.rb $(hdrdir)/parse.y --output=$@
|
$(RUBY) $(srcdir)/tools/preproc.rb $(hdrdir)/parse.y --output=$@
|
||||||
|
|
||||||
check: $(GEN) $(SRC1) $(SRC2)
|
check: $(GEN) $(SRC1) $(SRC2)
|
||||||
|
4
gc.c
4
gc.c
@ -859,13 +859,11 @@ gc_mark_children(VALUE ptr, int lev)
|
|||||||
case NODE_BLOCK_ARG:
|
case NODE_BLOCK_ARG:
|
||||||
case NODE_POSTEXE:
|
case NODE_POSTEXE:
|
||||||
break;
|
break;
|
||||||
#ifdef C_ALLOCA
|
|
||||||
case NODE_ALLOCA:
|
case NODE_ALLOCA:
|
||||||
mark_locations_array((VALUE*)obj->as.node.u1.value,
|
mark_locations_array((VALUE*)obj->as.node.u1.value,
|
||||||
obj->as.node.u3.cnt);
|
obj->as.node.u3.cnt);
|
||||||
ptr = (VALUE)obj->as.node.u2.node;
|
ptr = (VALUE)obj->as.node.u2.node;
|
||||||
goto again;
|
goto again;
|
||||||
#endif
|
|
||||||
|
|
||||||
default: /* unlisted NODE */
|
default: /* unlisted NODE */
|
||||||
if (is_pointer_to_heap(obj->as.node.u1.node)) {
|
if (is_pointer_to_heap(obj->as.node.u1.node)) {
|
||||||
@ -1192,11 +1190,9 @@ obj_free(VALUE obj)
|
|||||||
RUBY_CRITICAL(free(RANY(obj)->as.node.u1.tbl));
|
RUBY_CRITICAL(free(RANY(obj)->as.node.u1.tbl));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#ifdef C_ALLOCA
|
|
||||||
case NODE_ALLOCA:
|
case NODE_ALLOCA:
|
||||||
RUBY_CRITICAL(free(RANY(obj)->as.node.u1.node));
|
RUBY_CRITICAL(free(RANY(obj)->as.node.u1.node));
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
return; /* no need to free iv_tbl */
|
return; /* no need to free iv_tbl */
|
||||||
|
|
||||||
|
2
node.h
2
node.h
@ -116,9 +116,7 @@ enum node_type {
|
|||||||
NODE_ERRINFO,
|
NODE_ERRINFO,
|
||||||
NODE_DEFINED,
|
NODE_DEFINED,
|
||||||
NODE_POSTEXE,
|
NODE_POSTEXE,
|
||||||
#ifdef C_ALLOCA
|
|
||||||
NODE_ALLOCA,
|
NODE_ALLOCA,
|
||||||
#endif
|
|
||||||
NODE_BMETHOD,
|
NODE_BMETHOD,
|
||||||
NODE_MEMO,
|
NODE_MEMO,
|
||||||
NODE_IFUNC,
|
NODE_IFUNC,
|
||||||
|
99
parse.y
99
parse.y
@ -13,6 +13,8 @@
|
|||||||
%{
|
%{
|
||||||
|
|
||||||
#define YYDEBUG 1
|
#define YYDEBUG 1
|
||||||
|
#define YYERROR_VERBOSE 1
|
||||||
|
#define YYSTACK_USE_ALLOCA 0
|
||||||
|
|
||||||
#include "ruby.h"
|
#include "ruby.h"
|
||||||
#include "env.h"
|
#include "env.h"
|
||||||
@ -23,6 +25,15 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#define YYMALLOC(size) rb_parser_malloc(parser, size)
|
||||||
|
#define YYREALLOC(ptr, size) rb_parser_realloc(parser, ptr, size)
|
||||||
|
#define YYCALLOC(nelem, size) rb_parser_calloc(parser, nelem, size)
|
||||||
|
#define YYFREE(ptr) rb_parser_free(parser, ptr)
|
||||||
|
#define malloc YYMALLOC
|
||||||
|
#define realloc YYREALLOC
|
||||||
|
#define calloc YYCALLOC
|
||||||
|
#define free YYFREE
|
||||||
|
|
||||||
#define ID_SCOPE_SHIFT 3
|
#define ID_SCOPE_SHIFT 3
|
||||||
#define ID_SCOPE_MASK 0x07
|
#define ID_SCOPE_MASK 0x07
|
||||||
#define ID_LOCAL 0x01
|
#define ID_LOCAL 0x01
|
||||||
@ -168,8 +179,19 @@ struct parser_params {
|
|||||||
#endif
|
#endif
|
||||||
int line_count;
|
int line_count;
|
||||||
int has_shebang;
|
int has_shebang;
|
||||||
|
|
||||||
|
#ifdef YYMALLOC
|
||||||
|
NODE *heap;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef YYMALLOC
|
||||||
|
void *rb_parser_malloc(struct parser_params *, size_t);
|
||||||
|
void *rb_parser_realloc(struct parser_params *, void *, size_t);
|
||||||
|
void *rb_parser_calloc(struct parser_params *, size_t, size_t);
|
||||||
|
void rb_parser_free(struct parser_params *, void *);
|
||||||
|
#endif
|
||||||
|
|
||||||
static int parser_yyerror(struct parser_params*, const char*);
|
static int parser_yyerror(struct parser_params*, const char*);
|
||||||
#define yyerror(msg) parser_yyerror(parser, msg)
|
#define yyerror(msg) parser_yyerror(parser, msg)
|
||||||
|
|
||||||
@ -2487,11 +2509,10 @@ primary : literal
|
|||||||
}
|
}
|
||||||
| tLPAREN_ARG expr {lex_state = EXPR_ENDARG;} rparen
|
| tLPAREN_ARG expr {lex_state = EXPR_ENDARG;} rparen
|
||||||
{
|
{
|
||||||
|
rb_warning0("(...) interpreted as grouped expression");
|
||||||
/*%%%*/
|
/*%%%*/
|
||||||
rb_warning("(...) interpreted as grouped expression");
|
|
||||||
$$ = $2;
|
$$ = $2;
|
||||||
/*%
|
/*%
|
||||||
rb_warning0("(...) interpreted as grouped expression");
|
|
||||||
$$ = dispatch1(paren, $2);
|
$$ = dispatch1(paren, $2);
|
||||||
%*/
|
%*/
|
||||||
}
|
}
|
||||||
@ -8538,6 +8559,9 @@ parser_initialize(struct parser_params *parser)
|
|||||||
parser->parsing_thread = Qnil;
|
parser->parsing_thread = Qnil;
|
||||||
parser->toplevel_p = Qtrue;
|
parser->toplevel_p = Qtrue;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef YYMALLOC
|
||||||
|
parser->heap = NULL;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -8558,6 +8582,9 @@ parser_mark(void *ptr)
|
|||||||
rb_gc_mark(p->result);
|
rb_gc_mark(p->result);
|
||||||
rb_gc_mark(p->parsing_thread);
|
rb_gc_mark(p->parsing_thread);
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef YYMALLOC
|
||||||
|
rb_gc_mark((VALUE)p->heap);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -8613,6 +8640,63 @@ rb_parser_end_seen_p(VALUE vparser)
|
|||||||
Data_Get_Struct(vparser, struct parser_params, parser);
|
Data_Get_Struct(vparser, struct parser_params, parser);
|
||||||
return ruby__end__seen ? Qtrue : Qfalse;
|
return ruby__end__seen ? Qtrue : Qfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef YYMALLOC
|
||||||
|
#define HEAPCNT(n, size) ((size) % sizeof(YYSTYPE) ? 0 : (n) * (size) / sizeof(YYSTYPE))
|
||||||
|
#define NEWHEAP(cnt) rb_node_newnode(NODE_ALLOCA, 0, (VALUE)parserp->heap, cnt)
|
||||||
|
#define ADD2HEAP(n, ptr) ((parserp->heap = (n))->u1.node = (ptr))
|
||||||
|
|
||||||
|
void *
|
||||||
|
rb_parser_malloc(struct parser_params *parserp, size_t size)
|
||||||
|
{
|
||||||
|
NODE *n = NEWHEAP(HEAPCNT(1, size));
|
||||||
|
|
||||||
|
return ADD2HEAP(n, xmalloc(size));
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
rb_parser_calloc(struct parser_params *parserp, size_t nelem, size_t size)
|
||||||
|
{
|
||||||
|
NODE *n = NEWHEAP(HEAPCNT(nelem, size));
|
||||||
|
|
||||||
|
return ADD2HEAP(n, xcalloc(nelem, size));
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
rb_parser_realloc(struct parser_params *parserp, void *ptr, size_t size)
|
||||||
|
{
|
||||||
|
NODE *n;
|
||||||
|
size_t cnt = HEAPCNT(1, size);
|
||||||
|
|
||||||
|
if (ptr && (n = parserp->heap) != NULL) {
|
||||||
|
do {
|
||||||
|
if (n->u1.node == ptr) {
|
||||||
|
n->u1.node = ptr = xrealloc(ptr, size);
|
||||||
|
if (n->u3.cnt) n->u3.cnt = cnt;
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
} while ((n = n->u2.node) != NULL);
|
||||||
|
}
|
||||||
|
n = NEWHEAP(cnt);
|
||||||
|
return ADD2HEAP(n, xrealloc(ptr, size));
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
rb_parser_free(struct parser_params *parserp, void *ptr)
|
||||||
|
{
|
||||||
|
NODE **prev = &parserp->heap, *n;
|
||||||
|
|
||||||
|
while (n = *prev) {
|
||||||
|
if (n->u1.node == ptr) {
|
||||||
|
*prev = n->u2.node;
|
||||||
|
rb_gc_force_recycle((VALUE)n);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
prev = &n->u2.node;
|
||||||
|
}
|
||||||
|
xfree(ptr);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef RIPPER
|
#ifdef RIPPER
|
||||||
@ -8869,15 +8953,6 @@ ripper_s_allocate(VALUE klass)
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
obj_respond_to(VALUE obj, VALUE mid)
|
|
||||||
{
|
|
||||||
VALUE st;
|
|
||||||
|
|
||||||
st = rb_funcall(obj, rb_intern("respond_to?"), 2, mid, Qfalse);
|
|
||||||
return RTEST(st);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define ripper_initialized_p(r) ((r)->parser_lex_input != 0)
|
#define ripper_initialized_p(r) ((r)->parser_lex_input != 0)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -8898,7 +8973,7 @@ ripper_initialize(int argc, VALUE *argv, VALUE self)
|
|||||||
|
|
||||||
Data_Get_Struct(self, struct parser_params, parser);
|
Data_Get_Struct(self, struct parser_params, parser);
|
||||||
rb_scan_args(argc, argv, "12", &src, &fname, &lineno);
|
rb_scan_args(argc, argv, "12", &src, &fname, &lineno);
|
||||||
if (obj_respond_to(src, ID2SYM(ripper_id_gets))) {
|
if (rb_respond_to(src, ripper_id_gets)) {
|
||||||
parser->parser_lex_gets = ripper_lex_get_generic;
|
parser->parser_lex_gets = ripper_lex_get_generic;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user