2006-12-31 10:02:22 -05:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
compile.h -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
created at: 04/01/01 23:36:57 JST
|
|
|
|
|
* blockinlining.c, compile.c, compile.h, debug.c, debug.h,
id.c, insnhelper.h, insns.def, thread.c, thread_pthread.ci,
thread_pthread.h, thread_win32.ci, thread_win32.h, vm.h,
vm_dump.c, vm_evalbody.ci, vm_opts.h: fix comments and
copyright year.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13920 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-11-13 17:13:04 -05:00
|
|
|
Copyright (C) 2004-2007 Koichi Sasada
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
2007-04-05 04:58:46 -04:00
|
|
|
#ifndef RUBY_COMPILE_H
|
|
|
|
#define RUBY_COMPILE_H
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
/* */
|
|
|
|
/**
|
|
|
|
* debug function(macro) interface depend on CPDEBUG
|
2008-04-14 01:34:04 -04:00
|
|
|
* if it is less than 0, runtime option is in effect.
|
2006-12-31 10:02:22 -05:00
|
|
|
*
|
|
|
|
* debug level:
|
|
|
|
* 0: no debug output
|
|
|
|
* 1: show node type
|
|
|
|
* 2: show node important parameters
|
|
|
|
* ...
|
|
|
|
* 5: show other parameters
|
|
|
|
* 10: show every AST array
|
|
|
|
*/
|
|
|
|
|
* blockinlining.c: remove "yarv" prefix.
* array.c, numeric.c: ditto.
* insnhelper.ci, insns.def, vm_evalbody.ci: ditto.
* yarvcore.c: removed.
* yarvcore.h: renamed to core.h.
* cont.c, debug.c, error.c, process.c, signal.c : ditto.
* ext/probeprofiler/probeprofiler.c: ditto.
* id.c, id.h: added.
* inits.c: ditto.
* compile.c: rename internal functions.
* compile.h: fix debug flag.
* eval.c, object.c, vm.c: remove ruby_top_self.
use rb_vm_top_self() instead.
* eval_intern.h, eval_load: ditto.
* gc.c: rename yarv_machine_stack_mark() to
rb_gc_mark_machine_stack().
* insnhelper.h: remove unused macros.
* iseq.c: add iseq_compile() to create iseq object
from source string.
* proc.c: rename a internal function.
* template/insns.inc.tmpl: remove YARV prefix.
* thread.c:
* vm.c (rb_iseq_eval): added.
* vm.c: move some functions from yarvcore.c.
* vm_dump.c: fix to remove compiler warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-12 00:25:46 -04:00
|
|
|
#ifndef CPDEBUG
|
|
|
|
#define CPDEBUG 0
|
|
|
|
#endif
|
|
|
|
|
2008-04-14 01:34:04 -04:00
|
|
|
#if CPDEBUG >= 0
|
|
|
|
#define compile_debug CPDEBUG
|
|
|
|
#else
|
|
|
|
#define compile_debug iseq->compile_data->option->debug_level
|
2006-12-31 10:02:22 -05:00
|
|
|
#endif
|
|
|
|
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 04:12:18 -04:00
|
|
|
NORETURN(PRINTF_ARGS(void rb_compile_bug(const char*, int, const char*, ...), 3, 4));
|
|
|
|
|
2008-04-14 01:34:04 -04:00
|
|
|
#if CPDEBUG
|
|
|
|
|
|
|
|
#define compile_debug_print_indent(level) \
|
|
|
|
ruby_debug_print_indent(level, compile_debug, gl_node_level * 2)
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2008-04-14 01:34:04 -04:00
|
|
|
#define debugp(header, value) (void) \
|
|
|
|
(compile_debug_print_indent(1) && \
|
|
|
|
ruby_debug_print_value(1, compile_debug, header, value))
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2008-04-14 01:34:04 -04:00
|
|
|
#define debugi(header, id) (void) \
|
|
|
|
(compile_debug_print_indent(1) && \
|
|
|
|
ruby_debug_print_id(1, compile_debug, header, id))
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2008-04-14 01:34:04 -04:00
|
|
|
#define debugp_param(header, value) (void) \
|
|
|
|
(compile_debug_print_indent(1) && \
|
|
|
|
ruby_debug_print_value(1, compile_debug, header, value))
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2008-04-14 01:34:04 -04:00
|
|
|
#define debugp_verbose(header, value) (void) \
|
|
|
|
(compile_debug_print_indent(2) && \
|
|
|
|
ruby_debug_print_value(2, compile_debug, header, value))
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2008-04-14 01:34:04 -04:00
|
|
|
#define debugp_verbose_node(header, value) (void) \
|
|
|
|
(compile_debug_print_indent(10) && \
|
|
|
|
ruby_debug_print_value(10, compile_debug, header, value))
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2008-04-14 01:34:04 -04:00
|
|
|
#define debug_node_start(node) ((void) \
|
|
|
|
(compile_debug_print_indent(1) && \
|
|
|
|
(ruby_debug_print_node(1, CPDEBUG, "", (NODE *)node), gl_node_level)), \
|
|
|
|
gl_node_level++)
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2007-06-24 13:19:22 -04:00
|
|
|
#define debug_node_end() gl_node_level --;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
static inline ID
|
|
|
|
r_id(ID id)
|
|
|
|
{
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline VALUE
|
|
|
|
r_value(VALUE value)
|
|
|
|
{
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define debugi(header, id) r_id(id)
|
|
|
|
#define debugp(header, value) r_value(value)
|
|
|
|
#define debugp_verbose(header, value) r_value(value)
|
|
|
|
#define debugp_verbose_node(header, value) r_value(value)
|
|
|
|
#define debugp_param(header, value) r_value(value)
|
2008-04-14 01:34:04 -04:00
|
|
|
#define debug_node_start(node) ((void)0)
|
|
|
|
#define debug_node_end() ((void)0)
|
2006-12-31 10:02:22 -05:00
|
|
|
#endif
|
|
|
|
|
2008-04-14 01:34:04 -04:00
|
|
|
#if CPDEBUG > 1 || CPDEBUG < 0
|
|
|
|
PRINTF_ARGS(void ruby_debug_printf(const char*, ...), 1, 2);
|
|
|
|
#define debugs if (compile_debug_print_indent(1)) ruby_debug_printf
|
|
|
|
#define debug_compile(msg, v) ((void)(compile_debug_print_indent(1) && fputs(msg, stderr)), (v))
|
2006-12-31 10:02:22 -05:00
|
|
|
#else
|
|
|
|
#define debugs if(0)printf
|
|
|
|
#define debug_compile(msg, v) (v)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* create new label */
|
|
|
|
#define NEW_LABEL(l) new_label_body(iseq, l)
|
|
|
|
|
|
|
|
#define iseq_filename(iseq) \
|
2007-02-24 20:34:33 -05:00
|
|
|
(((rb_iseq_t*)DATA_PTR(iseq))->filename)
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
#define NEW_ISEQVAL(node, name, type) \
|
|
|
|
new_child_iseq(iseq, node, name, 0, type)
|
|
|
|
|
|
|
|
#define NEW_CHILD_ISEQVAL(node, name, type) \
|
|
|
|
new_child_iseq(iseq, node, name, iseq->self, type)
|
|
|
|
|
|
|
|
#define NEW_SPECIAQL_BLOCK_ISEQVAL(iseq, sym) \
|
|
|
|
new_child_iseq(iseq, iseq->node, iseq->name, iseq->parent_iseq, iseq->type, sym)
|
|
|
|
|
|
|
|
/* add instructions */
|
|
|
|
#define ADD_SEQ(seq1, seq2) \
|
|
|
|
APPEND_LIST(seq1, seq2)
|
|
|
|
|
|
|
|
/* add an instruction */
|
|
|
|
#define ADD_INSN(seq, line, insn) \
|
|
|
|
ADD_ELEM(seq, (LINK_ELEMENT *) new_insn_body(iseq, line, BIN(insn), 0))
|
|
|
|
|
|
|
|
/* add an instruction with label operand */
|
|
|
|
#define ADD_INSNL(seq, line, insn, label) \
|
|
|
|
ADD_ELEM(seq, (LINK_ELEMENT *) \
|
|
|
|
new_insn_body(iseq, line, BIN(insn), 1, (VALUE)label))
|
|
|
|
|
|
|
|
/* add an instruction with some operands (1, 2, 3, 5) */
|
|
|
|
#define ADD_INSN1(seq, line, insn, op1) \
|
|
|
|
ADD_ELEM(seq, (LINK_ELEMENT *) \
|
|
|
|
new_insn_body(iseq, line, BIN(insn), 1, (VALUE)op1))
|
|
|
|
|
|
|
|
#define ADD_INSN2(seq, line, insn, op1, op2) \
|
|
|
|
ADD_ELEM(seq, (LINK_ELEMENT *) \
|
|
|
|
new_insn_body(iseq, line, BIN(insn), 2, (VALUE)op1, (VALUE)op2))
|
|
|
|
|
|
|
|
#define ADD_INSN3(seq, line, insn, op1, op2, op3) \
|
|
|
|
ADD_ELEM(seq, (LINK_ELEMENT *) \
|
|
|
|
new_insn_body(iseq, line, BIN(insn), 3, (VALUE)op1, (VALUE)op2, (VALUE)op3))
|
|
|
|
|
|
|
|
/* Specific Insn factory */
|
|
|
|
#define ADD_SEND(seq, line, id, argc) \
|
|
|
|
ADD_SEND_R(seq, line, id, argc, (VALUE)Qfalse, (VALUE)INT2FIX(0))
|
|
|
|
|
2007-01-05 07:00:08 -05:00
|
|
|
#define ADD_CALL_RECEIVER(seq, line) \
|
|
|
|
ADD_INSN(seq, line, putnil)
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
#define ADD_CALL(seq, line, id, argc) \
|
|
|
|
ADD_SEND_R(seq, line, id, argc, (VALUE)Qfalse, (VALUE)INT2FIX(VM_CALL_FCALL_BIT))
|
|
|
|
|
2007-01-05 07:00:08 -05:00
|
|
|
#define ADD_CALL_WITH_BLOCK(seq, line, id, argc, block) \
|
|
|
|
ADD_SEND_R(seq, line, id, argc, block, (VALUE)INT2FIX(VM_CALL_FCALL_BIT))
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
#define ADD_SEND_R(seq, line, id, argc, block, flag) \
|
|
|
|
ADD_ELEM(seq, (LINK_ELEMENT *) \
|
|
|
|
new_insn_send(iseq, line, \
|
|
|
|
(VALUE)id, (VALUE)argc, (VALUE)block, (VALUE)flag))
|
|
|
|
|
2007-04-19 06:37:08 -04:00
|
|
|
#define ADD_TRACE(seq, line, event) \
|
2008-07-01 12:55:30 -04:00
|
|
|
do { \
|
|
|
|
if ((event) == RUBY_EVENT_LINE && iseq->coverage && RARRAY_PTR(iseq->coverage)[(line) - 1] == Qnil) { \
|
2008-07-01 14:13:22 -04:00
|
|
|
RARRAY_PTR(iseq->coverage)[(line) - 1] = INT2FIX(0); \
|
|
|
|
ADD_INSN1(seq, line, trace, INT2FIX(RUBY_EVENT_COVERAGE)); \
|
2008-07-01 12:55:30 -04:00
|
|
|
} \
|
2008-07-01 14:13:22 -04:00
|
|
|
ADD_INSN1(seq, line, trace, INT2FIX(event)); \
|
2008-07-01 12:55:30 -04:00
|
|
|
}while(0);
|
2007-04-19 06:37:08 -04:00
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
/* add label */
|
|
|
|
#define ADD_LABEL(seq, label) \
|
2008-01-25 13:02:01 -05:00
|
|
|
ADD_ELEM(seq, (LINK_ELEMENT *) label)
|
|
|
|
|
|
|
|
#define ADD_ADJUST(seq, line, label) \
|
|
|
|
ADD_ELEM(seq, (LINK_ELEMENT *) new_adjust_body(iseq, label, line))
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2008-01-26 03:27:00 -05:00
|
|
|
#define ADD_ADJUST_RESTORE(seq, label) \
|
|
|
|
ADD_ELEM(seq, (LINK_ELEMENT *) new_adjust_body(iseq, label, -1))
|
|
|
|
|
2007-04-05 04:58:46 -04:00
|
|
|
#define ADD_CATCH_ENTRY(type, ls, le, iseqv, lc) \
|
|
|
|
(rb_ary_push(iseq->compile_data->catch_table_ary, \
|
|
|
|
rb_ary_new3(5, type, \
|
|
|
|
(VALUE)(ls) | 1, (VALUE)(le) | 1, \
|
|
|
|
iseqv, (VALUE)(lc) | 1)))
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
/* compile node */
|
|
|
|
#define COMPILE(anchor, desc, node) \
|
|
|
|
(debug_compile("== " desc "\n", \
|
|
|
|
iseq_compile_each(iseq, anchor, node, 0)))
|
|
|
|
|
|
|
|
/* compile node, this node's value will be poped */
|
|
|
|
#define COMPILE_POPED(anchor, desc, node) \
|
|
|
|
(debug_compile("== " desc "\n", \
|
|
|
|
iseq_compile_each(iseq, anchor, node, 1)))
|
|
|
|
|
|
|
|
/* compile node, which is poped when 'poped' is true */
|
|
|
|
#define COMPILE_(anchor, desc, node, poped) \
|
|
|
|
(debug_compile("== " desc "\n", \
|
|
|
|
iseq_compile_each(iseq, anchor, node, poped)))
|
|
|
|
|
|
|
|
#define OPERAND_AT(insn, idx) \
|
|
|
|
(((INSN*)(insn))->operands[idx])
|
|
|
|
|
|
|
|
#define INSN_OF(insn) \
|
|
|
|
(((INSN*)(insn))->insn_id)
|
|
|
|
|
|
|
|
/* error */
|
|
|
|
#define COMPILE_ERROR(strs) \
|
|
|
|
{ \
|
|
|
|
VALUE tmp = GET_THREAD()->errinfo; \
|
2008-04-14 01:34:04 -04:00
|
|
|
if (compile_debug) rb_compile_bug strs; \
|
2006-12-31 10:02:22 -05:00
|
|
|
GET_THREAD()->errinfo = iseq->compile_data->err_info; \
|
|
|
|
rb_compile_error strs; \
|
|
|
|
iseq->compile_data->err_info = GET_THREAD()->errinfo; \
|
|
|
|
GET_THREAD()->errinfo = tmp; \
|
|
|
|
ret = 0; \
|
|
|
|
break; \
|
|
|
|
}
|
|
|
|
|
* 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.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15983 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-04-11 23:41:51 -04:00
|
|
|
#define ERROR_ARGS ruby_sourcefile, nd_line(node),
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 04:12:18 -04:00
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
#define COMPILE_OK 1
|
|
|
|
#define COMPILE_NG 0
|
|
|
|
|
2007-07-20 03:11:35 -04:00
|
|
|
|
|
|
|
/* leave name uninitialized so that compiler warn if INIT_ANCHOR is
|
|
|
|
* missing */
|
2006-12-31 10:02:22 -05:00
|
|
|
#define DECL_ANCHOR(name) \
|
2007-07-20 03:11:35 -04:00
|
|
|
LINK_ANCHOR *name, name##_body__ = {{0,},}
|
|
|
|
#define INIT_ANCHOR(name) \
|
|
|
|
(name##_body__.last = &name##_body__.anchor, name = &name##_body__)
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2007-04-05 04:58:46 -04:00
|
|
|
#endif /* RUBY_COMPILE_H */
|