2006-12-31 18:02:22 +03:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
iseq.c -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
$Date$
|
|
|
|
created at: 2006-07-11(Tue) 09:00:03 +0900
|
|
|
|
|
|
|
|
Copyright (C) 2006 Koichi Sasada
|
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
2007-06-10 07:06:15 +04:00
|
|
|
#include "ruby/ruby.h"
|
|
|
|
#include "ruby/node.h"
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* 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 08:25:46 +04:00
|
|
|
/* #define MARK_FREE_DEBUG 1 */
|
|
|
|
#include "gc.h"
|
|
|
|
#include "vm_core.h"
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
#include "insns.inc"
|
|
|
|
#include "insns_info.inc"
|
|
|
|
|
* 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 08:25:46 +04:00
|
|
|
/* compile.c */
|
|
|
|
void iseq_compile(VALUE self, NODE *node);
|
|
|
|
int iseq_translate_threaded_code(rb_iseq_t *iseq);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-01-17 11:48:52 +03:00
|
|
|
VALUE rb_cISeq;
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static void
|
|
|
|
compile_data_free(struct iseq_compile_data *compile_data)
|
|
|
|
{
|
|
|
|
if (compile_data) {
|
|
|
|
struct iseq_compile_data_storage *cur, *next;
|
|
|
|
cur = compile_data->storage_head;
|
|
|
|
while (cur) {
|
|
|
|
next = cur->next;
|
|
|
|
ruby_xfree(cur);
|
|
|
|
cur = next;
|
|
|
|
}
|
|
|
|
ruby_xfree(compile_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
iseq_free(void *ptr)
|
|
|
|
{
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
rb_iseq_t *iseq;
|
2007-06-25 06:44:20 +04:00
|
|
|
RUBY_FREE_ENTER("iseq");
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
if (ptr) {
|
|
|
|
iseq = ptr;
|
|
|
|
/* It's possible that strings are freed
|
|
|
|
* GC_INFO("%s @ %s\n", RSTRING_PTR(iseq->name),
|
2007-02-25 04:34:33 +03:00
|
|
|
* RSTRING_PTR(iseq->filename));
|
2006-12-31 18:02:22 +03:00
|
|
|
*/
|
|
|
|
if (iseq->iseq != iseq->iseq_encoded) {
|
2007-06-25 06:44:20 +04:00
|
|
|
RUBY_FREE_UNLESS_NULL(iseq->iseq_encoded);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2007-05-11 10:26:06 +04:00
|
|
|
|
2007-06-25 06:44:20 +04:00
|
|
|
RUBY_FREE_UNLESS_NULL(iseq->iseq);
|
2007-06-30 22:04:35 +04:00
|
|
|
RUBY_FREE_UNLESS_NULL(iseq->insn_info_table);
|
2007-06-25 06:44:20 +04:00
|
|
|
RUBY_FREE_UNLESS_NULL(iseq->local_table);
|
|
|
|
RUBY_FREE_UNLESS_NULL(iseq->catch_table);
|
2007-07-01 22:16:02 +04:00
|
|
|
RUBY_FREE_UNLESS_NULL(iseq->arg_opt_table);
|
2006-12-31 18:02:22 +03:00
|
|
|
compile_data_free(iseq->compile_data);
|
|
|
|
ruby_xfree(ptr);
|
|
|
|
}
|
2007-06-25 06:44:20 +04:00
|
|
|
RUBY_FREE_LEAVE("iseq");
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
iseq_mark(void *ptr)
|
|
|
|
{
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
rb_iseq_t *iseq;
|
2007-06-25 06:44:20 +04:00
|
|
|
RUBY_MARK_ENTER("iseq");
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
if (ptr) {
|
|
|
|
iseq = ptr;
|
2007-06-25 06:44:20 +04:00
|
|
|
RUBY_GC_INFO("%s @ %s\n", RSTRING_PTR(iseq->name), RSTRING_PTR(iseq->filename));
|
2007-07-01 22:16:02 +04:00
|
|
|
RUBY_MARK_UNLESS_NULL(iseq->mark_ary);
|
2007-06-25 06:44:20 +04:00
|
|
|
RUBY_MARK_UNLESS_NULL(iseq->name);
|
|
|
|
RUBY_MARK_UNLESS_NULL(iseq->filename);
|
|
|
|
RUBY_MARK_UNLESS_NULL((VALUE)iseq->cref_stack);
|
|
|
|
RUBY_MARK_UNLESS_NULL(iseq->klass);
|
2007-12-25 05:17:16 +03:00
|
|
|
/* RUBY_MARK_UNLESS_NULL((VALUE)iseq->node); */
|
|
|
|
/* RUBY_MARK_UNLESS_NULL(iseq->cached_special_block); */
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
if (iseq->compile_data != 0) {
|
2007-06-25 06:44:20 +04:00
|
|
|
RUBY_MARK_UNLESS_NULL(iseq->compile_data->mark_ary);
|
|
|
|
RUBY_MARK_UNLESS_NULL(iseq->compile_data->err_info);
|
|
|
|
RUBY_MARK_UNLESS_NULL(iseq->compile_data->catch_table_ary);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
2007-06-25 06:44:20 +04:00
|
|
|
RUBY_MARK_LEAVE("iseq");
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
iseq_alloc(VALUE klass)
|
|
|
|
{
|
|
|
|
VALUE volatile obj;
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
rb_iseq_t *iseq;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
obj = Data_Make_Struct(klass, rb_iseq_t, iseq_mark, iseq_free, iseq);
|
|
|
|
MEMZERO(iseq, rb_iseq_t, 1);
|
2006-12-31 18:02:22 +03:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2007-07-04 00:12:55 +04:00
|
|
|
static void
|
|
|
|
set_relation(rb_iseq_t *iseq, const VALUE parent)
|
|
|
|
{
|
|
|
|
const int type = iseq->type;
|
|
|
|
rb_thread_t *th = GET_THREAD();
|
|
|
|
|
|
|
|
/* set class nest stack */
|
|
|
|
if (type == ISEQ_TYPE_TOP) {
|
|
|
|
/* toplevel is private */
|
|
|
|
iseq->cref_stack = NEW_BLOCK(th->top_wrapper ? th->top_wrapper : rb_cObject);
|
|
|
|
iseq->cref_stack->nd_file = 0;
|
|
|
|
iseq->cref_stack->nd_visi = NOEX_PRIVATE;
|
|
|
|
}
|
|
|
|
else if (type == ISEQ_TYPE_METHOD || type == ISEQ_TYPE_CLASS) {
|
|
|
|
iseq->cref_stack = NEW_BLOCK(0); /* place holder */
|
|
|
|
iseq->cref_stack->nd_file = 0;
|
|
|
|
}
|
|
|
|
else if (RTEST(parent)) {
|
|
|
|
rb_iseq_t *piseq;
|
|
|
|
GetISeqPtr(parent, piseq);
|
|
|
|
iseq->cref_stack = piseq->cref_stack;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == ISEQ_TYPE_TOP ||
|
|
|
|
type == ISEQ_TYPE_METHOD || type == ISEQ_TYPE_CLASS) {
|
|
|
|
iseq->local_iseq = iseq;
|
|
|
|
}
|
|
|
|
else if (RTEST(parent)) {
|
|
|
|
rb_iseq_t *piseq;
|
|
|
|
GetISeqPtr(parent, piseq);
|
|
|
|
iseq->local_iseq = piseq->local_iseq;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RTEST(parent)) {
|
|
|
|
rb_iseq_t *piseq;
|
|
|
|
GetISeqPtr(parent, piseq);
|
|
|
|
iseq->parent_iseq = piseq;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static VALUE
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
prepare_iseq_build(rb_iseq_t *iseq,
|
2007-02-25 04:34:33 +03:00
|
|
|
VALUE name, VALUE filename,
|
2006-12-31 18:02:22 +03:00
|
|
|
VALUE parent, VALUE type, VALUE block_opt,
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
const rb_compile_option_t *option)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2007-06-07 12:21:01 +04:00
|
|
|
OBJ_FREEZE(name);
|
|
|
|
OBJ_FREEZE(filename);
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
iseq->name = name;
|
2007-02-25 04:34:33 +03:00
|
|
|
iseq->filename = filename;
|
2007-06-07 12:21:01 +04:00
|
|
|
iseq->defined_method_id = 0;
|
2007-07-01 22:16:02 +04:00
|
|
|
iseq->mark_ary = rb_ary_new();
|
|
|
|
RBASIC(iseq->mark_ary)->klass = 0;
|
2007-02-25 19:29:26 +03:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
iseq->type = type;
|
* compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,
proc.c, vm.c, vm_macro.def, vm_macro.def, yarvcore.c, yarvcore.h,
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change
is to change node structure around NODE_SCOPE, NODE_ARGS. Every
scope (method/class/block) has own NODE_SCOPE node and NODE_ARGS
represents more details of arguments information. I'll write a
document about detail of node structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-03-21 14:15:15 +03:00
|
|
|
iseq->arg_rest = -1;
|
|
|
|
iseq->arg_block = -1;
|
2006-12-31 18:02:22 +03:00
|
|
|
iseq->klass = 0;
|
2007-12-25 05:17:16 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* iseq->special_block_builder = GC_GUARDED_PTR_REF(block_opt);
|
|
|
|
* iseq->cached_special_block_builder = 0;
|
|
|
|
* iseq->cached_special_block = 0;
|
|
|
|
*/
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
iseq->compile_data = ALLOC(struct iseq_compile_data);
|
|
|
|
MEMZERO(iseq->compile_data, struct iseq_compile_data, 1);
|
|
|
|
iseq->compile_data->mark_ary = rb_ary_new();
|
|
|
|
RBASIC(iseq->compile_data->mark_ary)->klass = 0;
|
|
|
|
|
|
|
|
iseq->compile_data->storage_head = iseq->compile_data->storage_current =
|
2007-02-25 19:29:26 +03:00
|
|
|
(struct iseq_compile_data_storage *)
|
|
|
|
ALLOC_N(char, INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE +
|
2006-12-31 18:02:22 +03:00
|
|
|
sizeof(struct iseq_compile_data_storage));
|
|
|
|
|
|
|
|
iseq->compile_data->catch_table_ary = rb_ary_new();
|
|
|
|
iseq->compile_data->storage_head->pos = 0;
|
|
|
|
iseq->compile_data->storage_head->next = 0;
|
|
|
|
iseq->compile_data->storage_head->size =
|
2007-02-25 19:29:26 +03:00
|
|
|
INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE;
|
2006-12-31 18:02:22 +03:00
|
|
|
iseq->compile_data->storage_head->buff =
|
2007-02-25 19:29:26 +03:00
|
|
|
(char *)(&iseq->compile_data->storage_head->buff + 1);
|
2006-12-31 18:02:22 +03:00
|
|
|
iseq->compile_data->option = option;
|
|
|
|
|
2007-07-04 00:12:55 +04:00
|
|
|
set_relation(iseq, parent);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
cleanup_iseq_build(rb_iseq_t *iseq)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
struct iseq_compile_data *data = iseq->compile_data;
|
* 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 12:12:18 +04:00
|
|
|
VALUE err = data->err_info;
|
2006-12-31 18:02:22 +03:00
|
|
|
iseq->compile_data = 0;
|
|
|
|
compile_data_free(data);
|
2007-05-11 10:26:06 +04:00
|
|
|
|
* 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 12:12:18 +04:00
|
|
|
if (RTEST(err)) {
|
|
|
|
rb_funcall2(err, rb_intern("set_backtrace"), 1, &iseq->filename);
|
|
|
|
rb_exc_raise(err);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
static rb_compile_option_t COMPILE_OPTION_DEFAULT = {
|
2006-12-31 18:02:22 +03:00
|
|
|
OPT_INLINE_CONST_CACHE, /* int inline_const_cache; */
|
|
|
|
OPT_PEEPHOLE_OPTIMIZATION, /* int peephole_optimization; */
|
2007-05-21 08:46:51 +04:00
|
|
|
OPT_TAILCALL_OPTIMIZATION, /* int tailcall_optimization */
|
2006-12-31 18:02:22 +03:00
|
|
|
OPT_SPECIALISED_INSTRUCTION, /* int specialized_instruction; */
|
|
|
|
OPT_OPERANDS_UNIFICATION, /* int operands_unification; */
|
|
|
|
OPT_INSTRUCTIONS_UNIFICATION, /* int instructions_unification; */
|
|
|
|
OPT_STACK_CACHING, /* int stack_caching; */
|
2007-05-21 08:46:51 +04:00
|
|
|
OPT_TRACE_INSTRUCTION, /* int trace_instruction */
|
2006-12-31 18:02:22 +03:00
|
|
|
};
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
static const rb_compile_option_t COMPILE_OPTION_FALSE;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
static void
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
make_compile_option(rb_compile_option_t *option, VALUE opt)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
if (opt == Qnil) {
|
|
|
|
*option = COMPILE_OPTION_DEFAULT;
|
|
|
|
}
|
|
|
|
else if (opt == Qfalse) {
|
|
|
|
*option = COMPILE_OPTION_FALSE;
|
|
|
|
}
|
|
|
|
else if (opt == Qtrue) {
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
memset(option, 1, sizeof(rb_compile_option_t));
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
else if (CLASS_OF(opt) == rb_cHash) {
|
2007-05-21 08:46:51 +04:00
|
|
|
*option = COMPILE_OPTION_DEFAULT;
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
#define SET_COMPILE_OPTION(o, h, mem) \
|
2007-05-21 08:46:51 +04:00
|
|
|
{ VALUE flag = rb_hash_aref(h, ID2SYM(rb_intern(#mem))); \
|
2006-12-31 18:02:22 +03:00
|
|
|
if (flag == Qtrue) { o->mem = 1; } \
|
2007-05-21 08:46:51 +04:00
|
|
|
else if (flag == Qfalse) { o->mem = 0; } \
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
SET_COMPILE_OPTION(option, opt, inline_const_cache);
|
|
|
|
SET_COMPILE_OPTION(option, opt, peephole_optimization);
|
2007-05-21 08:46:51 +04:00
|
|
|
SET_COMPILE_OPTION(option, opt, tailcall_optimization);
|
2006-12-31 18:02:22 +03:00
|
|
|
SET_COMPILE_OPTION(option, opt, specialized_instruction);
|
|
|
|
SET_COMPILE_OPTION(option, opt, operands_unification);
|
|
|
|
SET_COMPILE_OPTION(option, opt, instructions_unification);
|
|
|
|
SET_COMPILE_OPTION(option, opt, stack_caching);
|
2007-04-19 14:37:08 +04:00
|
|
|
SET_COMPILE_OPTION(option, opt, trace_instruction);
|
2006-12-31 18:02:22 +03:00
|
|
|
#undef SET_COMPILE_OPTION
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_raise(rb_eTypeError, "Compile option must be Hash/true/false/nil");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
make_compile_option_value(rb_compile_option_t *option)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
VALUE opt = rb_hash_new();
|
|
|
|
#define SET_COMPILE_OPTION(o, h, mem) \
|
|
|
|
rb_hash_aset(h, ID2SYM(rb_intern(#mem)), o->mem ? Qtrue : Qfalse)
|
|
|
|
{
|
|
|
|
SET_COMPILE_OPTION(option, opt, inline_const_cache);
|
|
|
|
SET_COMPILE_OPTION(option, opt, peephole_optimization);
|
2007-05-21 08:46:51 +04:00
|
|
|
SET_COMPILE_OPTION(option, opt, tailcall_optimization);
|
2006-12-31 18:02:22 +03:00
|
|
|
SET_COMPILE_OPTION(option, opt, specialized_instruction);
|
|
|
|
SET_COMPILE_OPTION(option, opt, operands_unification);
|
|
|
|
SET_COMPILE_OPTION(option, opt, instructions_unification);
|
|
|
|
SET_COMPILE_OPTION(option, opt, stack_caching);
|
|
|
|
}
|
|
|
|
#undef SET_COMPILE_OPTION
|
|
|
|
return opt;
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
2007-02-25 04:34:33 +03:00
|
|
|
rb_iseq_new(NODE *node, VALUE name, VALUE filename,
|
2006-12-31 18:02:22 +03:00
|
|
|
VALUE parent, VALUE type)
|
|
|
|
{
|
2007-02-25 04:34:33 +03:00
|
|
|
return rb_iseq_new_with_opt(node, name, filename, parent, type,
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
&COMPILE_OPTION_DEFAULT);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2007-02-25 04:34:33 +03:00
|
|
|
rb_iseq_new_with_bopt_and_opt(NODE *node, VALUE name, VALUE filename,
|
2006-12-31 18:02:22 +03:00
|
|
|
VALUE parent, VALUE type, VALUE bopt,
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
const rb_compile_option_t *option)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
rb_iseq_t *iseq;
|
2007-01-17 11:48:52 +03:00
|
|
|
VALUE self = iseq_alloc(rb_cISeq);
|
2007-05-11 10:26:06 +04:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
GetISeqPtr(self, iseq);
|
|
|
|
iseq->self = self;
|
|
|
|
|
2007-02-25 04:34:33 +03:00
|
|
|
prepare_iseq_build(iseq, name, filename, parent, type, bopt, option);
|
* 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 08:25:46 +04:00
|
|
|
iseq_compile(self, node);
|
2006-12-31 18:02:22 +03:00
|
|
|
cleanup_iseq_build(iseq);
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
2007-02-25 04:34:33 +03:00
|
|
|
rb_iseq_new_with_opt(NODE *node, VALUE name, VALUE filename,
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
VALUE parent, VALUE type,
|
|
|
|
const rb_compile_option_t *option)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2007-02-25 04:34:33 +03:00
|
|
|
return rb_iseq_new_with_bopt_and_opt(node, name, filename, parent, type,
|
2006-12-31 18:02:22 +03:00
|
|
|
Qfalse, option);
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
2007-02-25 04:34:33 +03:00
|
|
|
rb_iseq_new_with_bopt(NODE *node, VALUE name, VALUE filename,
|
2006-12-31 18:02:22 +03:00
|
|
|
VALUE parent, VALUE type, VALUE bopt)
|
|
|
|
{
|
2007-02-25 04:34:33 +03:00
|
|
|
return rb_iseq_new_with_bopt_and_opt(node, name, filename, parent, type,
|
2006-12-31 18:02:22 +03:00
|
|
|
bopt, &COMPILE_OPTION_DEFAULT);
|
|
|
|
}
|
|
|
|
|
2007-07-02 01:43:30 +04:00
|
|
|
VALUE iseq_build_from_ary(rb_iseq_t *iseq, VALUE locals, VALUE args,
|
|
|
|
VALUE exception, VALUE body);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
#define CHECK_ARRAY(v) rb_convert_type(v, T_ARRAY, "Array", "to_ary")
|
|
|
|
#define CHECK_STRING(v) rb_convert_type(v, T_STRING, "String", "to_str")
|
|
|
|
#define CHECK_SYMBOL(v) rb_convert_type(v, T_SYMBOL, "Symbol", "to_sym")
|
|
|
|
#define CHECK_INTEGER(v) (NUM2LONG(v), v)
|
|
|
|
VALUE
|
|
|
|
iseq_load(VALUE self, VALUE data, VALUE parent, VALUE opt)
|
|
|
|
{
|
2007-01-17 11:48:52 +03:00
|
|
|
VALUE iseqval = iseq_alloc(rb_cISeq);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
VALUE magic, version1, version2, format_type, misc;
|
|
|
|
VALUE name, filename, line;
|
|
|
|
VALUE type, body, locals, args, exception;
|
|
|
|
|
|
|
|
VALUE iseq_type;
|
|
|
|
struct st_table *type_map = 0;
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
rb_iseq_t *iseq;
|
|
|
|
rb_compile_option_t option;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
/* [magic, major_version, minor_version, format_type, misc,
|
|
|
|
* name, filename, line,
|
|
|
|
* type, locals, args, exception_table, body]
|
|
|
|
*/
|
|
|
|
|
|
|
|
data = CHECK_ARRAY(data);
|
2007-05-11 10:26:06 +04:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
magic = CHECK_STRING(rb_ary_entry(data, 0));
|
|
|
|
version1 = CHECK_INTEGER(rb_ary_entry(data, 1));
|
|
|
|
version2 = CHECK_INTEGER(rb_ary_entry(data, 2));
|
|
|
|
format_type = CHECK_INTEGER(rb_ary_entry(data, 3));
|
|
|
|
misc = rb_ary_entry(data, 4); /* TODO */
|
|
|
|
|
|
|
|
name = CHECK_STRING(rb_ary_entry(data, 5));
|
|
|
|
filename = CHECK_STRING(rb_ary_entry(data, 6));
|
|
|
|
line = CHECK_ARRAY(rb_ary_entry(data, 7));
|
|
|
|
|
|
|
|
type = CHECK_SYMBOL(rb_ary_entry(data, 8));
|
|
|
|
locals = CHECK_ARRAY(rb_ary_entry(data, 9));
|
2007-07-02 01:43:30 +04:00
|
|
|
|
|
|
|
args = rb_ary_entry(data, 10);
|
2006-12-31 18:02:22 +03:00
|
|
|
if (FIXNUM_P(args) || (args = CHECK_ARRAY(args))) {
|
|
|
|
/* */
|
|
|
|
}
|
2007-07-02 01:43:30 +04:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
exception = CHECK_ARRAY(rb_ary_entry(data, 11));
|
|
|
|
body = CHECK_ARRAY(rb_ary_entry(data, 12));
|
|
|
|
|
|
|
|
GetISeqPtr(iseqval, iseq);
|
|
|
|
iseq->self = iseqval;
|
|
|
|
|
|
|
|
if (type_map == 0) {
|
|
|
|
type_map = st_init_numtable();
|
2007-07-02 03:57:04 +04:00
|
|
|
st_insert(type_map, ID2SYM(rb_intern("top")), ISEQ_TYPE_TOP);
|
|
|
|
st_insert(type_map, ID2SYM(rb_intern("method")), ISEQ_TYPE_METHOD);
|
|
|
|
st_insert(type_map, ID2SYM(rb_intern("block")), ISEQ_TYPE_BLOCK);
|
|
|
|
st_insert(type_map, ID2SYM(rb_intern("class")), ISEQ_TYPE_CLASS);
|
|
|
|
st_insert(type_map, ID2SYM(rb_intern("rescue")), ISEQ_TYPE_RESCUE);
|
|
|
|
st_insert(type_map, ID2SYM(rb_intern("ensure")), ISEQ_TYPE_ENSURE);
|
|
|
|
st_insert(type_map, ID2SYM(rb_intern("eval")), ISEQ_TYPE_EVAL);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (st_lookup(type_map, type, &iseq_type) == 0) {
|
* 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 12:12:18 +04:00
|
|
|
const char *typename = rb_id2name(type);
|
|
|
|
if (typename)
|
|
|
|
rb_raise(rb_eTypeError, "unsupport type: :%s", typename);
|
|
|
|
else
|
|
|
|
rb_raise(rb_eTypeError, "unsupport type: %p", (void *)type);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (parent == Qnil) {
|
|
|
|
parent = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
make_compile_option(&option, opt);
|
|
|
|
prepare_iseq_build(iseq, name, filename,
|
|
|
|
parent, iseq_type, 0, &option);
|
|
|
|
|
2007-07-02 01:43:30 +04:00
|
|
|
iseq_build_from_ary(iseq, locals, args, exception, body);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
cleanup_iseq_build(iseq);
|
|
|
|
return iseqval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
iseq_s_load(int argc, VALUE *argv, VALUE self)
|
|
|
|
{
|
|
|
|
VALUE data, opt=Qnil;
|
|
|
|
rb_scan_args(argc, argv, "11", &data, &opt);
|
2007-05-11 10:26:06 +04:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
return iseq_load(self, data, 0, opt);
|
|
|
|
}
|
|
|
|
|
|
|
|
static NODE *
|
|
|
|
compile_string(VALUE str, VALUE file, VALUE line)
|
|
|
|
{
|
* 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 12:12:18 +04:00
|
|
|
VALUE parser = rb_parser_new();
|
|
|
|
NODE *node = rb_parser_compile_string(parser, StringValueCStr(file),
|
|
|
|
str, NUM2INT(line));
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* 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 12:12:18 +04:00
|
|
|
if (!node) {
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 19:26:04 +03:00
|
|
|
rb_exc_raise(GET_THREAD()->errinfo); /* TODO: check err */
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
* 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 08:25:46 +04:00
|
|
|
VALUE
|
|
|
|
rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE line, VALUE opt)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
rb_compile_option_t option;
|
* 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 08:25:46 +04:00
|
|
|
NODE *node = compile_string(src, file, line);
|
|
|
|
rb_thread_t *th = GET_THREAD();
|
|
|
|
make_compile_option(&option, opt);
|
|
|
|
|
|
|
|
if (th->base_block) {
|
|
|
|
return rb_iseq_new_with_opt(node, th->base_block->iseq->name,
|
|
|
|
file, th->base_block->iseq->self,
|
|
|
|
ISEQ_TYPE_EVAL, &option);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return rb_iseq_new_with_opt(node, rb_str_new2("<compiled>"), file, Qfalse,
|
|
|
|
ISEQ_TYPE_TOP, &option);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_iseq_compile(VALUE src, VALUE file, VALUE line)
|
|
|
|
{
|
|
|
|
return rb_iseq_compile_with_option(src, file, line, Qnil);
|
|
|
|
}
|
2007-05-11 10:26:06 +04:00
|
|
|
|
* 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 08:25:46 +04:00
|
|
|
static VALUE
|
|
|
|
iseq_s_compile(int argc, VALUE *argv, VALUE self)
|
|
|
|
{
|
|
|
|
VALUE src, file = Qnil, line = INT2FIX(1), opt = Qnil;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-12-25 12:43:23 +03:00
|
|
|
rb_secure(1);
|
|
|
|
|
* 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 08:25:46 +04:00
|
|
|
rb_scan_args(argc, argv, "13", &src, &file, &line, &opt);
|
2006-12-31 18:02:22 +03:00
|
|
|
file = file == Qnil ? rb_str_new2("<compiled>") : file;
|
|
|
|
line = line == Qnil ? INT2FIX(1) : line;
|
|
|
|
|
* 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 08:25:46 +04:00
|
|
|
return rb_iseq_compile_with_option(src, file, line, opt);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
iseq_s_compile_file(int argc, VALUE *argv, VALUE self)
|
|
|
|
{
|
|
|
|
VALUE file, line = INT2FIX(1), opt = Qnil;
|
|
|
|
VALUE parser;
|
|
|
|
VALUE f;
|
|
|
|
NODE *node;
|
|
|
|
const char *fname;
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
rb_compile_option_t option;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-12-25 12:43:23 +03:00
|
|
|
rb_secure(1);
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_scan_args(argc, argv, "11", &file, &opt);
|
|
|
|
fname = StringValueCStr(file);
|
|
|
|
|
|
|
|
f = rb_file_open(fname, "r");
|
|
|
|
|
|
|
|
parser = rb_parser_new();
|
|
|
|
node = rb_parser_compile_file(parser, fname, f, NUM2INT(line));
|
|
|
|
make_compile_option(&option, opt);
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
return rb_iseq_new_with_opt(node, rb_str_new2("<main>"), file, Qfalse,
|
|
|
|
ISEQ_TYPE_TOP, &option);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
iseq_s_compile_option_set(VALUE self, VALUE opt)
|
|
|
|
{
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
rb_compile_option_t option;
|
2007-12-25 12:43:23 +03:00
|
|
|
rb_secure(1);
|
2006-12-31 18:02:22 +03:00
|
|
|
make_compile_option(&option, opt);
|
|
|
|
COMPILE_OPTION_DEFAULT = option;
|
2007-08-06 08:34:11 +04:00
|
|
|
return opt;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
iseq_s_compile_option_get(VALUE self)
|
|
|
|
{
|
|
|
|
return make_compile_option_value(&COMPILE_OPTION_DEFAULT);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
static rb_iseq_t *
|
2006-12-31 18:02:22 +03:00
|
|
|
iseq_check(VALUE val)
|
|
|
|
{
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
rb_iseq_t *iseq;
|
2006-12-31 18:02:22 +03:00
|
|
|
GetISeqPtr(val, iseq);
|
|
|
|
if (!iseq->name) {
|
|
|
|
rb_raise(rb_eTypeError, "uninitialized InstructionSequence");
|
|
|
|
}
|
|
|
|
return iseq;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
iseq_eval(VALUE self)
|
|
|
|
{
|
2007-12-25 12:43:23 +03:00
|
|
|
rb_secure(1);
|
* 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 08:25:46 +04:00
|
|
|
return rb_iseq_eval(self);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
iseq_inspect(VALUE self)
|
|
|
|
{
|
|
|
|
char buff[0x100];
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
rb_iseq_t *iseq = iseq_check(self);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
snprintf(buff, sizeof(buff), "<ISeq:%s@%s>",
|
2007-02-25 04:34:33 +03:00
|
|
|
RSTRING_PTR(iseq->name), RSTRING_PTR(iseq->filename));
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
return rb_str_new2(buff);
|
|
|
|
}
|
|
|
|
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
VALUE iseq_data_to_ary(rb_iseq_t *iseq);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
static VALUE
|
|
|
|
iseq_to_a(VALUE self)
|
|
|
|
{
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
rb_iseq_t *iseq = iseq_check(self);
|
2007-12-25 12:43:23 +03:00
|
|
|
rb_secure(1);
|
2006-12-31 18:02:22 +03:00
|
|
|
return iseq_data_to_ary(iseq);
|
|
|
|
}
|
|
|
|
|
2007-12-20 00:39:08 +03:00
|
|
|
/* TODO: search algorithm is brute force.
|
|
|
|
this should be binary search or so. */
|
|
|
|
|
|
|
|
static struct iseq_insn_info_entry *
|
|
|
|
get_insn_info(const rb_iseq_t *iseq, const unsigned long pos)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2007-12-20 00:39:08 +03:00
|
|
|
unsigned long i, size = iseq->insn_info_size;
|
|
|
|
struct iseq_insn_info_entry *table = iseq->insn_info_table;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
for (i = 0; i < size; i++) {
|
2007-12-20 00:39:08 +03:00
|
|
|
if (table[i].position == pos) {
|
|
|
|
return &table[i];
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
2007-12-20 00:39:08 +03:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-12-20 00:39:08 +03:00
|
|
|
static unsigned short
|
|
|
|
find_line_no(rb_iseq_t *iseq, unsigned long pos)
|
|
|
|
{
|
|
|
|
struct iseq_insn_info_entry *entry = get_insn_info(iseq, pos);
|
|
|
|
if (entry) {
|
|
|
|
return entry->line_no;
|
|
|
|
}
|
2007-12-20 10:44:03 +03:00
|
|
|
else {
|
|
|
|
return 0;
|
|
|
|
}
|
2007-12-20 00:39:08 +03:00
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static unsigned short
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
find_prev_line_no(rb_iseq_t *iseqdat, unsigned long pos)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
unsigned long i, size = iseqdat->insn_info_size;
|
2007-07-01 22:16:02 +04:00
|
|
|
struct iseq_insn_info_entry *iiary = iseqdat->insn_info_table;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
for (i = 0; i < size; i++) {
|
|
|
|
if (iiary[i].position == pos) {
|
|
|
|
if (i > 0) {
|
|
|
|
return iiary[i - 1].line_no;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-08-12 23:09:15 +04:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
insn_operand_intern(rb_iseq_t *iseq,
|
2006-12-31 18:02:22 +03:00
|
|
|
int insn, int op_no, VALUE op,
|
|
|
|
int len, int pos, VALUE *pnop, VALUE child)
|
|
|
|
{
|
|
|
|
char *types = insn_op_types(insn);
|
|
|
|
char type = types[op_no];
|
|
|
|
VALUE ret;
|
|
|
|
char buff[0x100];
|
|
|
|
|
|
|
|
switch (type) {
|
2007-05-11 10:26:06 +04:00
|
|
|
case TS_OFFSET: /* LONG */
|
2006-12-31 18:02:22 +03:00
|
|
|
snprintf(buff, sizeof(buff), "%ld", pos + len + op);
|
|
|
|
ret = rb_str_new2(buff);
|
|
|
|
break;
|
|
|
|
|
2007-05-11 10:26:06 +04:00
|
|
|
case TS_NUM: /* ULONG */
|
2006-12-31 18:02:22 +03:00
|
|
|
snprintf(buff, sizeof(buff), "%lu", op);
|
|
|
|
ret = rb_str_new2(buff);
|
|
|
|
break;
|
|
|
|
|
2007-05-11 10:26:06 +04:00
|
|
|
case TS_LINDEX:
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
rb_iseq_t *ip = iseq->local_iseq;
|
2007-02-25 04:34:33 +03:00
|
|
|
int lidx = ip->local_size - op;
|
* compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,
proc.c, vm.c, vm_macro.def, vm_macro.def, yarvcore.c, yarvcore.h,
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change
is to change node structure around NODE_SCOPE, NODE_ARGS. Every
scope (method/class/block) has own NODE_SCOPE node and NODE_ARGS
represents more details of arguments information. I'll write a
document about detail of node structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-03-21 14:15:15 +03:00
|
|
|
const char *name = rb_id2name(ip->local_table[lidx]);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,
proc.c, vm.c, vm_macro.def, vm_macro.def, yarvcore.c, yarvcore.h,
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change
is to change node structure around NODE_SCOPE, NODE_ARGS. Every
scope (method/class/block) has own NODE_SCOPE node and NODE_ARGS
represents more details of arguments information. I'll write a
document about detail of node structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-03-21 14:15:15 +03:00
|
|
|
if (name) {
|
|
|
|
ret = rb_str_new2(name);
|
* parse.y, node.h, compile.c: change node tree structure. a purpose
of this change is to unify argument structure of method and block.
this change prohibits duplicate block parameter name.
new argument infromation:
NODE_ARGS [m: int, o: NODE_OPT_ARG, ->]
NODE_ARGS_AUX [r: ID, b: ID, ->]
NODE_ARGS_AUX [Pst: id, Plen: int, init: NODE*]
optarg information:
NODE_OPT_ARGS [idx, expr, ->]
* vm_macro.def: ditto.
* gc.c: ditto.
* iseq.c: ditto.
* compile.h: fix debug function name.
* test/ripper/test_scanner_events.rb: |_,_,foo| -> |_1,_2,foo|
* test/ruby/test_lambda.rb: disalbe test temporarily.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11840 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-24 05:07:05 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
ret = rb_str_new2("*");
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
}
|
2007-05-11 10:26:06 +04:00
|
|
|
case TS_DINDEX:{
|
|
|
|
if (insn == BIN(getdynamic) || insn == BIN(setdynamic)) {
|
|
|
|
rb_iseq_t *ip = iseq;
|
|
|
|
int level = *pnop, i;
|
|
|
|
const char *name;
|
|
|
|
for (i = 0; i < level; i++) {
|
|
|
|
ip = ip->parent_iseq;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2007-05-11 10:26:06 +04:00
|
|
|
name = rb_id2name(ip->local_table[ip->local_size - op]);
|
|
|
|
|
|
|
|
if (!name) {
|
|
|
|
name = "*";
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2007-05-11 10:26:06 +04:00
|
|
|
ret = rb_str_new2(name);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2007-05-11 10:26:06 +04:00
|
|
|
else {
|
|
|
|
ret = rb_inspect(INT2FIX(op));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TS_ID: /* ID (symbol) */
|
2006-12-31 18:02:22 +03:00
|
|
|
op = ID2SYM(op);
|
2007-05-11 10:26:06 +04:00
|
|
|
case TS_VALUE: /* VALUE */
|
2006-12-31 18:02:22 +03:00
|
|
|
ret = rb_inspect(op);
|
2007-01-17 11:48:52 +03:00
|
|
|
if (CLASS_OF(op) == rb_cISeq) {
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_ary_push(child, op);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-05-11 10:26:06 +04:00
|
|
|
case TS_ISEQ: /* iseq */
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
rb_iseq_t *iseq = (rb_iseq_t *)op;
|
2006-12-31 18:02:22 +03:00
|
|
|
if (iseq) {
|
|
|
|
ret = iseq->name;
|
|
|
|
if (child) {
|
|
|
|
rb_ary_push(child, iseq->self);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ret = rb_str_new2("nil");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-05-11 10:26:06 +04:00
|
|
|
case TS_GENTRY:
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
struct global_entry *entry = (struct global_entry *)op;
|
2007-12-24 19:38:44 +03:00
|
|
|
ret = rb_str_dup(rb_id2str(entry->id));
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-05-11 10:26:06 +04:00
|
|
|
case TS_IC:
|
2006-12-31 18:02:22 +03:00
|
|
|
ret = rb_str_new2("<ic>");
|
|
|
|
break;
|
|
|
|
|
2007-05-11 10:26:06 +04:00
|
|
|
case TS_CDHASH:
|
2006-12-31 18:02:22 +03:00
|
|
|
ret = rb_str_new2("<cdhash>");
|
|
|
|
break;
|
|
|
|
|
2007-08-12 23:09:15 +04:00
|
|
|
case TS_FUNCPTR:
|
|
|
|
ret = rb_str_new2("<funcptr>");
|
|
|
|
break;
|
|
|
|
|
2007-05-11 10:26:06 +04:00
|
|
|
default:
|
* this commit is a result of refactoring. only renaming functions,
moving definitions place, add/remove prototypes, deleting
unused variables and removing yarv.h.
This commit doesn't change any behavior of ruby/vm.
* yarv.h, common.mk: remove yarv.h (contents are moved to yarvcore.h).
* error.c, eval_intern.h: include yarvcore.h instead yarv.h
* rename some functions:
* debug.[ch]: debug_*() -> ruby_debug_*()
* iseq.c: iseq_*() -> rb_iseq_*(), ruby_iseq_disasm()
* iseq.c: node_name() -> ruby_node_name()
* vm.c: yarv_check_redefinition_opt_method() ->
rb_vm_check_redefinition_opt_method()
* some refactoring with checking -Wall.
* array.c: remove rb_ary_ptr() (unused) and remove unused
local variables.
* object.c: add a prototype of rb_mod_module_exec().
* eval_intern.h (ruby_cref): set it inline.
* eval_load.c (rb_load), yarvcore.c: yarv_load() -> rb_load_internal().
* parse.y: add a prototype of rb_parse_in_eval() (in eval.c).
* process.c: add a prototype of rb_thread_stop_timer_thread() (in thread.c).
* thread.c: remove raw_gets() function (unused) and fix some format
mismatch (format mismatchs have remained yet. this is todo).
* thread.c (rb_thread_wait_fd_rw): fix typo on label name.
* thread_pthread.ci: comment out codes with USE_THREAD_CACHE.
* vm.c (rb_svar, rb_backref_get, rb_backref_get,
rb_lastline_get, rb_lastline_set) : moved from yarvcore.c.
* vm.c (yarv_init_redefined_flag): add a prototype and rename
yarv_opt_method_table to vm_opt_method_table.
* vm.c (rb_thread_eval): moved from yarvcore.c.
* yarvcore.c: remove unused global variables and fix to use nsdr().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-07 04:25:05 +03:00
|
|
|
rb_bug("ruby_iseq_disasm: unknown operand type: %c", type);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disassemble a instruction
|
|
|
|
* Iseq -> Iseq inspect object
|
|
|
|
*/
|
|
|
|
VALUE
|
* this commit is a result of refactoring. only renaming functions,
moving definitions place, add/remove prototypes, deleting
unused variables and removing yarv.h.
This commit doesn't change any behavior of ruby/vm.
* yarv.h, common.mk: remove yarv.h (contents are moved to yarvcore.h).
* error.c, eval_intern.h: include yarvcore.h instead yarv.h
* rename some functions:
* debug.[ch]: debug_*() -> ruby_debug_*()
* iseq.c: iseq_*() -> rb_iseq_*(), ruby_iseq_disasm()
* iseq.c: node_name() -> ruby_node_name()
* vm.c: yarv_check_redefinition_opt_method() ->
rb_vm_check_redefinition_opt_method()
* some refactoring with checking -Wall.
* array.c: remove rb_ary_ptr() (unused) and remove unused
local variables.
* object.c: add a prototype of rb_mod_module_exec().
* eval_intern.h (ruby_cref): set it inline.
* eval_load.c (rb_load), yarvcore.c: yarv_load() -> rb_load_internal().
* parse.y: add a prototype of rb_parse_in_eval() (in eval.c).
* process.c: add a prototype of rb_thread_stop_timer_thread() (in thread.c).
* thread.c: remove raw_gets() function (unused) and fix some format
mismatch (format mismatchs have remained yet. this is todo).
* thread.c (rb_thread_wait_fd_rw): fix typo on label name.
* thread_pthread.ci: comment out codes with USE_THREAD_CACHE.
* vm.c (rb_svar, rb_backref_get, rb_backref_get,
rb_lastline_get, rb_lastline_set) : moved from yarvcore.c.
* vm.c (yarv_init_redefined_flag): add a prototype and rename
yarv_opt_method_table to vm_opt_method_table.
* vm.c (rb_thread_eval): moved from yarvcore.c.
* yarvcore.c: remove unused global variables and fix to use nsdr().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-07 04:25:05 +03:00
|
|
|
ruby_iseq_disasm_insn(VALUE ret, VALUE *iseq, int pos,
|
2007-08-06 08:34:11 +04:00
|
|
|
rb_iseq_t *iseqdat, VALUE child)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
int insn = iseq[pos];
|
|
|
|
int len = insn_len(insn);
|
|
|
|
int i, j;
|
|
|
|
char *types = insn_op_types(insn);
|
|
|
|
VALUE str = rb_str_new(0, 0);
|
|
|
|
char buff[0x100];
|
|
|
|
char insn_name_buff[0x100];
|
|
|
|
|
|
|
|
strcpy(insn_name_buff, insn_name(insn));
|
|
|
|
if (0) {
|
|
|
|
for (i = 0; insn_name_buff[i]; i++) {
|
|
|
|
if (insn_name_buff[i] == '_') {
|
|
|
|
insn_name_buff[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(buff, sizeof(buff), "%04d %-16s ", pos, insn_name_buff);
|
|
|
|
rb_str_cat2(str, buff);
|
|
|
|
|
|
|
|
for (j = 0; types[j]; j++) {
|
|
|
|
char *types = insn_op_types(insn);
|
|
|
|
VALUE opstr = insn_operand_intern(iseqdat, insn, j, iseq[pos + j + 1],
|
|
|
|
len, pos, &iseq[pos + j + 2],
|
|
|
|
child);
|
|
|
|
rb_str_concat(str, opstr);
|
|
|
|
|
|
|
|
if (types[j + 1]) {
|
|
|
|
rb_str_cat2(str, ", ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-20 00:39:08 +03:00
|
|
|
if (1) {
|
2006-12-31 18:02:22 +03:00
|
|
|
int line_no = find_line_no(iseqdat, pos);
|
|
|
|
int prev = find_prev_line_no(iseqdat, pos);
|
|
|
|
if (line_no && line_no != prev) {
|
|
|
|
snprintf(buff, sizeof(buff), "%-70s(%4d)", RSTRING_PTR(str),
|
|
|
|
line_no);
|
|
|
|
str = rb_str_new2(buff);
|
|
|
|
}
|
|
|
|
}
|
2007-12-20 00:39:08 +03:00
|
|
|
else {
|
|
|
|
/* for debug */
|
|
|
|
struct iseq_insn_info_entry *entry = get_insn_info(iseqdat, pos);
|
|
|
|
snprintf(buff, sizeof(buff), "%-60s(line: %d, sp: %d)",
|
|
|
|
RSTRING_PTR(str), entry->line_no, entry->sp);
|
|
|
|
str = rb_str_new2(buff);
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
if (ret) {
|
|
|
|
rb_str_cat2(str, "\n");
|
|
|
|
rb_str_concat(ret, str);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("%s\n", RSTRING_PTR(str));
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
catch_type(int type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
2007-05-11 10:26:06 +04:00
|
|
|
case CATCH_TYPE_RESCUE:
|
2006-12-31 18:02:22 +03:00
|
|
|
return "rescue";
|
2007-05-11 10:26:06 +04:00
|
|
|
case CATCH_TYPE_ENSURE:
|
2006-12-31 18:02:22 +03:00
|
|
|
return "ensure";
|
2007-05-11 10:26:06 +04:00
|
|
|
case CATCH_TYPE_RETRY:
|
2006-12-31 18:02:22 +03:00
|
|
|
return "retry";
|
2007-05-11 10:26:06 +04:00
|
|
|
case CATCH_TYPE_BREAK:
|
2006-12-31 18:02:22 +03:00
|
|
|
return "break";
|
2007-05-11 10:26:06 +04:00
|
|
|
case CATCH_TYPE_REDO:
|
2006-12-31 18:02:22 +03:00
|
|
|
return "redo";
|
2007-05-11 10:26:06 +04:00
|
|
|
case CATCH_TYPE_NEXT:
|
2006-12-31 18:02:22 +03:00
|
|
|
return "next";
|
2007-05-11 10:26:06 +04:00
|
|
|
default:
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_bug("unknown catch type (%d)", type);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* this commit is a result of refactoring. only renaming functions,
moving definitions place, add/remove prototypes, deleting
unused variables and removing yarv.h.
This commit doesn't change any behavior of ruby/vm.
* yarv.h, common.mk: remove yarv.h (contents are moved to yarvcore.h).
* error.c, eval_intern.h: include yarvcore.h instead yarv.h
* rename some functions:
* debug.[ch]: debug_*() -> ruby_debug_*()
* iseq.c: iseq_*() -> rb_iseq_*(), ruby_iseq_disasm()
* iseq.c: node_name() -> ruby_node_name()
* vm.c: yarv_check_redefinition_opt_method() ->
rb_vm_check_redefinition_opt_method()
* some refactoring with checking -Wall.
* array.c: remove rb_ary_ptr() (unused) and remove unused
local variables.
* object.c: add a prototype of rb_mod_module_exec().
* eval_intern.h (ruby_cref): set it inline.
* eval_load.c (rb_load), yarvcore.c: yarv_load() -> rb_load_internal().
* parse.y: add a prototype of rb_parse_in_eval() (in eval.c).
* process.c: add a prototype of rb_thread_stop_timer_thread() (in thread.c).
* thread.c: remove raw_gets() function (unused) and fix some format
mismatch (format mismatchs have remained yet. this is todo).
* thread.c (rb_thread_wait_fd_rw): fix typo on label name.
* thread_pthread.ci: comment out codes with USE_THREAD_CACHE.
* vm.c (rb_svar, rb_backref_get, rb_backref_get,
rb_lastline_get, rb_lastline_set) : moved from yarvcore.c.
* vm.c (yarv_init_redefined_flag): add a prototype and rename
yarv_opt_method_table to vm_opt_method_table.
* vm.c (rb_thread_eval): moved from yarvcore.c.
* yarvcore.c: remove unused global variables and fix to use nsdr().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-07 04:25:05 +03:00
|
|
|
ruby_iseq_disasm(VALUE self)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
rb_iseq_t *iseqdat = iseq_check(self);
|
2006-12-31 18:02:22 +03:00
|
|
|
VALUE *iseq;
|
|
|
|
VALUE str = rb_str_new(0, 0);
|
|
|
|
VALUE child = rb_ary_new();
|
|
|
|
unsigned long size;
|
* vm.c: some refactoring.
* rename th_* to vm_*.
* remove unused variables functions.
* add prototypes.
* blockinlining.c, compile.c, cont.c, eval.c, eval_intern.h,
eval_jump.h, eval_load.c, inits.c, insns.def, iseq.c, parse.y,
proc.c, process.c, signal.c, thread.c, vm.c, vm_dump.c,
vm_evalbody.ci, yarvcore.c, yarvcore.h: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12603 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-24 19:42:41 +04:00
|
|
|
int i;
|
2006-12-31 18:02:22 +03:00
|
|
|
ID *tbl;
|
|
|
|
char buff[0x200];
|
2007-08-06 08:34:11 +04:00
|
|
|
enum {header_minlen = 72};
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-12-25 12:43:23 +03:00
|
|
|
rb_secure(1);
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
iseq = iseqdat->iseq;
|
2007-06-30 22:04:35 +04:00
|
|
|
size = iseqdat->iseq_size;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
rb_str_cat2(str, "== disasm: ");
|
|
|
|
|
|
|
|
rb_str_concat(str, iseq_inspect(iseqdat->self));
|
2007-08-06 08:34:11 +04:00
|
|
|
if ((i = RSTRING_LEN(str)) < header_minlen) {
|
|
|
|
rb_str_resize(str, header_minlen);
|
|
|
|
memset(RSTRING_PTR(str) + i, '=', header_minlen - i);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
rb_str_cat2(str, "\n");
|
|
|
|
|
|
|
|
/* show catch table information */
|
|
|
|
if (iseqdat->catch_table_size != 0) {
|
|
|
|
rb_str_cat2(str, "== catch table\n");
|
|
|
|
}
|
|
|
|
for (i = 0; i < iseqdat->catch_table_size; i++) {
|
2007-07-01 22:16:02 +04:00
|
|
|
struct iseq_catch_table_entry *entry = &iseqdat->catch_table[i];
|
2006-12-31 18:02:22 +03:00
|
|
|
sprintf(buff,
|
|
|
|
"| catch type: %-6s st: %04d ed: %04d sp: %04d cont: %04d\n",
|
|
|
|
catch_type((int)entry->type), (int)entry->start,
|
|
|
|
(int)entry->end, (int)entry->sp, (int)entry->cont);
|
|
|
|
rb_str_cat2(str, buff);
|
|
|
|
if (entry->iseq) {
|
* this commit is a result of refactoring. only renaming functions,
moving definitions place, add/remove prototypes, deleting
unused variables and removing yarv.h.
This commit doesn't change any behavior of ruby/vm.
* yarv.h, common.mk: remove yarv.h (contents are moved to yarvcore.h).
* error.c, eval_intern.h: include yarvcore.h instead yarv.h
* rename some functions:
* debug.[ch]: debug_*() -> ruby_debug_*()
* iseq.c: iseq_*() -> rb_iseq_*(), ruby_iseq_disasm()
* iseq.c: node_name() -> ruby_node_name()
* vm.c: yarv_check_redefinition_opt_method() ->
rb_vm_check_redefinition_opt_method()
* some refactoring with checking -Wall.
* array.c: remove rb_ary_ptr() (unused) and remove unused
local variables.
* object.c: add a prototype of rb_mod_module_exec().
* eval_intern.h (ruby_cref): set it inline.
* eval_load.c (rb_load), yarvcore.c: yarv_load() -> rb_load_internal().
* parse.y: add a prototype of rb_parse_in_eval() (in eval.c).
* process.c: add a prototype of rb_thread_stop_timer_thread() (in thread.c).
* thread.c: remove raw_gets() function (unused) and fix some format
mismatch (format mismatchs have remained yet. this is todo).
* thread.c (rb_thread_wait_fd_rw): fix typo on label name.
* thread_pthread.ci: comment out codes with USE_THREAD_CACHE.
* vm.c (rb_svar, rb_backref_get, rb_backref_get,
rb_lastline_get, rb_lastline_set) : moved from yarvcore.c.
* vm.c (yarv_init_redefined_flag): add a prototype and rename
yarv_opt_method_table to vm_opt_method_table.
* vm.c (rb_thread_eval): moved from yarvcore.c.
* yarvcore.c: remove unused global variables and fix to use nsdr().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-07 04:25:05 +03:00
|
|
|
rb_str_concat(str, ruby_iseq_disasm(entry->iseq));
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (iseqdat->catch_table_size != 0) {
|
|
|
|
rb_str_cat2(str, "|-------------------------------------"
|
|
|
|
"-----------------------------------\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* show local table information */
|
2007-02-25 04:34:33 +03:00
|
|
|
tbl = iseqdat->local_table;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
if (tbl) {
|
|
|
|
snprintf(buff, sizeof(buff),
|
* compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,
proc.c, vm.c, vm_macro.def, vm_macro.def, yarvcore.c, yarvcore.h,
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change
is to change node structure around NODE_SCOPE, NODE_ARGS. Every
scope (method/class/block) has own NODE_SCOPE node and NODE_ARGS
represents more details of arguments information. I'll write a
document about detail of node structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-03-21 14:15:15 +03:00
|
|
|
"local table (size: %d, argc: %d "
|
2007-08-16 20:25:30 +04:00
|
|
|
"[opts: %d, rest: %d, post: %d, block: %d] s%d)\n",
|
* compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,
proc.c, vm.c, vm_macro.def, vm_macro.def, yarvcore.c, yarvcore.h,
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change
is to change node structure around NODE_SCOPE, NODE_ARGS. Every
scope (method/class/block) has own NODE_SCOPE node and NODE_ARGS
represents more details of arguments information. I'll write a
document about detail of node structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-03-21 14:15:15 +03:00
|
|
|
iseqdat->local_size, iseqdat->argc,
|
2007-05-17 08:04:49 +04:00
|
|
|
iseqdat->arg_opts, iseqdat->arg_rest,
|
|
|
|
iseqdat->arg_post_len, iseqdat->arg_block,
|
2007-08-16 20:25:30 +04:00
|
|
|
iseqdat->arg_simple);
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_str_cat2(str, buff);
|
|
|
|
|
2007-02-25 04:34:33 +03:00
|
|
|
for (i = 0; i < iseqdat->local_table_size; i++) {
|
|
|
|
const char *name = rb_id2name(tbl[i]);
|
2006-12-31 18:02:22 +03:00
|
|
|
char info[0x100];
|
|
|
|
char argi[0x100] = "";
|
|
|
|
char opti[0x100] = "";
|
|
|
|
|
|
|
|
if (iseqdat->arg_opts) {
|
|
|
|
int argc = iseqdat->argc;
|
|
|
|
int opts = iseqdat->arg_opts;
|
|
|
|
if (i >= argc && i < argc + opts - 1) {
|
|
|
|
snprintf(opti, sizeof(opti), "Opt=%ld",
|
2007-07-01 22:16:02 +04:00
|
|
|
iseqdat->arg_opt_table[i - argc]);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-24 11:29:21 +04:00
|
|
|
snprintf(argi, sizeof(argi), "%s%s%s%s%s", /* arg, opts, rest, post block */
|
2006-12-31 18:02:22 +03:00
|
|
|
iseqdat->argc > i ? "Arg" : "",
|
|
|
|
opti,
|
2007-06-24 11:29:21 +04:00
|
|
|
iseqdat->arg_rest == i ? "Rest" : "",
|
|
|
|
(iseqdat->arg_post_start <= i &&
|
|
|
|
i < iseqdat->arg_post_start + iseqdat->arg_post_len) ? "Post" : "",
|
|
|
|
iseqdat->arg_block == i ? "Block" : "");
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
snprintf(info, sizeof(info), "%s%s%s%s", name ? name : "?",
|
|
|
|
*argi ? "<" : "", argi, *argi ? ">" : "");
|
|
|
|
|
|
|
|
snprintf(buff, sizeof(buff), "[%2d] %-11s",
|
|
|
|
iseqdat->local_size - i, info);
|
|
|
|
|
|
|
|
rb_str_cat2(str, buff);
|
|
|
|
}
|
|
|
|
rb_str_cat2(str, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* show each line */
|
|
|
|
for (i = 0; i < size;) {
|
* this commit is a result of refactoring. only renaming functions,
moving definitions place, add/remove prototypes, deleting
unused variables and removing yarv.h.
This commit doesn't change any behavior of ruby/vm.
* yarv.h, common.mk: remove yarv.h (contents are moved to yarvcore.h).
* error.c, eval_intern.h: include yarvcore.h instead yarv.h
* rename some functions:
* debug.[ch]: debug_*() -> ruby_debug_*()
* iseq.c: iseq_*() -> rb_iseq_*(), ruby_iseq_disasm()
* iseq.c: node_name() -> ruby_node_name()
* vm.c: yarv_check_redefinition_opt_method() ->
rb_vm_check_redefinition_opt_method()
* some refactoring with checking -Wall.
* array.c: remove rb_ary_ptr() (unused) and remove unused
local variables.
* object.c: add a prototype of rb_mod_module_exec().
* eval_intern.h (ruby_cref): set it inline.
* eval_load.c (rb_load), yarvcore.c: yarv_load() -> rb_load_internal().
* parse.y: add a prototype of rb_parse_in_eval() (in eval.c).
* process.c: add a prototype of rb_thread_stop_timer_thread() (in thread.c).
* thread.c: remove raw_gets() function (unused) and fix some format
mismatch (format mismatchs have remained yet. this is todo).
* thread.c (rb_thread_wait_fd_rw): fix typo on label name.
* thread_pthread.ci: comment out codes with USE_THREAD_CACHE.
* vm.c (rb_svar, rb_backref_get, rb_backref_get,
rb_lastline_get, rb_lastline_set) : moved from yarvcore.c.
* vm.c (yarv_init_redefined_flag): add a prototype and rename
yarv_opt_method_table to vm_opt_method_table.
* vm.c (rb_thread_eval): moved from yarvcore.c.
* yarvcore.c: remove unused global variables and fix to use nsdr().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-07 04:25:05 +03:00
|
|
|
i += ruby_iseq_disasm_insn(str, iseq, i, iseqdat, child);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < RARRAY_LEN(child); i++) {
|
|
|
|
VALUE isv = rb_ary_entry(child, i);
|
* this commit is a result of refactoring. only renaming functions,
moving definitions place, add/remove prototypes, deleting
unused variables and removing yarv.h.
This commit doesn't change any behavior of ruby/vm.
* yarv.h, common.mk: remove yarv.h (contents are moved to yarvcore.h).
* error.c, eval_intern.h: include yarvcore.h instead yarv.h
* rename some functions:
* debug.[ch]: debug_*() -> ruby_debug_*()
* iseq.c: iseq_*() -> rb_iseq_*(), ruby_iseq_disasm()
* iseq.c: node_name() -> ruby_node_name()
* vm.c: yarv_check_redefinition_opt_method() ->
rb_vm_check_redefinition_opt_method()
* some refactoring with checking -Wall.
* array.c: remove rb_ary_ptr() (unused) and remove unused
local variables.
* object.c: add a prototype of rb_mod_module_exec().
* eval_intern.h (ruby_cref): set it inline.
* eval_load.c (rb_load), yarvcore.c: yarv_load() -> rb_load_internal().
* parse.y: add a prototype of rb_parse_in_eval() (in eval.c).
* process.c: add a prototype of rb_thread_stop_timer_thread() (in thread.c).
* thread.c: remove raw_gets() function (unused) and fix some format
mismatch (format mismatchs have remained yet. this is todo).
* thread.c (rb_thread_wait_fd_rw): fix typo on label name.
* thread_pthread.ci: comment out codes with USE_THREAD_CACHE.
* vm.c (rb_svar, rb_backref_get, rb_backref_get,
rb_lastline_get, rb_lastline_set) : moved from yarvcore.c.
* vm.c (yarv_init_redefined_flag): add a prototype and rename
yarv_opt_method_table to vm_opt_method_table.
* vm.c (rb_thread_eval): moved from yarvcore.c.
* yarvcore.c: remove unused global variables and fix to use nsdr().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-07 04:25:05 +03:00
|
|
|
rb_str_concat(str, ruby_iseq_disasm(isv));
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2007-12-24 12:09:21 +03:00
|
|
|
static VALUE
|
|
|
|
iseq_s_disasm(VALUE klass, VALUE body)
|
|
|
|
{
|
|
|
|
extern NODE *rb_method_body(VALUE body);
|
|
|
|
NODE *node;
|
|
|
|
VALUE ret = Qnil;
|
|
|
|
|
2007-12-25 12:43:23 +03:00
|
|
|
rb_secure(1);
|
|
|
|
|
2007-12-24 12:09:21 +03:00
|
|
|
if ((node = rb_method_body(body)) != 0) {
|
|
|
|
if (nd_type(node) == RUBY_VM_METHOD_NODE) {
|
|
|
|
VALUE iseqval = (VALUE)node->nd_body;
|
|
|
|
ret = ruby_iseq_disasm(iseqval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
* 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 12:12:18 +04:00
|
|
|
const char *
|
* this commit is a result of refactoring. only renaming functions,
moving definitions place, add/remove prototypes, deleting
unused variables and removing yarv.h.
This commit doesn't change any behavior of ruby/vm.
* yarv.h, common.mk: remove yarv.h (contents are moved to yarvcore.h).
* error.c, eval_intern.h: include yarvcore.h instead yarv.h
* rename some functions:
* debug.[ch]: debug_*() -> ruby_debug_*()
* iseq.c: iseq_*() -> rb_iseq_*(), ruby_iseq_disasm()
* iseq.c: node_name() -> ruby_node_name()
* vm.c: yarv_check_redefinition_opt_method() ->
rb_vm_check_redefinition_opt_method()
* some refactoring with checking -Wall.
* array.c: remove rb_ary_ptr() (unused) and remove unused
local variables.
* object.c: add a prototype of rb_mod_module_exec().
* eval_intern.h (ruby_cref): set it inline.
* eval_load.c (rb_load), yarvcore.c: yarv_load() -> rb_load_internal().
* parse.y: add a prototype of rb_parse_in_eval() (in eval.c).
* process.c: add a prototype of rb_thread_stop_timer_thread() (in thread.c).
* thread.c: remove raw_gets() function (unused) and fix some format
mismatch (format mismatchs have remained yet. this is todo).
* thread.c (rb_thread_wait_fd_rw): fix typo on label name.
* thread_pthread.ci: comment out codes with USE_THREAD_CACHE.
* vm.c (rb_svar, rb_backref_get, rb_backref_get,
rb_lastline_get, rb_lastline_set) : moved from yarvcore.c.
* vm.c (yarv_init_redefined_flag): add a prototype and rename
yarv_opt_method_table to vm_opt_method_table.
* vm.c (rb_thread_eval): moved from yarvcore.c.
* yarvcore.c: remove unused global variables and fix to use nsdr().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-07 04:25:05 +03:00
|
|
|
ruby_node_name(int node)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
switch (node) {
|
2007-08-06 08:09:56 +04:00
|
|
|
#include "node_name.inc"
|
2007-05-11 10:26:06 +04:00
|
|
|
default:
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_bug("unknown node (%d)", node);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DECL_SYMBOL(name) \
|
|
|
|
static VALUE sym_##name
|
|
|
|
|
|
|
|
#define INIT_SYMBOL(name) \
|
|
|
|
sym_##name = ID2SYM(rb_intern(#name))
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
register_label(struct st_table *table, int idx)
|
|
|
|
{
|
|
|
|
VALUE sym;
|
|
|
|
char buff[0x20];
|
|
|
|
|
|
|
|
snprintf(buff, 0x20, "label_%u", idx);
|
|
|
|
sym = ID2SYM(rb_intern(buff));
|
|
|
|
st_insert(table, idx, sym);
|
|
|
|
return sym;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
exception_type2symbol(VALUE type)
|
|
|
|
{
|
|
|
|
ID id;
|
|
|
|
switch(type) {
|
|
|
|
case CATCH_TYPE_RESCUE: id = rb_intern("rescue"); break;
|
|
|
|
case CATCH_TYPE_ENSURE: id = rb_intern("ensure"); break;
|
|
|
|
case CATCH_TYPE_RETRY: id = rb_intern("retry"); break;
|
|
|
|
case CATCH_TYPE_BREAK: id = rb_intern("break"); break;
|
|
|
|
case CATCH_TYPE_REDO: id = rb_intern("redo"); break;
|
|
|
|
case CATCH_TYPE_NEXT: id = rb_intern("next"); break;
|
|
|
|
default:
|
|
|
|
rb_bug("...");
|
|
|
|
}
|
|
|
|
return ID2SYM(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
cdhash_each(VALUE key, VALUE value, VALUE ary)
|
|
|
|
{
|
|
|
|
rb_ary_push(ary, key);
|
|
|
|
rb_ary_push(ary, value);
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
iseq_data_to_ary(rb_iseq_t *iseq)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
* 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 08:25:46 +04:00
|
|
|
int i, pos, line = 0;
|
2006-12-31 18:02:22 +03:00
|
|
|
VALUE *seq;
|
|
|
|
|
|
|
|
VALUE val = rb_ary_new();
|
|
|
|
VALUE type; /* Symbol */
|
|
|
|
VALUE locals = rb_ary_new();
|
|
|
|
VALUE args = rb_ary_new();
|
|
|
|
VALUE body = rb_ary_new(); /* [[:insn1, ...], ...] */
|
|
|
|
VALUE nbody;
|
|
|
|
VALUE exception = rb_ary_new(); /* [[....]] */
|
2007-07-02 01:43:30 +04:00
|
|
|
VALUE misc = rb_hash_new();
|
2007-05-11 10:26:06 +04:00
|
|
|
|
* 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 08:25:46 +04:00
|
|
|
static VALUE insn_syms[VM_INSTRUCTION_SIZE];
|
2006-12-31 18:02:22 +03:00
|
|
|
struct st_table *labels_table = st_init_numtable();
|
2007-05-11 10:26:06 +04:00
|
|
|
|
2007-07-02 03:57:04 +04:00
|
|
|
DECL_SYMBOL(top);
|
2006-12-31 18:02:22 +03:00
|
|
|
DECL_SYMBOL(method);
|
|
|
|
DECL_SYMBOL(block);
|
|
|
|
DECL_SYMBOL(class);
|
|
|
|
DECL_SYMBOL(rescue);
|
|
|
|
DECL_SYMBOL(ensure);
|
|
|
|
DECL_SYMBOL(eval);
|
|
|
|
|
2007-07-02 03:57:04 +04:00
|
|
|
if (sym_top == 0) {
|
2006-12-31 18:02:22 +03:00
|
|
|
int i;
|
* 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 08:25:46 +04:00
|
|
|
for (i=0; i<VM_INSTRUCTION_SIZE; i++) {
|
2006-12-31 18:02:22 +03:00
|
|
|
insn_syms[i] = ID2SYM(rb_intern(insn_name(i)));
|
|
|
|
}
|
2007-07-02 03:57:04 +04:00
|
|
|
INIT_SYMBOL(top);
|
2006-12-31 18:02:22 +03:00
|
|
|
INIT_SYMBOL(method);
|
|
|
|
INIT_SYMBOL(block);
|
|
|
|
INIT_SYMBOL(class);
|
|
|
|
INIT_SYMBOL(rescue);
|
|
|
|
INIT_SYMBOL(ensure);
|
|
|
|
INIT_SYMBOL(eval);
|
|
|
|
}
|
2007-05-11 10:26:06 +04:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
/* type */
|
|
|
|
switch(iseq->type) {
|
2007-07-02 03:57:04 +04:00
|
|
|
case ISEQ_TYPE_TOP: type = sym_top; break;
|
|
|
|
case ISEQ_TYPE_METHOD: type = sym_method; break;
|
|
|
|
case ISEQ_TYPE_BLOCK: type = sym_block; break;
|
|
|
|
case ISEQ_TYPE_CLASS: type = sym_class; break;
|
|
|
|
case ISEQ_TYPE_RESCUE: type = sym_rescue; break;
|
|
|
|
case ISEQ_TYPE_ENSURE: type = sym_ensure; break;
|
|
|
|
case ISEQ_TYPE_EVAL: type = sym_eval; break;
|
2006-12-31 18:02:22 +03:00
|
|
|
default: rb_bug("unsupported iseq type");
|
|
|
|
};
|
|
|
|
|
|
|
|
/* locals */
|
2007-02-25 04:34:33 +03:00
|
|
|
for (i=0; i<iseq->local_table_size; i++) {
|
|
|
|
ID lid = iseq->local_table[i];
|
2006-12-31 18:02:22 +03:00
|
|
|
if (lid) {
|
2007-05-11 10:26:06 +04:00
|
|
|
if (rb_id2str(lid)) rb_ary_push(locals, ID2SYM(lid));
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_ary_push(locals, ID2SYM(rb_intern("#arg_rest")));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* args */
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* [argc, # argc
|
|
|
|
* [label1, label2, ...] # opts
|
2007-07-02 01:43:30 +04:00
|
|
|
* rest index,
|
|
|
|
* post_len
|
|
|
|
* post_start
|
|
|
|
* block index,
|
|
|
|
* simple,
|
2006-12-31 18:02:22 +03:00
|
|
|
* ]
|
|
|
|
*/
|
|
|
|
VALUE arg_opt_labels = rb_ary_new();
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for (j=0; j<iseq->arg_opts; j++) {
|
|
|
|
rb_ary_push(arg_opt_labels,
|
2007-07-01 22:16:02 +04:00
|
|
|
register_label(labels_table, iseq->arg_opt_table[j]));
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* commit */
|
2007-07-02 01:43:30 +04:00
|
|
|
if (iseq->arg_simple == 1) {
|
2006-12-31 18:02:22 +03:00
|
|
|
args = INT2FIX(iseq->argc);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_ary_push(args, INT2FIX(iseq->argc));
|
|
|
|
rb_ary_push(args, arg_opt_labels);
|
2007-07-02 01:43:30 +04:00
|
|
|
rb_ary_push(args, INT2FIX(iseq->arg_post_len));
|
|
|
|
rb_ary_push(args, INT2FIX(iseq->arg_post_start));
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_ary_push(args, INT2FIX(iseq->arg_rest));
|
|
|
|
rb_ary_push(args, INT2FIX(iseq->arg_block));
|
2007-07-02 01:43:30 +04:00
|
|
|
rb_ary_push(args, INT2FIX(iseq->arg_simple));
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* body */
|
2007-06-30 22:04:35 +04:00
|
|
|
for (seq = iseq->iseq; seq < iseq->iseq + iseq->iseq_size; ) {
|
2006-12-31 18:02:22 +03:00
|
|
|
VALUE insn = *seq++;
|
|
|
|
int j, len = insn_len(insn);
|
|
|
|
VALUE *nseq = seq + len - 1;
|
2007-05-11 10:26:06 +04:00
|
|
|
VALUE ary = rb_ary_new2(len);
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_ary_push(ary, insn_syms[insn]);
|
|
|
|
for (j=0; j<len-1; j++, seq++) {
|
|
|
|
switch (insn_op_type(insn, j)) {
|
|
|
|
case TS_OFFSET: {
|
2007-05-11 10:26:06 +04:00
|
|
|
unsigned int idx = nseq - iseq->iseq + *seq;
|
|
|
|
rb_ary_push(ary, register_label(labels_table, idx));
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case TS_LINDEX:
|
|
|
|
case TS_DINDEX:
|
|
|
|
case TS_NUM:
|
|
|
|
rb_ary_push(ary, INT2FIX(*seq));
|
|
|
|
break;
|
|
|
|
case TS_VALUE:
|
|
|
|
rb_ary_push(ary, *seq);
|
|
|
|
break;
|
|
|
|
case TS_ISEQ:
|
|
|
|
{
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
rb_iseq_t *iseq = (rb_iseq_t *)*seq;
|
2006-12-31 18:02:22 +03:00
|
|
|
if (iseq) {
|
|
|
|
VALUE val = iseq_data_to_ary(iseq);
|
|
|
|
rb_ary_push(ary, val);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_ary_push(ary, Qnil);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TS_GENTRY:
|
|
|
|
{
|
|
|
|
struct global_entry *entry = (struct global_entry *)*seq;
|
|
|
|
rb_ary_push(ary, ID2SYM(entry->id));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TS_IC:
|
|
|
|
rb_ary_push(ary, Qnil);
|
|
|
|
break;
|
|
|
|
case TS_ID:
|
|
|
|
rb_ary_push(ary, ID2SYM(*seq));
|
|
|
|
break;
|
|
|
|
case TS_CDHASH:
|
|
|
|
{
|
|
|
|
VALUE hash = *seq;
|
|
|
|
VALUE val = rb_ary_new();
|
|
|
|
int i;
|
2007-05-11 10:26:06 +04:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_hash_foreach(hash, cdhash_each, val);
|
|
|
|
|
|
|
|
for (i=0; i<RARRAY_LEN(val); i+=2) {
|
|
|
|
VALUE pos = FIX2INT(rb_ary_entry(val, i+1));
|
|
|
|
unsigned int idx = nseq - iseq->iseq + pos;
|
|
|
|
|
|
|
|
rb_ary_store(val, i+1,
|
|
|
|
register_label(labels_table, idx));
|
|
|
|
}
|
|
|
|
rb_ary_push(ary, val);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rb_bug("unknown operand: %c", insn_op_type(insn, j));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rb_ary_push(body, ary);
|
|
|
|
}
|
|
|
|
|
|
|
|
nbody = body;
|
|
|
|
|
|
|
|
/* exception */
|
|
|
|
for (i=0; i<iseq->catch_table_size; i++) {
|
|
|
|
VALUE ary = rb_ary_new();
|
2007-07-01 22:16:02 +04:00
|
|
|
struct iseq_catch_table_entry *entry = &iseq->catch_table[i];
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_ary_push(ary, exception_type2symbol(entry->type));
|
|
|
|
if (entry->iseq) {
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 22:00:03 +03:00
|
|
|
rb_iseq_t *eiseq;
|
2006-12-31 18:02:22 +03:00
|
|
|
GetISeqPtr(entry->iseq, eiseq);
|
|
|
|
rb_ary_push(ary, iseq_data_to_ary(eiseq));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_ary_push(ary, Qnil);
|
|
|
|
}
|
|
|
|
rb_ary_push(ary, register_label(labels_table, entry->start));
|
|
|
|
rb_ary_push(ary, register_label(labels_table, entry->end));
|
|
|
|
rb_ary_push(ary, register_label(labels_table, entry->cont));
|
|
|
|
rb_ary_push(ary, INT2FIX(entry->sp));
|
|
|
|
rb_ary_push(exception, ary);
|
|
|
|
}
|
|
|
|
|
2007-07-02 01:43:30 +04:00
|
|
|
/* make body with labels and insert line number */
|
2006-12-31 18:02:22 +03:00
|
|
|
body = rb_ary_new();
|
|
|
|
|
|
|
|
for (i=0, pos=0; i<RARRAY_LEN(nbody); i++) {
|
|
|
|
VALUE ary = RARRAY_PTR(nbody)[i];
|
|
|
|
VALUE label;
|
|
|
|
|
|
|
|
if (st_lookup(labels_table, pos, &label)) {
|
|
|
|
rb_ary_push(body, label);
|
|
|
|
}
|
|
|
|
|
2007-07-02 01:43:30 +04:00
|
|
|
if (iseq->insn_info_table[i].line_no != line) {
|
|
|
|
line = iseq->insn_info_table[i].line_no;
|
|
|
|
rb_ary_push(body, INT2FIX(line));
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_ary_push(body, ary);
|
|
|
|
pos += RARRAY_LEN(ary);
|
|
|
|
}
|
|
|
|
|
|
|
|
st_free_table(labels_table);
|
|
|
|
|
2007-07-02 01:43:30 +04:00
|
|
|
rb_hash_aset(misc, ID2SYM(rb_intern("arg_size")), INT2FIX(iseq->arg_size));
|
|
|
|
rb_hash_aset(misc, ID2SYM(rb_intern("local_size")), INT2FIX(iseq->local_size));
|
|
|
|
rb_hash_aset(misc, ID2SYM(rb_intern("stack_max")), INT2FIX(iseq->stack_max));
|
2007-05-11 10:26:06 +04:00
|
|
|
|
2007-07-02 01:43:30 +04:00
|
|
|
/*
|
|
|
|
* [:magic, :major_version, :minor_version, :format_type, :misc,
|
|
|
|
* :name, :filename, :type, :locals, :args,
|
|
|
|
* :catch_table, :bytecode]
|
2006-12-31 18:02:22 +03:00
|
|
|
*/
|
* 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 08:25:46 +04:00
|
|
|
rb_ary_push(val, rb_str_new2("YARVInstructionSequence/SimpleDataFormat"));
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_ary_push(val, INT2FIX(1));
|
|
|
|
rb_ary_push(val, INT2FIX(1));
|
|
|
|
rb_ary_push(val, INT2FIX(1));
|
2007-07-02 01:43:30 +04:00
|
|
|
rb_ary_push(val, misc);
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_ary_push(val, iseq->name);
|
2007-02-25 04:34:33 +03:00
|
|
|
rb_ary_push(val, iseq->filename);
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_ary_push(val, type);
|
|
|
|
rb_ary_push(val, locals);
|
|
|
|
rb_ary_push(val, args);
|
|
|
|
rb_ary_push(val, exception);
|
|
|
|
rb_ary_push(val, body);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct st_table *
|
|
|
|
insn_make_insn_table(void)
|
|
|
|
{
|
|
|
|
struct st_table *table;
|
|
|
|
int i;
|
|
|
|
table = st_init_numtable();
|
|
|
|
|
* 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 08:25:46 +04:00
|
|
|
for (i=0; i<VM_INSTRUCTION_SIZE; i++) {
|
2006-12-31 18:02:22 +03:00
|
|
|
st_insert(table, ID2SYM(rb_intern(insn_name(i))), i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return table;
|
|
|
|
}
|
|
|
|
|
2007-07-01 22:16:02 +04:00
|
|
|
/* ruby2cext */
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_iseq_build_for_ruby2cext(
|
|
|
|
const rb_iseq_t *iseq_template,
|
|
|
|
const rb_insn_func_t *func,
|
|
|
|
const struct iseq_insn_info_entry *insn_info_table,
|
|
|
|
const char **local_table,
|
|
|
|
const VALUE *arg_opt_table,
|
|
|
|
const struct iseq_catch_table_entry *catch_table,
|
|
|
|
const char *name,
|
|
|
|
const char *filename)
|
|
|
|
{
|
2007-07-02 16:49:35 +04:00
|
|
|
int i;
|
2007-07-01 22:16:02 +04:00
|
|
|
VALUE iseqval = iseq_alloc(rb_cISeq);
|
|
|
|
rb_iseq_t *iseq;
|
|
|
|
GetISeqPtr(iseqval, iseq);
|
|
|
|
|
|
|
|
/* copy iseq */
|
|
|
|
*iseq = *iseq_template;
|
|
|
|
iseq->name = rb_str_new2(name);
|
|
|
|
iseq->filename = rb_str_new2(filename);
|
|
|
|
iseq->mark_ary = rb_ary_new();
|
2007-07-04 00:12:55 +04:00
|
|
|
iseq->self = iseqval;
|
2007-07-01 22:16:02 +04:00
|
|
|
|
2007-07-02 16:49:35 +04:00
|
|
|
iseq->iseq = ALLOC_N(VALUE, iseq->iseq_size);
|
|
|
|
|
|
|
|
for (i=0; i<iseq->iseq_size; i+=2) {
|
|
|
|
iseq->iseq[i] = BIN(opt_call_c_function);
|
|
|
|
iseq->iseq[i+1] = (VALUE)func;
|
|
|
|
}
|
|
|
|
|
|
|
|
iseq_translate_threaded_code(iseq);
|
|
|
|
|
2007-07-01 22:16:02 +04:00
|
|
|
#define ALLOC_AND_COPY(dst, src, type, size) do { \
|
|
|
|
if (size) { \
|
|
|
|
(dst) = ALLOC_N(type, (size)); \
|
|
|
|
MEMCPY((dst), (src), type, (size)); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
ALLOC_AND_COPY(iseq->insn_info_table, insn_info_table,
|
|
|
|
struct iseq_insn_info_entry, iseq->insn_info_size);
|
|
|
|
|
|
|
|
ALLOC_AND_COPY(iseq->catch_table, catch_table,
|
|
|
|
struct iseq_catch_table_entry, iseq->catch_table_size);
|
|
|
|
|
|
|
|
ALLOC_AND_COPY(iseq->arg_opt_table, arg_opt_table,
|
|
|
|
VALUE, iseq->arg_opts);
|
|
|
|
|
2007-07-04 00:12:55 +04:00
|
|
|
set_relation(iseq, 0);
|
|
|
|
|
2007-07-01 22:16:02 +04:00
|
|
|
return iseqval;
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
Init_ISeq(void)
|
|
|
|
{
|
* 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 08:25:46 +04:00
|
|
|
/* declare ::VM::InstructionSequence */
|
2007-01-17 11:48:52 +03:00
|
|
|
rb_cISeq = rb_define_class_under(rb_cVM, "InstructionSequence", rb_cObject);
|
|
|
|
rb_define_alloc_func(rb_cISeq, iseq_alloc);
|
|
|
|
rb_define_method(rb_cISeq, "inspect", iseq_inspect, 0);
|
* this commit is a result of refactoring. only renaming functions,
moving definitions place, add/remove prototypes, deleting
unused variables and removing yarv.h.
This commit doesn't change any behavior of ruby/vm.
* yarv.h, common.mk: remove yarv.h (contents are moved to yarvcore.h).
* error.c, eval_intern.h: include yarvcore.h instead yarv.h
* rename some functions:
* debug.[ch]: debug_*() -> ruby_debug_*()
* iseq.c: iseq_*() -> rb_iseq_*(), ruby_iseq_disasm()
* iseq.c: node_name() -> ruby_node_name()
* vm.c: yarv_check_redefinition_opt_method() ->
rb_vm_check_redefinition_opt_method()
* some refactoring with checking -Wall.
* array.c: remove rb_ary_ptr() (unused) and remove unused
local variables.
* object.c: add a prototype of rb_mod_module_exec().
* eval_intern.h (ruby_cref): set it inline.
* eval_load.c (rb_load), yarvcore.c: yarv_load() -> rb_load_internal().
* parse.y: add a prototype of rb_parse_in_eval() (in eval.c).
* process.c: add a prototype of rb_thread_stop_timer_thread() (in thread.c).
* thread.c: remove raw_gets() function (unused) and fix some format
mismatch (format mismatchs have remained yet. this is todo).
* thread.c (rb_thread_wait_fd_rw): fix typo on label name.
* thread_pthread.ci: comment out codes with USE_THREAD_CACHE.
* vm.c (rb_svar, rb_backref_get, rb_backref_get,
rb_lastline_get, rb_lastline_set) : moved from yarvcore.c.
* vm.c (yarv_init_redefined_flag): add a prototype and rename
yarv_opt_method_table to vm_opt_method_table.
* vm.c (rb_thread_eval): moved from yarvcore.c.
* yarvcore.c: remove unused global variables and fix to use nsdr().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-07 04:25:05 +03:00
|
|
|
rb_define_method(rb_cISeq, "disasm", ruby_iseq_disasm, 0);
|
2007-12-24 12:09:21 +03:00
|
|
|
rb_define_method(rb_cISeq, "disassemble", ruby_iseq_disasm, 0);
|
2007-01-17 11:48:52 +03:00
|
|
|
rb_define_method(rb_cISeq, "to_a", iseq_to_a, 0);
|
|
|
|
rb_define_method(rb_cISeq, "eval", iseq_eval, 0);
|
|
|
|
|
2007-12-24 12:09:21 +03:00
|
|
|
/* disable this feature because there is no verifier. */
|
|
|
|
/* rb_define_singleton_method(rb_cISeq, "load", iseq_s_load, -1); */
|
|
|
|
|
2007-01-17 11:48:52 +03:00
|
|
|
rb_define_singleton_method(rb_cISeq, "compile", iseq_s_compile, -1);
|
|
|
|
rb_define_singleton_method(rb_cISeq, "new", iseq_s_compile, -1);
|
|
|
|
rb_define_singleton_method(rb_cISeq, "compile_file", iseq_s_compile_file, -1);
|
2007-12-24 12:09:21 +03:00
|
|
|
rb_define_singleton_method(rb_cISeq, "compile_option", iseq_s_compile_option_get, 0);
|
|
|
|
rb_define_singleton_method(rb_cISeq, "compile_option=", iseq_s_compile_option_set, 1);
|
|
|
|
rb_define_singleton_method(rb_cISeq, "disasm", iseq_s_disasm, 1);
|
|
|
|
rb_define_singleton_method(rb_cISeq, "disassemble", iseq_s_disasm, 1);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|