diff --git a/ChangeLog b/ChangeLog index b7e55f5ca0..2607bc1037 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +Sat Apr 12 12:41:49 2008 Nobuyoshi Nakada + + * eval.c (ruby_exec_node, ruby_run_node), ruby.c (process_options): + use iseq instead of NODE. + + * gc.c (source_filenames): removed. + + * include/ruby/intern.h, parse.y (yycompile, parser_mark, parser_free, + ripper_initialize): rb_source_filename() is no longer used. + + * compile.c, compile.h (ERROR_ARGS), parse.y (node_newnode, fixpos, + parser_warn, e_option_supplied, warn_unless_e_option, range_op, + cond0): nd_file is no longer used. + Sat Apr 12 05:55:57 2008 Eric Hodel * lib/rubygems*, test/rubygems*: Update to RubyGems 1.1.1 r1701. diff --git a/compile.c b/compile.c index ea76aa1e5c..5966c2aa73 100644 --- a/compile.c +++ b/compile.c @@ -132,6 +132,8 @@ iseq_add_mark_object(rb_iseq_t *iseq, VALUE v) return COMPILE_OK; } +#define ruby_sourcefile RSTRING_PTR(iseq->filename) + static int iseq_add_mark_object_compile_time(rb_iseq_t *iseq, VALUE v) { diff --git a/compile.h b/compile.h index f2e0cae5b9..94ceb3d577 100644 --- a/compile.h +++ b/compile.h @@ -210,7 +210,7 @@ r_value(VALUE value) break; \ } -#define ERROR_ARGS (node)->nd_file, nd_line(node), +#define ERROR_ARGS ruby_sourcefile, nd_line(node), #define COMPILE_OK 1 diff --git a/eval.c b/eval.c index f3a0806654..ab2c33dbcb 100644 --- a/eval.c +++ b/eval.c @@ -214,22 +214,19 @@ ruby_cleanup(int ex) } int -ruby_exec_node(void *n, char *file) +ruby_exec_node(void *n, const char *file) { int state; - VALUE val; - NODE *node = n; + VALUE iseq = (VALUE)n; rb_thread_t *th = GET_THREAD(); - if (!node) return 0; + if (!n) return 0; PUSH_TAG(); if ((state = EXEC_TAG()) == 0) { - VALUE iseq = rb_iseq_new(n, rb_str_new2("
"), - rb_str_new2(file), Qfalse, ISEQ_TYPE_TOP); SAVE_ROOT_JMPBUF(th, { th->base_block = 0; - val = rb_iseq_eval(iseq); + rb_iseq_eval(iseq); }); } POP_TAG(); @@ -245,17 +242,17 @@ ruby_stop(int ex) int ruby_run_node(void *n) { - NODE *node = (NODE *)n; + VALUE v = (VALUE)n; - switch ((VALUE)n) { + switch (v) { case Qtrue: return EXIT_SUCCESS; case Qfalse: return EXIT_FAILURE; } - if (FIXNUM_P((VALUE)n)) { - return FIX2INT((VALUE)n); + if (FIXNUM_P(v)) { + return FIX2INT(v); } Init_stack((void *)&n); - return ruby_cleanup(ruby_exec_node(node, node->nd_file)); + return ruby_cleanup(ruby_exec_node(n, 0)); } VALUE diff --git a/gc.c b/gc.c index e090b0db49..eefa9d6f7d 100644 --- a/gc.c +++ b/gc.c @@ -665,47 +665,6 @@ init_mark_stack(void) #define MARK_STACK_EMPTY (mark_stack_ptr == mark_stack) -static st_table *source_filenames; - -char * -rb_source_filename(const char *f) -{ - st_data_t name; - - if (!st_lookup(source_filenames, (st_data_t)f, &name)) { - long len = strlen(f) + 1; - char *ptr = ALLOC_N(char, len + 1); - - name = (st_data_t)ptr; - *ptr++ = 0; - MEMCPY(ptr, f, char, len); - st_add_direct(source_filenames, (st_data_t)ptr, name); - return ptr; - } - return (char *)name + 1; -} - -void -rb_mark_source_filename(char *f) -{ - if (f) { - f[-1] = 1; - } -} - -static int -sweep_source_filename(char *key, char *value) -{ - if (*value) { - *value = 0; - return ST_CONTINUE; - } - else { - free(value); - return ST_DELETE; - } -} - static void gc_mark(VALUE ptr, int lev); static void gc_mark_children(VALUE ptr, int lev); @@ -924,7 +883,6 @@ gc_mark_children(VALUE ptr, int lev) break; case T_NODE: - rb_mark_source_filename(obj->as.node.nd_file); switch (nd_type(obj)) { case NODE_IF: /* 1,2,3 */ case NODE_FOR: @@ -1221,10 +1179,6 @@ gc_sweep(void) if (free_min < FREE_MIN) free_min = FREE_MIN; - if (source_filenames) { - st_foreach(source_filenames, sweep_source_filename, 0); - } - freelist = 0; final_list = deferred_final_list; deferred_final_list = 0; @@ -2335,8 +2289,6 @@ Init_GC(void) rb_gc_unregister_address(&rb_mObSpace); finalizers = rb_ary_new(); - source_filenames = st_init_strtable(); - rb_global_variable(&nomem_error); nomem_error = rb_exc_new2(rb_eNoMemError, "failed to allocate memory"); diff --git a/include/ruby/intern.h b/include/ruby/intern.h index 01ea5285bb..57305fd1dc 100644 --- a/include/ruby/intern.h +++ b/include/ruby/intern.h @@ -325,7 +325,6 @@ void ruby_set_stack_size(size_t); NORETURN(void rb_memerror(void)); int ruby_stack_check(void); int ruby_stack_length(VALUE**); -char *rb_source_filename(const char*); void rb_gc_mark_locations(VALUE*, VALUE*); void rb_mark_tbl(struct st_table*); void rb_mark_set(struct st_table*); diff --git a/parse.y b/parse.y index 8181c5c40a..657eafbad4 100644 --- a/parse.y +++ b/parse.y @@ -4738,7 +4738,7 @@ yycompile0(VALUE arg, int tracing) static NODE* yycompile(struct parser_params *parser, const char *f, int line) { - ruby_sourcefile = rb_source_filename(f); + ruby_sourcefile = ruby_strdup(f); ruby_sourceline = line - 1; return (NODE *)ruby_suppress_tracing(yycompile0, (VALUE)parser, Qtrue); } @@ -7316,7 +7316,6 @@ node_newnode(struct parser_params *parser, enum node_type type, VALUE a0, VALUE { NODE *n = (rb_node_newnode)(type, a0, a1, a2); nd_set_line(n, ruby_sourceline); - n->nd_file = ruby_sourcefile; return n; } @@ -7348,21 +7347,22 @@ fixpos(NODE *node, NODE *orig) if (!node) return; if (!orig) return; if (orig == (NODE*)1) return; - node->nd_file = orig->nd_file; nd_set_line(node, nd_line(orig)); } static void -parser_warning(NODE *node, const char *mesg) +parser_warning(struct parser_params *parser, NODE *node, const char *mesg) { - rb_compile_warning(node->nd_file, nd_line(node), "%s", mesg); + rb_compile_warning(ruby_sourcefile, nd_line(node), "%s", mesg); } +#define parser_warning(node, mesg) parser_warning(parser, node, mesg) static void -parser_warn(NODE *node, const char *mesg) +parser_warn(struct parser_params *parser, NODE *node, const char *mesg) { - rb_compile_warn(node->nd_file, nd_line(node), "%s", mesg); + rb_compile_warn(ruby_sourcefile, nd_line(node), "%s", mesg); } +#define parser_warn(node, mesg) parser_warn(parser, node, mesg) static NODE* block_append_gen(struct parser_params *parser, NODE *head, NODE *tail) @@ -8144,23 +8144,23 @@ assign_in_cond(struct parser_params *parser, NODE *node) } static int -e_option_supplied(NODE *node) +e_option_supplied(struct parser_params *parser) { - if (strcmp(node->nd_file, "-e") == 0) + if (strcmp(ruby_sourcefile, "-e") == 0) return Qtrue; return Qfalse; } static void -warn_unless_e_option(NODE *node, const char *str) +warn_unless_e_option(struct parser_params *parser, NODE *node, const char *str) { - if (!e_option_supplied(node)) parser_warn(node, str); + if (!e_option_supplied(parser)) parser_warn(node, str); } static void -warning_unless_e_option(NODE *node, const char *str) +warning_unless_e_option(struct parser_params *parser, NODE *node, const char *str) { - if (!e_option_supplied(node)) parser_warning(node, str); + if (!e_option_supplied(parser)) parser_warning(node, str); } static NODE *cond0(struct parser_params*,NODE*); @@ -8170,14 +8170,14 @@ range_op(struct parser_params *parser, NODE *node) { enum node_type type; - if (!e_option_supplied(node)) return node; + if (!e_option_supplied(parser)) return node; if (node == 0) return 0; value_expr(node); node = cond0(parser, node); type = nd_type(node); if (type == NODE_LIT && FIXNUM_P(node->nd_lit)) { - warn_unless_e_option(node, "integer literal in conditional range"); + warn_unless_e_option(parser, node, "integer literal in conditional range"); return NEW_CALL(node, tEQ, NEW_LIST(NEW_GVAR(rb_intern("$.")))); } return node; @@ -8219,7 +8219,7 @@ cond0(struct parser_params *parser, NODE *node) case NODE_DREGX: case NODE_DREGX_ONCE: - warning_unless_e_option(node, "regex literal in condition"); + warning_unless_e_option(parser, node, "regex literal in condition"); return NEW_MATCH2(node, NEW_GVAR(rb_intern("$_"))); case NODE_AND: @@ -8234,7 +8234,7 @@ cond0(struct parser_params *parser, NODE *node) node->nd_end = range_op(parser, node->nd_end); if (nd_type(node) == NODE_DOT2) nd_set_type(node,NODE_FLIP2); else if (nd_type(node) == NODE_DOT3) nd_set_type(node, NODE_FLIP3); - if (!e_option_supplied(node)) { + if (!e_option_supplied(parser)) { int b = literal_node(node->nd_beg); int e = literal_node(node->nd_end); if ((b == 1 && e == 1) || (b + e >= 2 && RTEST(ruby_verbose))) { @@ -8249,7 +8249,7 @@ cond0(struct parser_params *parser, NODE *node) case NODE_LIT: if (TYPE(node->nd_lit) == T_REGEXP) { - warn_unless_e_option(node, "regex literal in condition"); + warn_unless_e_option(parser, node, "regex literal in condition"); nd_set_type(node, NODE_MATCH); } else { @@ -9311,8 +9311,6 @@ parser_initialize(struct parser_params *parser) parser->enc = rb_usascii_encoding(); } -extern void rb_mark_source_filename(char *); - #ifdef RIPPER #define parser_mark ripper_parser_mark #define parser_free ripper_parser_free @@ -9331,7 +9329,6 @@ parser_mark(void *ptr) rb_gc_mark((VALUE)p->parser_eval_tree_begin) ; rb_gc_mark((VALUE)p->parser_eval_tree) ; rb_gc_mark(p->debug_lines); - rb_mark_source_filename(p->parser_ruby_sourcefile); #else rb_gc_mark(p->parser_ruby_sourcefile_string); rb_gc_mark(p->delayed); @@ -9358,6 +9355,9 @@ parser_free(void *ptr) prev = local->prev; xfree(local); } +#ifndef RIPPER + xfree(p->parser_ruby_sourcefile); +#endif xfree(p); } @@ -9784,7 +9784,6 @@ ripper_initialize(int argc, VALUE *argv, VALUE self) { struct parser_params *parser; VALUE src, fname, lineno; - VALUE fname2; Data_Get_Struct(self, struct parser_params, parser); rb_scan_args(argc, argv, "12", &src, &fname, &lineno); @@ -9798,17 +9797,15 @@ ripper_initialize(int argc, VALUE *argv, VALUE self) parser->parser_lex_input = src; parser->eofp = Qfalse; if (NIL_P(fname)) { - fname2 = STR_NEW2(" (ripper)"); + fname = STR_NEW2("(ripper)"); } else { StringValue(fname); - fname2 = rb_usascii_str_new2(" "); - rb_str_append(fname2, fname); } parser_initialize(parser); - parser->parser_ruby_sourcefile_string = fname2; - parser->parser_ruby_sourcefile = RSTRING_PTR(fname2)+1; + parser->parser_ruby_sourcefile_string = fname; + parser->parser_ruby_sourcefile = RSTRING_PTR(fname); parser->parser_ruby_sourceline = NIL_P(lineno) ? 0 : NUM2INT(lineno) - 1; return Qnil; diff --git a/ruby.c b/ruby.c index 075c3d057a..4890d94b01 100644 --- a/ruby.c +++ b/ruby.c @@ -1103,16 +1103,15 @@ process_options(VALUE arg) return Qtrue; } - if (tree) { - if (opt->do_print) { - tree = rb_parser_append_print(parser, tree); - } - if (opt->do_loop) { - tree = rb_parser_while_loop(parser, tree, opt->do_line, opt->do_split); - } + if (opt->do_print) { + tree = rb_parser_append_print(parser, tree); + } + if (opt->do_loop) { + tree = rb_parser_while_loop(parser, tree, opt->do_line, opt->do_split); } - return (VALUE)tree; + return rb_iseq_new(tree, rb_str_new2("
"), + rb_str_new2(opt->script), Qfalse, ISEQ_TYPE_TOP); } static NODE *