diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-10-08 09:58:25 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-10-08 09:58:25 +0000 |
commit | 04bdcf84328eec8e144b3b9e0a1ee4407d71d594 (patch) | |
tree | 4ca2af8aef6783ba5232d3a920cc7225d0a63404 | |
parent | 1022702acf4f25b0d6e11ce5ad6743fbde59bb25 (diff) | |
download | ruby-04bdcf84328eec8e144b3b9e0a1ee4407d71d594.tar.gz |
* 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
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | ext/ripper/depend | 7 | ||||
-rw-r--r-- | gc.c | 4 | ||||
-rw-r--r-- | node.h | 2 | ||||
-rw-r--r-- | parse.y | 99 |
5 files changed, 101 insertions, 20 deletions
@@ -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> * ext/strscan/strscan.c (strscan_free): remove useless code. diff --git a/ext/ripper/depend b/ext/ripper/depend index c47f210186..4f5c822308 100644 --- a/ext/ripper/depend +++ b/ext/ripper/depend @@ -1,15 +1,18 @@ GEN = $(srcdir)/tools/generate.rb SRC1 = $(hdrdir)/parse.y SRC2 = $(srcdir)/eventids2.c +BISON = bison src: ripper.c eventids1.c eventids2table.c ripper.o: ripper.c $(hdrdir)/lex.c eventids1.c $(srcdir)/eventids2.c eventids2table.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=$@ check: $(GEN) $(SRC1) $(SRC2) @@ -859,13 +859,11 @@ gc_mark_children(VALUE ptr, int lev) case NODE_BLOCK_ARG: case NODE_POSTEXE: break; -#ifdef C_ALLOCA case NODE_ALLOCA: mark_locations_array((VALUE*)obj->as.node.u1.value, obj->as.node.u3.cnt); ptr = (VALUE)obj->as.node.u2.node; goto again; -#endif default: /* unlisted 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)); } break; -#ifdef C_ALLOCA case NODE_ALLOCA: RUBY_CRITICAL(free(RANY(obj)->as.node.u1.node)); break; -#endif } return; /* no need to free iv_tbl */ @@ -116,9 +116,7 @@ enum node_type { NODE_ERRINFO, NODE_DEFINED, NODE_POSTEXE, -#ifdef C_ALLOCA NODE_ALLOCA, -#endif NODE_BMETHOD, NODE_MEMO, NODE_IFUNC, @@ -13,6 +13,8 @@ %{ #define YYDEBUG 1 +#define YYERROR_VERBOSE 1 +#define YYSTACK_USE_ALLOCA 0 #include "ruby.h" #include "env.h" @@ -23,6 +25,15 @@ #include <errno.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_MASK 0x07 #define ID_LOCAL 0x01 @@ -168,8 +179,19 @@ struct parser_params { #endif int line_count; 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*); #define yyerror(msg) parser_yyerror(parser, msg) @@ -2487,11 +2509,10 @@ primary : literal } | tLPAREN_ARG expr {lex_state = EXPR_ENDARG;} rparen { + rb_warning0("(...) interpreted as grouped expression"); /*%%%*/ - rb_warning("(...) interpreted as grouped expression"); $$ = $2; /*% - rb_warning0("(...) interpreted as grouped expression"); $$ = dispatch1(paren, $2); %*/ } @@ -8538,6 +8559,9 @@ parser_initialize(struct parser_params *parser) parser->parsing_thread = Qnil; parser->toplevel_p = Qtrue; #endif +#ifdef YYMALLOC + parser->heap = NULL; +#endif } static void @@ -8558,6 +8582,9 @@ parser_mark(void *ptr) rb_gc_mark(p->result); rb_gc_mark(p->parsing_thread); #endif +#ifdef YYMALLOC + rb_gc_mark((VALUE)p->heap); +#endif } static void @@ -8613,6 +8640,63 @@ rb_parser_end_seen_p(VALUE vparser) Data_Get_Struct(vparser, struct parser_params, parser); 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 #ifdef RIPPER @@ -8869,15 +8953,6 @@ ripper_s_allocate(VALUE klass) 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) /* @@ -8898,7 +8973,7 @@ ripper_initialize(int argc, VALUE *argv, VALUE self) Data_Get_Struct(self, struct parser_params, parser); 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; } else { |