2006-12-31 18:02:22 +03:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
iseq.c -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
created at: 2006-07-11(Tue) 09:00:03 +0900
|
|
|
|
|
|
|
|
Copyright (C) 2006 Koichi Sasada
|
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
* internal.h: declare internal functions here.
* node.h: declare NODE dependent internal functions here.
* iseq.h: declare rb_iseq_t dependent internal functions here.
* vm_core.h: declare rb_thread_t dependent internal functions here.
* bignum.c, class.c, compile.c, complex.c, cont.c, dir.c, encoding.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c, io.c,
iseq.c, load.c, marshal.c, math.c, numeric.c, object.c, parse.y,
proc.c, process.c, range.c, rational.c, re.c, ruby.c, string.c,
thread.c, time.c, transcode.c, variable.c, vm.c,
tool/compile_prelude.rb: don't declare internal functions declared
in above headers. include above headers if required.
Note that rb_thread_mark() was declared as
void rb_thread_mark(rb_thread_t *th) in cont.c but defined as
void rb_thread_mark(void *ptr) in vm.c. Now it is declared as
the later in internal.h.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32156 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-18 02:43:38 +04:00
|
|
|
#include "internal.h"
|
2014-11-15 14:49:06 +03:00
|
|
|
#include "ruby/util.h"
|
* iseq.c, vm_eval.c: set th->base_block properly.
th->base_block is information for (a) parsing, (b) compiling
and (c) setting up the frame to execute the program passed by
`eval' method. For example, (1) parser need to know up-level
variables to detect it is variable or method without paren.
Befor (a), (b) and (c), VM set th->base_block by passed bindng
(or previous frame information). After execute (a), (b) and (c),
VM should clear th->base_block. However, if (a), (b) or (c)
raises an exception, then th->base_block is not cleared.
Problem is that the uncleared value th->balo_block is used for
irrelevant iseq compilation. It causes SEGV or critical error.
I tried to solve this problem: to clear them before exception,
but finally I found out that it is difficult to do it (Ruby
program can be run in many places).
Because of this background, I set th->base_block before
compiling iseq and restore it after compiling.
Basically, th->base_block is dirty hack (similar to global
variable) and this patch is also dirty.
* bootstraptest/test_eval.rb: add a test for above.
* internal.h: remove unused decl.
* iseq.c (rb_iseq_compile_with_option): add base_block parameter.
set th->base_block before compation and restore it after
compilation.
* ruby.c (require_libraries): pass 0 as base_block instead of
setting th->base_block
* tool/compile_prelude.rb (prelude_eval): apply above changes.
* vm.c, vm_eval.c: ditto.
* vm_core.h: add comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-22 13:32:56 +04:00
|
|
|
#include "eval_intern.h"
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2014-12-16 04:14:27 +03:00
|
|
|
#ifdef HAVE_DLADDR
|
|
|
|
# include <dlfcn.h>
|
|
|
|
#endif
|
|
|
|
|
2009-10-16 08:40:11 +04:00
|
|
|
/* #define RUBY_MARK_FREE_DEBUG 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
|
|
|
#include "gc.h"
|
|
|
|
#include "vm_core.h"
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
#include "iseq.h"
|
* 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
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
#include "insns.inc"
|
|
|
|
#include "insns_info.inc"
|
|
|
|
|
2012-08-08 11:52:19 +04:00
|
|
|
#define ISEQ_MAJOR_VERSION 2
|
2014-11-03 02:14:21 +03:00
|
|
|
#define ISEQ_MINOR_VERSION 2
|
2010-10-31 04:42:54 +03:00
|
|
|
|
2007-01-17 11:48:52 +03:00
|
|
|
VALUE rb_cISeq;
|
|
|
|
|
2009-02-12 13:42:36 +03:00
|
|
|
#define hidden_obj_p(obj) (!SPECIAL_CONST_P(obj) && !RBASIC(obj)->klass)
|
|
|
|
|
2009-02-18 08:33:36 +03:00
|
|
|
static inline VALUE
|
|
|
|
obj_resurrect(VALUE obj)
|
|
|
|
{
|
|
|
|
if (hidden_obj_p(obj)) {
|
|
|
|
switch (BUILTIN_TYPE(obj)) {
|
|
|
|
case T_STRING:
|
|
|
|
obj = rb_str_resurrect(obj);
|
|
|
|
break;
|
|
|
|
case T_ARRAY:
|
|
|
|
obj = rb_ary_resurrect(obj);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
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) {
|
* rewrite method/block parameter fitting logic to optimize
keyword arguments/parameters and a splat argument.
[Feature #10440] (Details are described in this ticket)
Most of complex part is moved to vm_args.c.
Now, ISeq#to_a does not catch up new instruction format.
* vm_core.h: change iseq data structures.
* introduce rb_call_info_kw_arg_t to represent keyword arguments.
* add rb_call_info_t::kw_arg.
* rename rb_iseq_t::arg_post_len to rb_iseq_t::arg_post_num.
* rename rb_iseq_t::arg_keywords to arg_keyword_num.
* rename rb_iseq_t::arg_keyword to rb_iseq_t::arg_keyword_bits.
to represent keyword bitmap parameter index.
This bitmap parameter shows that which keyword parameters are given
or not given (0 for given).
It is refered by `checkkeyword' instruction described bellow.
* rename rb_iseq_t::arg_keyword_check to rb_iseq_t::arg_keyword_rest
to represent keyword rest parameter index.
* add rb_iseq_t::arg_keyword_default_values to represent default
keyword values.
* rename VM_CALL_ARGS_SKIP_SETUP to VM_CALL_ARGS_SIMPLE
to represent
(ci->flag & (SPLAT|BLOCKARG)) &&
ci->blockiseq == NULL &&
ci->kw_arg == NULL.
* vm_insnhelper.c, vm_args.c: rewrite with refactoring.
* rewrite splat argument code.
* rewrite keyword arguments/parameters code.
* merge method and block parameter fitting code into one code base.
* vm.c, vm_eval.c: catch up these changes.
* compile.c (new_callinfo): callinfo requires kw_arg parameter.
* compile.c (compile_array_): check the last argument Hash object or
not. If Hash object and all keys are Symbol literals, they are
compiled to keyword arguments.
* insns.def (checkkeyword): add new instruction.
This instruction check the availability of corresponding keyword.
For example, a method "def foo k1: 'v1'; end" is cimpiled to the
following instructions.
0000 checkkeyword 2, 0 # check k1 is given.
0003 branchif 9 # if given, jump to address #9
0005 putstring "v1"
0007 setlocal_OP__WC__0 3 # k1 = 'v1'
0009 trace 8
0011 putnil
0012 trace 16
0014 leave
* insns.def (opt_send_simple): removed and add new instruction
"opt_send_without_block".
* parse.y (new_args_tail_gen): reorder variables.
Before this patch, a method "def foo(k1: 1, kr1:, k2: 2, **krest, &b)"
has parameter variables "k1, kr1, k2, &b, internal_id, krest",
but this patch reorders to "kr1, k1, k2, internal_id, krest, &b".
(locate a block variable at last)
* parse.y (vtable_pop): added.
This function remove latest `n' variables from vtable.
* iseq.c: catch up iseq data changes.
* proc.c: ditto.
* class.c (keyword_error): export as rb_keyword_error().
* common.mk: depend vm_args.c for vm.o.
* hash.c (rb_hash_has_key): export.
* internal.h: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-02 21:02:55 +03:00
|
|
|
int i;
|
2006-12-31 18:02:22 +03:00
|
|
|
iseq = ptr;
|
2008-08-11 12:13:42 +04:00
|
|
|
if (!iseq->orig) {
|
2009-10-16 08:40:11 +04:00
|
|
|
/* It's possible that strings are freed */
|
|
|
|
if (0) {
|
2012-06-04 06:49:37 +04:00
|
|
|
RUBY_GC_INFO("%s @ %s\n", RSTRING_PTR(iseq->location.label),
|
|
|
|
RSTRING_PTR(iseq->location.path));
|
2009-10-16 08:40:11 +04:00
|
|
|
}
|
|
|
|
|
compile: translate iseq in-place
running "ruby -rpp -e 'pp GC.stat'", a reduction in
malloc usage is shown:
before:
:malloc_increase=>118784,
:oldmalloc_increase=>1178736,
after:
:malloc_increase=>99832,
:oldmalloc_increase=>1031976,
For "ruby -e exit", valgrind reports over 300K reduction in
overall allocations (and unnecessary memory copies).
before:
total heap usage: 49,622 allocs, 20,492 frees, 8,697,493 bytes allocated
after:
total heap usage: 48,935 allocs, 19,805 frees, 8,373,773 bytes allocated
(numbers from x86-64)
v2 changes based on ko1 recommendations [ruby-core:64883]:
- squashed in-place direct thread translation to avoid alloc+copy
- renamed rb_iseq_untranslate_threaded_code to rb_iseq_original_iseq,
cache new iseq->iseq_original field.
* compile.c (rb_iseq_translate_threaded_code): modify in-place w/o copy
(rb_vm_addr2insn): new function for debug
(rb_iseq_original_iseq): ditto
(iseq_set_sequence): assign iseq_encoded directly
[Feature #10185]
* vm_core (rb_iseq_t): move original ->iseq to bottom
* iseq.c (iseq_free, iseq_free): adjust for new layout
(rb_iseq_disasm): use original iseq for dump
(iseq_data_to_ary): ditto
(rb_iseq_line_trace_each): ditto
(rb_iseq_build_for_ruby2cext): use iseq_encoded directly
* vm_dump.c (rb_vmdebug_debug_print_pre): use original iseq
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 10:14:07 +04:00
|
|
|
RUBY_FREE_UNLESS_NULL(iseq->iseq_encoded);
|
2011-08-24 10:31:15 +04:00
|
|
|
RUBY_FREE_UNLESS_NULL(iseq->line_info_table);
|
2008-08-11 12:13:42 +04:00
|
|
|
RUBY_FREE_UNLESS_NULL(iseq->local_table);
|
2013-08-20 21:41:13 +04:00
|
|
|
RUBY_FREE_UNLESS_NULL(iseq->is_entries);
|
2014-12-04 01:03:59 +03:00
|
|
|
if (iseq->callinfo_entries) {
|
|
|
|
for (i=0; i<iseq->callinfo_size; i++) {
|
|
|
|
/* TODO: revisit callinfo data structure */
|
|
|
|
rb_call_info_kw_arg_t *kw_arg = iseq->callinfo_entries[i].kw_arg;
|
|
|
|
RUBY_FREE_UNLESS_NULL(kw_arg);
|
|
|
|
}
|
|
|
|
RUBY_FREE_UNLESS_NULL(iseq->callinfo_entries);
|
* rewrite method/block parameter fitting logic to optimize
keyword arguments/parameters and a splat argument.
[Feature #10440] (Details are described in this ticket)
Most of complex part is moved to vm_args.c.
Now, ISeq#to_a does not catch up new instruction format.
* vm_core.h: change iseq data structures.
* introduce rb_call_info_kw_arg_t to represent keyword arguments.
* add rb_call_info_t::kw_arg.
* rename rb_iseq_t::arg_post_len to rb_iseq_t::arg_post_num.
* rename rb_iseq_t::arg_keywords to arg_keyword_num.
* rename rb_iseq_t::arg_keyword to rb_iseq_t::arg_keyword_bits.
to represent keyword bitmap parameter index.
This bitmap parameter shows that which keyword parameters are given
or not given (0 for given).
It is refered by `checkkeyword' instruction described bellow.
* rename rb_iseq_t::arg_keyword_check to rb_iseq_t::arg_keyword_rest
to represent keyword rest parameter index.
* add rb_iseq_t::arg_keyword_default_values to represent default
keyword values.
* rename VM_CALL_ARGS_SKIP_SETUP to VM_CALL_ARGS_SIMPLE
to represent
(ci->flag & (SPLAT|BLOCKARG)) &&
ci->blockiseq == NULL &&
ci->kw_arg == NULL.
* vm_insnhelper.c, vm_args.c: rewrite with refactoring.
* rewrite splat argument code.
* rewrite keyword arguments/parameters code.
* merge method and block parameter fitting code into one code base.
* vm.c, vm_eval.c: catch up these changes.
* compile.c (new_callinfo): callinfo requires kw_arg parameter.
* compile.c (compile_array_): check the last argument Hash object or
not. If Hash object and all keys are Symbol literals, they are
compiled to keyword arguments.
* insns.def (checkkeyword): add new instruction.
This instruction check the availability of corresponding keyword.
For example, a method "def foo k1: 'v1'; end" is cimpiled to the
following instructions.
0000 checkkeyword 2, 0 # check k1 is given.
0003 branchif 9 # if given, jump to address #9
0005 putstring "v1"
0007 setlocal_OP__WC__0 3 # k1 = 'v1'
0009 trace 8
0011 putnil
0012 trace 16
0014 leave
* insns.def (opt_send_simple): removed and add new instruction
"opt_send_without_block".
* parse.y (new_args_tail_gen): reorder variables.
Before this patch, a method "def foo(k1: 1, kr1:, k2: 2, **krest, &b)"
has parameter variables "k1, kr1, k2, &b, internal_id, krest",
but this patch reorders to "kr1, k1, k2, internal_id, krest, &b".
(locate a block variable at last)
* parse.y (vtable_pop): added.
This function remove latest `n' variables from vtable.
* iseq.c: catch up iseq data changes.
* proc.c: ditto.
* class.c (keyword_error): export as rb_keyword_error().
* common.mk: depend vm_args.c for vm.o.
* hash.c (rb_hash_has_key): export.
* internal.h: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-02 21:02:55 +03:00
|
|
|
}
|
2008-08-11 12:13:42 +04:00
|
|
|
RUBY_FREE_UNLESS_NULL(iseq->catch_table);
|
2014-11-03 02:14:21 +03:00
|
|
|
RUBY_FREE_UNLESS_NULL(iseq->param.opt_table);
|
2014-11-03 08:43:31 +03:00
|
|
|
if (iseq->param.keyword != NULL) {
|
|
|
|
RUBY_FREE_UNLESS_NULL(iseq->param.keyword->default_values);
|
|
|
|
RUBY_FREE_UNLESS_NULL(iseq->param.keyword);
|
|
|
|
}
|
2008-08-11 12:13:42 +04:00
|
|
|
compile_data_free(iseq->compile_data);
|
compile: translate iseq in-place
running "ruby -rpp -e 'pp GC.stat'", a reduction in
malloc usage is shown:
before:
:malloc_increase=>118784,
:oldmalloc_increase=>1178736,
after:
:malloc_increase=>99832,
:oldmalloc_increase=>1031976,
For "ruby -e exit", valgrind reports over 300K reduction in
overall allocations (and unnecessary memory copies).
before:
total heap usage: 49,622 allocs, 20,492 frees, 8,697,493 bytes allocated
after:
total heap usage: 48,935 allocs, 19,805 frees, 8,373,773 bytes allocated
(numbers from x86-64)
v2 changes based on ko1 recommendations [ruby-core:64883]:
- squashed in-place direct thread translation to avoid alloc+copy
- renamed rb_iseq_untranslate_threaded_code to rb_iseq_original_iseq,
cache new iseq->iseq_original field.
* compile.c (rb_iseq_translate_threaded_code): modify in-place w/o copy
(rb_vm_addr2insn): new function for debug
(rb_iseq_original_iseq): ditto
(iseq_set_sequence): assign iseq_encoded directly
[Feature #10185]
* vm_core (rb_iseq_t): move original ->iseq to bottom
* iseq.c (iseq_free, iseq_free): adjust for new layout
(rb_iseq_disasm): use original iseq for dump
(iseq_data_to_ary): ditto
(rb_iseq_line_trace_each): ditto
(rb_iseq_build_for_ruby2cext): use iseq_encoded directly
* vm_dump.c (rb_vmdebug_debug_print_pre): use original iseq
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 10:14:07 +04:00
|
|
|
RUBY_FREE_UNLESS_NULL(iseq->iseq);
|
2008-08-11 12:13:42 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
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)
|
|
|
|
{
|
2007-06-25 06:44:20 +04:00
|
|
|
RUBY_MARK_ENTER("iseq");
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
if (ptr) {
|
2009-07-13 13:30:23 +04:00
|
|
|
rb_iseq_t *iseq = ptr;
|
|
|
|
|
2012-06-04 06:49:37 +04:00
|
|
|
RUBY_GC_INFO("%s @ %s\n", RSTRING_PTR(iseq->location.label), RSTRING_PTR(iseq->location.path));
|
2007-07-01 22:16:02 +04:00
|
|
|
RUBY_MARK_UNLESS_NULL(iseq->mark_ary);
|
2012-05-22 12:31:38 +04:00
|
|
|
|
2012-06-04 06:49:37 +04:00
|
|
|
RUBY_MARK_UNLESS_NULL(iseq->location.label);
|
|
|
|
RUBY_MARK_UNLESS_NULL(iseq->location.base_label);
|
|
|
|
RUBY_MARK_UNLESS_NULL(iseq->location.path);
|
|
|
|
RUBY_MARK_UNLESS_NULL(iseq->location.absolute_path);
|
2012-05-22 12:31:38 +04:00
|
|
|
|
2007-06-25 06:44:20 +04:00
|
|
|
RUBY_MARK_UNLESS_NULL((VALUE)iseq->cref_stack);
|
|
|
|
RUBY_MARK_UNLESS_NULL(iseq->klass);
|
2008-07-01 20:55:30 +04:00
|
|
|
RUBY_MARK_UNLESS_NULL(iseq->coverage);
|
2008-08-11 12:13:42 +04:00
|
|
|
RUBY_MARK_UNLESS_NULL(iseq->orig);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
if (iseq->compile_data != 0) {
|
2009-08-28 04:31:01 +04:00
|
|
|
struct iseq_compile_data *const compile_data = iseq->compile_data;
|
|
|
|
RUBY_MARK_UNLESS_NULL(compile_data->mark_ary);
|
|
|
|
RUBY_MARK_UNLESS_NULL(compile_data->err_info);
|
|
|
|
RUBY_MARK_UNLESS_NULL(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
|
|
|
}
|
|
|
|
|
2009-06-17 02:23:53 +04:00
|
|
|
static size_t
|
2009-09-09 06:11:35 +04:00
|
|
|
iseq_memsize(const void *ptr)
|
2009-06-17 02:23:53 +04:00
|
|
|
{
|
|
|
|
size_t size = sizeof(rb_iseq_t);
|
2009-09-09 06:11:35 +04:00
|
|
|
const rb_iseq_t *iseq;
|
2009-06-17 02:23:53 +04:00
|
|
|
|
|
|
|
if (ptr) {
|
|
|
|
iseq = ptr;
|
|
|
|
if (!iseq->orig) {
|
|
|
|
size += iseq->iseq_size * sizeof(VALUE);
|
2011-08-24 10:31:15 +04:00
|
|
|
size += iseq->line_info_size * sizeof(struct iseq_line_info_entry);
|
2009-06-17 02:23:53 +04:00
|
|
|
size += iseq->local_table_size * sizeof(ID);
|
2014-07-14 11:06:26 +04:00
|
|
|
if (iseq->catch_table) {
|
|
|
|
size += iseq_catch_table_bytes(iseq->catch_table->size);
|
|
|
|
}
|
2014-11-03 07:43:07 +03:00
|
|
|
size += (iseq->param.opt_num + 1) * sizeof(VALUE);
|
2014-11-03 07:54:27 +03:00
|
|
|
if (iseq->param.keyword != NULL) {
|
|
|
|
size += sizeof(struct rb_iseq_param_keyword);
|
|
|
|
size += sizeof(VALUE) * (iseq->param.keyword->num - iseq->param.keyword->required_num);
|
|
|
|
}
|
2013-08-20 21:41:13 +04:00
|
|
|
size += iseq->is_size * sizeof(union iseq_inline_storage_entry);
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
size += iseq->callinfo_size * sizeof(rb_call_info_t);
|
2009-06-17 02:23:53 +04:00
|
|
|
|
|
|
|
if (iseq->compile_data) {
|
|
|
|
struct iseq_compile_data_storage *cur;
|
|
|
|
|
|
|
|
cur = iseq->compile_data->storage_head;
|
|
|
|
while (cur) {
|
2014-07-26 11:57:44 +04:00
|
|
|
size += cur->size + SIZEOF_ISEQ_COMPILE_DATA_STORAGE;
|
2009-06-17 02:23:53 +04:00
|
|
|
cur = cur->next;
|
|
|
|
}
|
|
|
|
size += sizeof(struct iseq_compile_data);
|
|
|
|
}
|
compile: translate iseq in-place
running "ruby -rpp -e 'pp GC.stat'", a reduction in
malloc usage is shown:
before:
:malloc_increase=>118784,
:oldmalloc_increase=>1178736,
after:
:malloc_increase=>99832,
:oldmalloc_increase=>1031976,
For "ruby -e exit", valgrind reports over 300K reduction in
overall allocations (and unnecessary memory copies).
before:
total heap usage: 49,622 allocs, 20,492 frees, 8,697,493 bytes allocated
after:
total heap usage: 48,935 allocs, 19,805 frees, 8,373,773 bytes allocated
(numbers from x86-64)
v2 changes based on ko1 recommendations [ruby-core:64883]:
- squashed in-place direct thread translation to avoid alloc+copy
- renamed rb_iseq_untranslate_threaded_code to rb_iseq_original_iseq,
cache new iseq->iseq_original field.
* compile.c (rb_iseq_translate_threaded_code): modify in-place w/o copy
(rb_vm_addr2insn): new function for debug
(rb_iseq_original_iseq): ditto
(iseq_set_sequence): assign iseq_encoded directly
[Feature #10185]
* vm_core (rb_iseq_t): move original ->iseq to bottom
* iseq.c (iseq_free, iseq_free): adjust for new layout
(rb_iseq_disasm): use original iseq for dump
(iseq_data_to_ary): ditto
(rb_iseq_line_trace_each): ditto
(rb_iseq_build_for_ruby2cext): use iseq_encoded directly
* vm_dump.c (rb_vmdebug_debug_print_pre): use original iseq
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 10:14:07 +04:00
|
|
|
if (iseq->iseq) {
|
|
|
|
size += iseq->iseq_size * sizeof(VALUE);
|
|
|
|
}
|
2009-06-17 02:23:53 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const rb_data_type_t iseq_data_type = {
|
|
|
|
"iseq",
|
2010-07-18 11:31:54 +04:00
|
|
|
{
|
|
|
|
iseq_mark,
|
|
|
|
iseq_free,
|
|
|
|
iseq_memsize,
|
2013-06-19 10:26:01 +04:00
|
|
|
}, /* functions */
|
2014-12-01 09:38:04 +03:00
|
|
|
0, 0,
|
2014-12-11 13:15:30 +03:00
|
|
|
RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_PROMOTED1 /* start from age == 2 */ | RUBY_TYPED_WB_PROTECTED
|
2009-06-17 02:23:53 +04:00
|
|
|
};
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static VALUE
|
|
|
|
iseq_alloc(VALUE klass)
|
|
|
|
{
|
* 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;
|
2009-07-08 00:28:27 +04:00
|
|
|
return TypedData_Make_Struct(klass, rb_iseq_t, &iseq_data_type, iseq);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2012-06-04 06:49:37 +04:00
|
|
|
static rb_iseq_location_t *
|
2014-08-25 06:24:10 +04:00
|
|
|
iseq_location_setup(rb_iseq_t *iseq, VALUE path, VALUE absolute_path, VALUE name, VALUE first_lineno)
|
2012-05-22 12:31:38 +04:00
|
|
|
{
|
2012-06-04 06:49:37 +04:00
|
|
|
rb_iseq_location_t *loc = &iseq->location;
|
* include/ruby/ruby.h: rename OBJ_WRITE and OBJ_WRITTEN into
RB_OBJ_WRITE and RB_OBJ_WRITTEN.
* array.c, class.c, compile.c, hash.c, internal.h, iseq.c,
proc.c, process.c, re.c, string.c, variable.c, vm.c,
vm_eval.c, vm_insnhelper.c, vm_insnhelper.h,
vm_method.c: catch up this change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-20 12:07:47 +04:00
|
|
|
RB_OBJ_WRITE(iseq->self, &loc->path, path);
|
2013-06-19 10:26:01 +04:00
|
|
|
if (RTEST(absolute_path) && rb_str_cmp(path, absolute_path) == 0) {
|
* include/ruby/ruby.h: rename OBJ_WRITE and OBJ_WRITTEN into
RB_OBJ_WRITE and RB_OBJ_WRITTEN.
* array.c, class.c, compile.c, hash.c, internal.h, iseq.c,
proc.c, process.c, re.c, string.c, variable.c, vm.c,
vm_eval.c, vm_insnhelper.c, vm_insnhelper.h,
vm_method.c: catch up this change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-20 12:07:47 +04:00
|
|
|
RB_OBJ_WRITE(iseq->self, &loc->absolute_path, path);
|
2013-06-19 10:26:01 +04:00
|
|
|
}
|
|
|
|
else {
|
* include/ruby/ruby.h: rename OBJ_WRITE and OBJ_WRITTEN into
RB_OBJ_WRITE and RB_OBJ_WRITTEN.
* array.c, class.c, compile.c, hash.c, internal.h, iseq.c,
proc.c, process.c, re.c, string.c, variable.c, vm.c,
vm_eval.c, vm_insnhelper.c, vm_insnhelper.h,
vm_method.c: catch up this change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-20 12:07:47 +04:00
|
|
|
RB_OBJ_WRITE(iseq->self, &loc->absolute_path, absolute_path);
|
2013-06-19 10:26:01 +04:00
|
|
|
}
|
* include/ruby/ruby.h: rename OBJ_WRITE and OBJ_WRITTEN into
RB_OBJ_WRITE and RB_OBJ_WRITTEN.
* array.c, class.c, compile.c, hash.c, internal.h, iseq.c,
proc.c, process.c, re.c, string.c, variable.c, vm.c,
vm_eval.c, vm_insnhelper.c, vm_insnhelper.h,
vm_method.c: catch up this change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-20 12:07:47 +04:00
|
|
|
RB_OBJ_WRITE(iseq->self, &loc->label, name);
|
|
|
|
RB_OBJ_WRITE(iseq->self, &loc->base_label, name);
|
2012-06-04 06:49:37 +04:00
|
|
|
loc->first_lineno = first_lineno;
|
2012-05-22 12:31:38 +04:00
|
|
|
return loc;
|
|
|
|
}
|
|
|
|
|
* include/ruby/ruby.h: rename OBJ_WRITE and OBJ_WRITTEN into
RB_OBJ_WRITE and RB_OBJ_WRITTEN.
* array.c, class.c, compile.c, hash.c, internal.h, iseq.c,
proc.c, process.c, re.c, string.c, variable.c, vm.c,
vm_eval.c, vm_insnhelper.c, vm_insnhelper.h,
vm_method.c: catch up this change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-20 12:07:47 +04:00
|
|
|
#define ISEQ_SET_CREF(iseq, cref) RB_OBJ_WRITE((iseq)->self, &(iseq)->cref_stack, (cref))
|
2013-06-19 10:26:01 +04:00
|
|
|
|
2007-07-04 00:12:55 +04:00
|
|
|
static void
|
|
|
|
set_relation(rb_iseq_t *iseq, const VALUE parent)
|
|
|
|
{
|
2009-07-07 05:12:17 +04:00
|
|
|
const VALUE type = iseq->type;
|
2007-07-04 00:12:55 +04:00
|
|
|
rb_thread_t *th = GET_THREAD();
|
2012-11-01 16:20:00 +04:00
|
|
|
rb_iseq_t *piseq;
|
2007-07-04 00:12:55 +04:00
|
|
|
|
|
|
|
/* set class nest stack */
|
|
|
|
if (type == ISEQ_TYPE_TOP) {
|
|
|
|
/* toplevel is private */
|
* include/ruby/ruby.h: rename OBJ_WRITE and OBJ_WRITTEN into
RB_OBJ_WRITE and RB_OBJ_WRITTEN.
* array.c, class.c, compile.c, hash.c, internal.h, iseq.c,
proc.c, process.c, re.c, string.c, variable.c, vm.c,
vm_eval.c, vm_insnhelper.c, vm_insnhelper.h,
vm_method.c: catch up this change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-20 12:07:47 +04:00
|
|
|
RB_OBJ_WRITE(iseq->self, &iseq->cref_stack, NEW_CREF(rb_cObject));
|
2012-10-08 18:02:46 +04:00
|
|
|
iseq->cref_stack->nd_refinements = Qnil;
|
2007-07-04 00:12:55 +04:00
|
|
|
iseq->cref_stack->nd_visi = NOEX_PRIVATE;
|
2010-04-27 17:42:29 +04:00
|
|
|
if (th->top_wrapper) {
|
2012-08-02 15:34:19 +04:00
|
|
|
NODE *cref = NEW_CREF(th->top_wrapper);
|
2012-10-08 18:02:46 +04:00
|
|
|
cref->nd_refinements = Qnil;
|
2010-04-27 17:42:29 +04:00
|
|
|
cref->nd_visi = NOEX_PRIVATE;
|
* include/ruby/ruby.h: rename OBJ_WRITE and OBJ_WRITTEN into
RB_OBJ_WRITE and RB_OBJ_WRITTEN.
* array.c, class.c, compile.c, hash.c, internal.h, iseq.c,
proc.c, process.c, re.c, string.c, variable.c, vm.c,
vm_eval.c, vm_insnhelper.c, vm_insnhelper.h,
vm_method.c: catch up this change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-20 12:07:47 +04:00
|
|
|
RB_OBJ_WRITE(cref, &cref->nd_next, iseq->cref_stack);
|
2013-06-19 10:26:01 +04:00
|
|
|
ISEQ_SET_CREF(iseq, cref);
|
2010-04-27 17:42:29 +04:00
|
|
|
}
|
2012-11-01 08:17:01 +04:00
|
|
|
iseq->local_iseq = iseq;
|
2007-07-04 00:12:55 +04:00
|
|
|
}
|
|
|
|
else if (type == ISEQ_TYPE_METHOD || type == ISEQ_TYPE_CLASS) {
|
2013-06-19 10:26:01 +04:00
|
|
|
ISEQ_SET_CREF(iseq, NEW_CREF(0)); /* place holder */
|
2012-10-08 18:02:46 +04:00
|
|
|
iseq->cref_stack->nd_refinements = Qnil;
|
2007-07-04 00:12:55 +04:00
|
|
|
iseq->local_iseq = iseq;
|
|
|
|
}
|
|
|
|
else if (RTEST(parent)) {
|
|
|
|
GetISeqPtr(parent, piseq);
|
2013-06-19 10:26:01 +04:00
|
|
|
ISEQ_SET_CREF(iseq, piseq->cref_stack);
|
2007-07-04 00:12:55 +04:00
|
|
|
iseq->local_iseq = piseq->local_iseq;
|
2012-11-01 16:20:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (RTEST(parent)) {
|
|
|
|
GetISeqPtr(parent, piseq);
|
2007-07-04 00:12:55 +04:00
|
|
|
iseq->parent_iseq = piseq;
|
|
|
|
}
|
2012-12-10 10:11:16 +04:00
|
|
|
|
|
|
|
if (type == ISEQ_TYPE_MAIN) {
|
|
|
|
iseq->local_iseq = iseq;
|
|
|
|
}
|
2007-07-04 00:12:55 +04:00
|
|
|
}
|
|
|
|
|
2013-04-17 15:20:23 +04:00
|
|
|
void
|
|
|
|
rb_iseq_add_mark_object(rb_iseq_t *iseq, VALUE obj)
|
|
|
|
{
|
|
|
|
if (!RTEST(iseq->mark_ary)) {
|
* include/ruby/ruby.h: rename OBJ_WRITE and OBJ_WRITTEN into
RB_OBJ_WRITE and RB_OBJ_WRITTEN.
* array.c, class.c, compile.c, hash.c, internal.h, iseq.c,
proc.c, process.c, re.c, string.c, variable.c, vm.c,
vm_eval.c, vm_insnhelper.c, vm_insnhelper.h,
vm_method.c: catch up this change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-20 12:07:47 +04:00
|
|
|
RB_OBJ_WRITE(iseq->self, &iseq->mark_ary, rb_ary_tmp_new(3));
|
* include/ruby/ruby.h: constify RBasic::klass and add
RBASIC_CLASS(obj) macro which returns a class of `obj'.
This change is a part of RGENGC branch [ruby-trunk - Feature #8339].
* object.c: add new function rb_obj_reveal().
This function reveal interal (hidden) object by rb_obj_hide().
Note that do not change class before and after hiding.
Only permitted example is:
klass = RBASIC_CLASS(obj);
rb_obj_hide(obj);
....
rb_obj_reveal(obj, klass);
TODO: API design. rb_obj_reveal() should be replaced with others.
TODO: modify constified variables using cast may be harmful for
compiler's analysis and optimizaton.
Any idea to prohibt inserting RBasic::klass directly?
If rename RBasic::klass and force to use RBASIC_CLASS(obj),
then all codes such as `RBASIC(obj)->klass' will be
compilation error. Is it acceptable? (We have similar
experience at Ruby 1.9,
for example "RARRAY(ary)->ptr" to "RARRAY_PTR(ary)".
* internal.h: add some macros.
* RBASIC_CLEAR_CLASS(obj) clear RBasic::klass to make it internal
object.
* RBASIC_SET_CLASS(obj, cls) set RBasic::klass.
* RBASIC_SET_CLASS_RAW(obj, cls) same as RBASIC_SET_CLASS
without write barrier (planned).
* RCLASS_SET_SUPER(a, b) set super class of a.
* array.c, class.c, compile.c, encoding.c, enum.c, error.c, eval.c,
file.c, gc.c, hash.c, io.c, iseq.c, marshal.c, object.c,
parse.y, proc.c, process.c, random.c, ruby.c, sprintf.c,
string.c, thread.c, transcode.c, vm.c, vm_eval.c, win32/file.c:
Use above macros and functions to access RBasic::klass.
* ext/coverage/coverage.c, ext/readline/readline.c,
ext/socket/ancdata.c, ext/socket/init.c,
* ext/zlib/zlib.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40691 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 14:49:11 +04:00
|
|
|
RBASIC_CLEAR_CLASS(iseq->mark_ary);
|
2013-04-17 15:20:23 +04:00
|
|
|
}
|
|
|
|
rb_ary_push(iseq->mark_ary, obj);
|
|
|
|
}
|
|
|
|
|
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,
|
2012-06-04 06:49:37 +04:00
|
|
|
VALUE name, VALUE path, VALUE absolute_path, VALUE first_lineno,
|
2014-12-05 05:10:29 +03:00
|
|
|
VALUE parent, enum iseq_type 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
|
|
|
const rb_compile_option_t *option)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2012-05-22 12:31:38 +04:00
|
|
|
iseq->type = type;
|
* include/ruby/ruby.h: rename OBJ_WRITE and OBJ_WRITTEN into
RB_OBJ_WRITE and RB_OBJ_WRITTEN.
* array.c, class.c, compile.c, hash.c, internal.h, iseq.c,
proc.c, process.c, re.c, string.c, variable.c, vm.c,
vm_eval.c, vm_insnhelper.c, vm_insnhelper.h,
vm_method.c: catch up this change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-20 12:07:47 +04:00
|
|
|
RB_OBJ_WRITE(iseq->self, &iseq->klass, 0);
|
2012-05-22 12:31:38 +04:00
|
|
|
set_relation(iseq, parent);
|
|
|
|
|
2013-11-27 03:30:25 +04:00
|
|
|
name = rb_fstring(name);
|
|
|
|
path = rb_fstring(path);
|
2014-11-03 02:14:21 +03:00
|
|
|
if (RTEST(absolute_path)) absolute_path = rb_fstring(absolute_path);
|
2012-06-04 06:49:37 +04:00
|
|
|
iseq_location_setup(iseq, path, absolute_path, name, first_lineno);
|
2012-05-22 12:31:38 +04:00
|
|
|
if (iseq != iseq->local_iseq) {
|
* include/ruby/ruby.h: rename OBJ_WRITE and OBJ_WRITTEN into
RB_OBJ_WRITE and RB_OBJ_WRITTEN.
* array.c, class.c, compile.c, hash.c, internal.h, iseq.c,
proc.c, process.c, re.c, string.c, variable.c, vm.c,
vm_eval.c, vm_insnhelper.c, vm_insnhelper.h,
vm_method.c: catch up this change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-20 12:07:47 +04:00
|
|
|
RB_OBJ_WRITE(iseq->self, &iseq->location.base_label, iseq->local_iseq->location.label);
|
2012-05-22 12:31:38 +04:00
|
|
|
}
|
2007-06-07 12:21:01 +04:00
|
|
|
iseq->defined_method_id = 0;
|
* include/ruby/ruby.h: rename OBJ_WRITE and OBJ_WRITTEN into
RB_OBJ_WRITE and RB_OBJ_WRITTEN.
* array.c, class.c, compile.c, hash.c, internal.h, iseq.c,
proc.c, process.c, re.c, string.c, variable.c, vm.c,
vm_eval.c, vm_insnhelper.c, vm_insnhelper.h,
vm_method.c: catch up this change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-20 12:07:47 +04:00
|
|
|
RB_OBJ_WRITE(iseq->self, &iseq->mark_ary, 0);
|
2007-02-25 19:29:26 +03:00
|
|
|
|
2014-07-26 01:34:35 +04:00
|
|
|
iseq->compile_data = ZALLOC(struct iseq_compile_data);
|
* include/ruby/ruby.h: rename OBJ_WRITE and OBJ_WRITTEN into
RB_OBJ_WRITE and RB_OBJ_WRITTEN.
* array.c, class.c, compile.c, hash.c, internal.h, iseq.c,
proc.c, process.c, re.c, string.c, variable.c, vm.c,
vm_eval.c, vm_insnhelper.c, vm_insnhelper.h,
vm_method.c: catch up this change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-20 12:07:47 +04:00
|
|
|
RB_OBJ_WRITE(iseq->self, &iseq->compile_data->err_info, Qnil);
|
|
|
|
RB_OBJ_WRITE(iseq->self, &iseq->compile_data->mark_ary, rb_ary_tmp_new(3));
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
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 +
|
2014-07-26 11:57:44 +04:00
|
|
|
SIZEOF_ISEQ_COMPILE_DATA_STORAGE);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* include/ruby/ruby.h: rename OBJ_WRITE and OBJ_WRITTEN into
RB_OBJ_WRITE and RB_OBJ_WRITTEN.
* array.c, class.c, compile.c, hash.c, internal.h, iseq.c,
proc.c, process.c, re.c, string.c, variable.c, vm.c,
vm_eval.c, vm_insnhelper.c, vm_insnhelper.h,
vm_method.c: catch up this change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-20 12:07:47 +04:00
|
|
|
RB_OBJ_WRITE(iseq->self, &iseq->compile_data->catch_table_ary, rb_ary_new());
|
2006-12-31 18:02:22 +03:00
|
|
|
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->option = option;
|
2009-10-08 20:11:30 +04:00
|
|
|
iseq->compile_data->last_coverable_line = -1;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* include/ruby/ruby.h: rename OBJ_WRITE and OBJ_WRITTEN into
RB_OBJ_WRITE and RB_OBJ_WRITTEN.
* array.c, class.c, compile.c, hash.c, internal.h, iseq.c,
proc.c, process.c, re.c, string.c, variable.c, vm.c,
vm_eval.c, vm_insnhelper.c, vm_insnhelper.h,
vm_method.c: catch up this change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-20 12:07:47 +04:00
|
|
|
RB_OBJ_WRITE(iseq->self, &iseq->coverage, Qfalse);
|
2008-07-01 20:55:30 +04:00
|
|
|
if (!GET_THREAD()->parse_in_eval) {
|
2008-07-08 19:13:22 +04:00
|
|
|
VALUE coverages = rb_get_coverages();
|
2008-07-03 16:55:12 +04:00
|
|
|
if (RTEST(coverages)) {
|
* include/ruby/ruby.h: rename OBJ_WRITE and OBJ_WRITTEN into
RB_OBJ_WRITE and RB_OBJ_WRITTEN.
* array.c, class.c, compile.c, hash.c, internal.h, iseq.c,
proc.c, process.c, re.c, string.c, variable.c, vm.c,
vm_eval.c, vm_insnhelper.c, vm_insnhelper.h,
vm_method.c: catch up this change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-20 12:07:47 +04:00
|
|
|
RB_OBJ_WRITE(iseq->self, &iseq->coverage, rb_hash_lookup(coverages, path));
|
|
|
|
if (NIL_P(iseq->coverage)) RB_OBJ_WRITE(iseq->self, &iseq->coverage, Qfalse);
|
2008-07-01 20:55:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)) {
|
2012-06-04 06:49:37 +04:00
|
|
|
rb_funcall2(err, rb_intern("set_backtrace"), 1, &iseq->location.path);
|
* 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
|
|
|
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
|
|
|
};
|
2008-07-01 12:44:32 +04:00
|
|
|
static const rb_compile_option_t COMPILE_OPTION_FALSE = {0};
|
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) {
|
2013-11-15 12:07:35 +04:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < (int)(sizeof(rb_compile_option_t) / sizeof(int)); ++i)
|
|
|
|
((int *)option)[i] = 1;
|
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) \
|
2010-12-17 01:05:58 +03:00
|
|
|
{ VALUE flag = rb_hash_aref((h), ID2SYM(rb_intern(#mem))); \
|
|
|
|
if (flag == Qtrue) { (o)->mem = 1; } \
|
|
|
|
else if (flag == Qfalse) { (o)->mem = 0; } \
|
2008-04-14 09:34:04 +04:00
|
|
|
}
|
|
|
|
#define SET_COMPILE_OPTION_NUM(o, h, mem) \
|
|
|
|
{ VALUE num = rb_hash_aref(opt, ID2SYM(rb_intern(#mem))); \
|
2010-12-17 01:05:58 +03:00
|
|
|
if (!NIL_P(num)) (o)->mem = NUM2INT(num); \
|
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);
|
2008-04-14 09:34:04 +04:00
|
|
|
SET_COMPILE_OPTION_NUM(option, opt, debug_level);
|
2006-12-31 18:02:22 +03:00
|
|
|
#undef SET_COMPILE_OPTION
|
2008-04-14 09:34:04 +04:00
|
|
|
#undef SET_COMPILE_OPTION_NUM
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
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) \
|
2010-12-17 01:05:58 +03:00
|
|
|
rb_hash_aset((h), ID2SYM(rb_intern(#mem)), (o)->mem ? Qtrue : Qfalse)
|
2008-04-14 09:34:04 +04:00
|
|
|
#define SET_COMPILE_OPTION_NUM(o, h, mem) \
|
2010-12-17 01:05:58 +03:00
|
|
|
rb_hash_aset((h), ID2SYM(rb_intern(#mem)), INT2NUM((o)->mem))
|
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);
|
2012-11-26 14:46:01 +04:00
|
|
|
SET_COMPILE_OPTION(option, opt, trace_instruction);
|
2008-04-14 09:34:04 +04:00
|
|
|
SET_COMPILE_OPTION_NUM(option, opt, debug_level);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
#undef SET_COMPILE_OPTION
|
2008-04-14 09:34:04 +04:00
|
|
|
#undef SET_COMPILE_OPTION_NUM
|
2006-12-31 18:02:22 +03:00
|
|
|
return opt;
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
2012-06-04 06:49:37 +04:00
|
|
|
rb_iseq_new(NODE *node, VALUE name, VALUE path, VALUE absolute_path,
|
2010-10-31 16:11:02 +03:00
|
|
|
VALUE parent, enum iseq_type type)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2012-06-04 06:49:37 +04:00
|
|
|
return rb_iseq_new_with_opt(node, name, path, absolute_path, INT2FIX(0), 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
|
|
|
}
|
|
|
|
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
VALUE
|
2012-06-04 06:49:37 +04:00
|
|
|
rb_iseq_new_top(NODE *node, VALUE name, VALUE path, VALUE absolute_path, VALUE parent)
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
{
|
2012-06-04 06:49:37 +04:00
|
|
|
return rb_iseq_new_with_opt(node, name, path, absolute_path, INT2FIX(0), parent, ISEQ_TYPE_TOP,
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
&COMPILE_OPTION_DEFAULT);
|
2008-12-27 04:15:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
2012-06-04 06:49:37 +04:00
|
|
|
rb_iseq_new_main(NODE *node, VALUE path, VALUE absolute_path)
|
2008-12-27 04:15:56 +03:00
|
|
|
{
|
|
|
|
rb_thread_t *th = GET_THREAD();
|
|
|
|
VALUE parent = th->base_block->iseq->self;
|
2012-06-04 06:49:37 +04:00
|
|
|
return rb_iseq_new_with_opt(node, rb_str_new2("<main>"), path, absolute_path, INT2FIX(0),
|
2008-12-27 08:58:23 +03:00
|
|
|
parent, ISEQ_TYPE_MAIN, &COMPILE_OPTION_DEFAULT);
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 11:49:45 +04:00
|
|
|
}
|
|
|
|
|
2014-12-05 05:10:29 +03:00
|
|
|
VALUE
|
|
|
|
rb_iseq_new_with_opt(NODE *node, VALUE name, VALUE path, VALUE absolute_path,
|
|
|
|
VALUE first_lineno, VALUE parent, enum iseq_type type,
|
|
|
|
const rb_compile_option_t *option)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2014-12-05 05:10:29 +03:00
|
|
|
/* TODO: argument check */
|
* 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;
|
|
|
|
|
2014-12-17 05:57:51 +03:00
|
|
|
if (!option) option = &COMPILE_OPTION_DEFAULT;
|
2014-12-05 05:10:29 +03:00
|
|
|
prepare_iseq_build(iseq, name, path, absolute_path, first_lineno, parent,
|
|
|
|
type, option);
|
|
|
|
|
2009-01-19 04:06:56 +03:00
|
|
|
rb_iseq_compile_node(self, node);
|
2006-12-31 18:02:22 +03:00
|
|
|
cleanup_iseq_build(iseq);
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-12-17 01:05:58 +03:00
|
|
|
#define CHECK_ARRAY(v) rb_convert_type((v), T_ARRAY, "Array", "to_ary")
|
2014-12-04 01:16:58 +03:00
|
|
|
#define CHECK_HASH(v) rb_convert_type((v), T_HASH, "Hash", "to_hash")
|
2010-12-17 01:05:58 +03:00
|
|
|
#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")
|
2010-07-27 11:13:43 +04:00
|
|
|
static inline VALUE CHECK_INTEGER(VALUE v) {(void)NUM2LONG(v); return v;}
|
2014-01-12 11:49:26 +04:00
|
|
|
|
|
|
|
static enum iseq_type
|
2014-07-28 12:15:42 +04:00
|
|
|
iseq_type_from_sym(VALUE type)
|
2014-01-12 11:49:26 +04:00
|
|
|
{
|
2014-07-28 12:15:42 +04:00
|
|
|
const ID id_top = rb_intern("top");
|
|
|
|
const ID id_method = rb_intern("method");
|
|
|
|
const ID id_block = rb_intern("block");
|
|
|
|
const ID id_class = rb_intern("class");
|
|
|
|
const ID id_rescue = rb_intern("rescue");
|
|
|
|
const ID id_ensure = rb_intern("ensure");
|
|
|
|
const ID id_eval = rb_intern("eval");
|
|
|
|
const ID id_main = rb_intern("main");
|
|
|
|
const ID id_defined_guard = rb_intern("defined_guard");
|
|
|
|
/* ensure all symbols are static or pinned down before
|
|
|
|
* conversion */
|
|
|
|
const ID typeid = rb_check_id(&type);
|
|
|
|
if (typeid == id_top) return ISEQ_TYPE_TOP;
|
|
|
|
if (typeid == id_method) return ISEQ_TYPE_METHOD;
|
|
|
|
if (typeid == id_block) return ISEQ_TYPE_BLOCK;
|
|
|
|
if (typeid == id_class) return ISEQ_TYPE_CLASS;
|
|
|
|
if (typeid == id_rescue) return ISEQ_TYPE_RESCUE;
|
|
|
|
if (typeid == id_ensure) return ISEQ_TYPE_ENSURE;
|
|
|
|
if (typeid == id_eval) return ISEQ_TYPE_EVAL;
|
|
|
|
if (typeid == id_main) return ISEQ_TYPE_MAIN;
|
|
|
|
if (typeid == id_defined_guard) return ISEQ_TYPE_DEFINED_GUARD;
|
2014-01-12 11:49:26 +04:00
|
|
|
return (enum iseq_type)-1;
|
|
|
|
}
|
|
|
|
|
2008-12-05 06:35:48 +03:00
|
|
|
static VALUE
|
2006-12-31 18:02:22 +03:00
|
|
|
iseq_load(VALUE self, VALUE data, VALUE parent, VALUE opt)
|
|
|
|
{
|
2008-12-05 06:35:48 +03:00
|
|
|
VALUE iseqval = iseq_alloc(self);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
VALUE magic, version1, version2, format_type, misc;
|
2012-06-04 06:49:37 +04:00
|
|
|
VALUE name, path, absolute_path, first_lineno;
|
2014-12-04 01:16:58 +03:00
|
|
|
VALUE type, body, locals, params, exception;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c (iseq_build_body), error.c (set_syserr, get_syserr),
(syserr_initialize), gc.c (define_final, rb_gc_copy_finalizer),
(run_final), hash.c (rb_hash_aref, rb_hash_lookup2),
(rb_hash_fetch_m, rb_hash_clear, rb_hash_aset, eql_i),
iseq.c (iseq_load, iseq_data_to_ary), marshal.c (r_symlink),
thread.c (rb_thread_local_aref),
variable.c (generic_ivar_remove, ivar_get, rb_const_get_0),
(rb_cvar_get), vm.c (rb_vm_check_redefinition_opt_method),
vm_insnhelper.c (vm_get_ev_const), vm_method.c (remove_method),
ext/iconv/iconv.c (map_charset): use st_data_t.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-10-12 18:47:23 +04:00
|
|
|
st_data_t iseq_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
|
|
|
rb_iseq_t *iseq;
|
|
|
|
rb_compile_option_t option;
|
2008-01-08 07:05:59 +03:00
|
|
|
int i = 0;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
/* [magic, major_version, minor_version, format_type, misc,
|
2012-06-04 06:49:37 +04:00
|
|
|
* label, path, first_lineno,
|
2006-12-31 18:02:22 +03:00
|
|
|
* type, locals, args, exception_table, body]
|
|
|
|
*/
|
|
|
|
|
|
|
|
data = CHECK_ARRAY(data);
|
2007-05-11 10:26:06 +04:00
|
|
|
|
2008-01-08 07:05:59 +03:00
|
|
|
magic = CHECK_STRING(rb_ary_entry(data, i++));
|
|
|
|
version1 = CHECK_INTEGER(rb_ary_entry(data, i++));
|
|
|
|
version2 = CHECK_INTEGER(rb_ary_entry(data, i++));
|
|
|
|
format_type = CHECK_INTEGER(rb_ary_entry(data, i++));
|
2014-12-04 01:16:58 +03:00
|
|
|
misc = CHECK_HASH(rb_ary_entry(data, i++));
|
|
|
|
((void)magic, (void)version1, (void)version2, (void)format_type);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2008-01-08 07:05:59 +03:00
|
|
|
name = CHECK_STRING(rb_ary_entry(data, i++));
|
2012-06-04 06:49:37 +04:00
|
|
|
path = CHECK_STRING(rb_ary_entry(data, i++));
|
|
|
|
absolute_path = rb_ary_entry(data, i++);
|
|
|
|
absolute_path = NIL_P(absolute_path) ? Qnil : CHECK_STRING(absolute_path);
|
|
|
|
first_lineno = CHECK_INTEGER(rb_ary_entry(data, i++));
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2008-01-08 07:05:59 +03:00
|
|
|
type = CHECK_SYMBOL(rb_ary_entry(data, i++));
|
|
|
|
locals = CHECK_ARRAY(rb_ary_entry(data, i++));
|
2014-12-04 01:16:58 +03:00
|
|
|
params = CHECK_HASH(rb_ary_entry(data, i++));
|
2008-01-08 07:05:59 +03:00
|
|
|
exception = CHECK_ARRAY(rb_ary_entry(data, i++));
|
|
|
|
body = CHECK_ARRAY(rb_ary_entry(data, i++));
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
GetISeqPtr(iseqval, iseq);
|
|
|
|
iseq->self = iseqval;
|
2013-03-26 10:24:26 +04:00
|
|
|
iseq->local_iseq = iseq;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2014-07-28 12:15:42 +04:00
|
|
|
iseq_type = iseq_type_from_sym(type);
|
2014-01-12 11:49:26 +04:00
|
|
|
if (iseq_type == (enum iseq_type)-1) {
|
2014-07-28 12:15:42 +04:00
|
|
|
rb_raise(rb_eTypeError, "unsupport type: :%"PRIsVALUE, rb_sym2str(type));
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (parent == Qnil) {
|
|
|
|
parent = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
make_compile_option(&option, opt);
|
2014-12-04 01:16:58 +03:00
|
|
|
|
2012-06-04 06:49:37 +04:00
|
|
|
prepare_iseq_build(iseq, name, path, absolute_path, first_lineno,
|
2014-12-05 05:10:29 +03:00
|
|
|
parent, (enum iseq_type)iseq_type, &option);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2014-12-04 01:16:58 +03:00
|
|
|
rb_iseq_build_from_ary(iseq, misc, locals, params, exception, body);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
cleanup_iseq_build(iseq);
|
|
|
|
return iseqval;
|
|
|
|
}
|
|
|
|
|
2012-07-25 01:29:24 +04:00
|
|
|
/*
|
|
|
|
* :nodoc:
|
|
|
|
*/
|
2006-12-31 18:02:22 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2008-12-05 06:35:48 +03:00
|
|
|
VALUE
|
* iseq.c (rb_iseq_load): renamed from ruby_iseq_load, since it is
for C extensions or the ruby core. [ruby-core:21407]
Index: compile.c
===================================================================
--- compile.c (revision 21649)
+++ compile.c (working copy)
@@ -5078,5 +5078,5 @@ iseq_build_exception(rb_iseq_t *iseq, st
}
else {
- eiseqval = ruby_iseq_load(ptr[1], iseq->self, Qnil);
+ eiseqval = rb_iseq_load(ptr[1], iseq->self, Qnil);
}
@@ -5162,5 +5162,5 @@ iseq_build_body(rb_iseq_t *iseq, LINK_AN
if (op != Qnil) {
if (TYPE(op) == T_ARRAY) {
- argv[j] = ruby_iseq_load(op, iseq->self, Qnil);
+ argv[j] = rb_iseq_load(op, iseq->self, Qnil);
}
else if (CLASS_OF(op) == rb_cISeq) {
Index: iseq.c
===================================================================
--- iseq.c (revision 21649)
+++ iseq.c (working copy)
@@ -448,5 +448,5 @@ iseq_s_load(int argc, VALUE *argv, VALUE
VALUE
-ruby_iseq_load(VALUE data, VALUE parent, VALUE opt)
+rb_iseq_load(VALUE data, VALUE parent, VALUE opt)
{
return iseq_load(rb_cISeq, data, parent, opt);
Index: iseq.h
===================================================================
--- iseq.h (revision 21649)
+++ iseq.h (working copy)
@@ -21,5 +21,5 @@ VALUE ruby_iseq_build_from_ary(rb_iseq_t
/* iseq.c */
-VALUE ruby_iseq_load(VALUE data, VALUE parent, VALUE opt);
+VALUE rb_iseq_load(VALUE data, VALUE parent, VALUE opt);
struct st_table *ruby_insn_make_insn_table(void);
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21650 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-01-18 22:05:15 +03:00
|
|
|
rb_iseq_load(VALUE data, VALUE parent, VALUE opt)
|
2008-12-05 06:35:48 +03:00
|
|
|
{
|
|
|
|
return iseq_load(rb_cISeq, data, parent, opt);
|
|
|
|
}
|
|
|
|
|
* 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
|
* iseq.c, vm_eval.c: set th->base_block properly.
th->base_block is information for (a) parsing, (b) compiling
and (c) setting up the frame to execute the program passed by
`eval' method. For example, (1) parser need to know up-level
variables to detect it is variable or method without paren.
Befor (a), (b) and (c), VM set th->base_block by passed bindng
(or previous frame information). After execute (a), (b) and (c),
VM should clear th->base_block. However, if (a), (b) or (c)
raises an exception, then th->base_block is not cleared.
Problem is that the uncleared value th->balo_block is used for
irrelevant iseq compilation. It causes SEGV or critical error.
I tried to solve this problem: to clear them before exception,
but finally I found out that it is difficult to do it (Ruby
program can be run in many places).
Because of this background, I set th->base_block before
compiling iseq and restore it after compiling.
Basically, th->base_block is dirty hack (similar to global
variable) and this patch is also dirty.
* bootstraptest/test_eval.rb: add a test for above.
* internal.h: remove unused decl.
* iseq.c (rb_iseq_compile_with_option): add base_block parameter.
set th->base_block before compation and restore it after
compilation.
* ruby.c (require_libraries): pass 0 as base_block instead of
setting th->base_block
* tool/compile_prelude.rb (prelude_eval): apply above changes.
* vm.c, vm_eval.c: ditto.
* vm_core.h: add comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-22 13:32:56 +04:00
|
|
|
rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE absolute_path, VALUE line, rb_block_t *base_block, VALUE opt)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
* iseq.c, vm_eval.c: set th->base_block properly.
th->base_block is information for (a) parsing, (b) compiling
and (c) setting up the frame to execute the program passed by
`eval' method. For example, (1) parser need to know up-level
variables to detect it is variable or method without paren.
Befor (a), (b) and (c), VM set th->base_block by passed bindng
(or previous frame information). After execute (a), (b) and (c),
VM should clear th->base_block. However, if (a), (b) or (c)
raises an exception, then th->base_block is not cleared.
Problem is that the uncleared value th->balo_block is used for
irrelevant iseq compilation. It causes SEGV or critical error.
I tried to solve this problem: to clear them before exception,
but finally I found out that it is difficult to do it (Ruby
program can be run in many places).
Because of this background, I set th->base_block before
compiling iseq and restore it after compiling.
Basically, th->base_block is dirty hack (similar to global
variable) and this patch is also dirty.
* bootstraptest/test_eval.rb: add a test for above.
* internal.h: remove unused decl.
* iseq.c (rb_iseq_compile_with_option): add base_block parameter.
set th->base_block before compation and restore it after
compilation.
* ruby.c (require_libraries): pass 0 as base_block instead of
setting th->base_block
* tool/compile_prelude.rb (prelude_eval): apply above changes.
* vm.c, vm_eval.c: ditto.
* vm_core.h: add comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-22 13:32:56 +04:00
|
|
|
int state;
|
* 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_thread_t *th = GET_THREAD();
|
* iseq.c, vm_eval.c: set th->base_block properly.
th->base_block is information for (a) parsing, (b) compiling
and (c) setting up the frame to execute the program passed by
`eval' method. For example, (1) parser need to know up-level
variables to detect it is variable or method without paren.
Befor (a), (b) and (c), VM set th->base_block by passed bindng
(or previous frame information). After execute (a), (b) and (c),
VM should clear th->base_block. However, if (a), (b) or (c)
raises an exception, then th->base_block is not cleared.
Problem is that the uncleared value th->balo_block is used for
irrelevant iseq compilation. It causes SEGV or critical error.
I tried to solve this problem: to clear them before exception,
but finally I found out that it is difficult to do it (Ruby
program can be run in many places).
Because of this background, I set th->base_block before
compiling iseq and restore it after compiling.
Basically, th->base_block is dirty hack (similar to global
variable) and this patch is also dirty.
* bootstraptest/test_eval.rb: add a test for above.
* internal.h: remove unused decl.
* iseq.c (rb_iseq_compile_with_option): add base_block parameter.
set th->base_block before compation and restore it after
compilation.
* ruby.c (require_libraries): pass 0 as base_block instead of
setting th->base_block
* tool/compile_prelude.rb (prelude_eval): apply above changes.
* vm.c, vm_eval.c: ditto.
* vm_core.h: add comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-22 13:32:56 +04:00
|
|
|
rb_block_t *prev_base_block = th->base_block;
|
2012-10-11 04:50:29 +04:00
|
|
|
VALUE iseqval = Qundef;
|
* iseq.c, vm_eval.c: set th->base_block properly.
th->base_block is information for (a) parsing, (b) compiling
and (c) setting up the frame to execute the program passed by
`eval' method. For example, (1) parser need to know up-level
variables to detect it is variable or method without paren.
Befor (a), (b) and (c), VM set th->base_block by passed bindng
(or previous frame information). After execute (a), (b) and (c),
VM should clear th->base_block. However, if (a), (b) or (c)
raises an exception, then th->base_block is not cleared.
Problem is that the uncleared value th->balo_block is used for
irrelevant iseq compilation. It causes SEGV or critical error.
I tried to solve this problem: to clear them before exception,
but finally I found out that it is difficult to do it (Ruby
program can be run in many places).
Because of this background, I set th->base_block before
compiling iseq and restore it after compiling.
Basically, th->base_block is dirty hack (similar to global
variable) and this patch is also dirty.
* bootstraptest/test_eval.rb: add a test for above.
* internal.h: remove unused decl.
* iseq.c (rb_iseq_compile_with_option): add base_block parameter.
set th->base_block before compation and restore it after
compilation.
* ruby.c (require_libraries): pass 0 as base_block instead of
setting th->base_block
* tool/compile_prelude.rb (prelude_eval): apply above changes.
* vm.c, vm_eval.c: ditto.
* vm_core.h: add comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-22 13:32:56 +04:00
|
|
|
|
|
|
|
th->base_block = base_block;
|
|
|
|
|
|
|
|
TH_PUSH_TAG(th);
|
|
|
|
if ((state = EXEC_TAG()) == 0) {
|
2013-07-29 12:00:34 +04:00
|
|
|
VALUE parser;
|
* iseq.c, vm_eval.c: set th->base_block properly.
th->base_block is information for (a) parsing, (b) compiling
and (c) setting up the frame to execute the program passed by
`eval' method. For example, (1) parser need to know up-level
variables to detect it is variable or method without paren.
Befor (a), (b) and (c), VM set th->base_block by passed bindng
(or previous frame information). After execute (a), (b) and (c),
VM should clear th->base_block. However, if (a), (b) or (c)
raises an exception, then th->base_block is not cleared.
Problem is that the uncleared value th->balo_block is used for
irrelevant iseq compilation. It causes SEGV or critical error.
I tried to solve this problem: to clear them before exception,
but finally I found out that it is difficult to do it (Ruby
program can be run in many places).
Because of this background, I set th->base_block before
compiling iseq and restore it after compiling.
Basically, th->base_block is dirty hack (similar to global
variable) and this patch is also dirty.
* bootstraptest/test_eval.rb: add a test for above.
* internal.h: remove unused decl.
* iseq.c (rb_iseq_compile_with_option): add base_block parameter.
set th->base_block before compation and restore it after
compilation.
* ruby.c (require_libraries): pass 0 as base_block instead of
setting th->base_block
* tool/compile_prelude.rb (prelude_eval): apply above changes.
* vm.c, vm_eval.c: ditto.
* vm_core.h: add comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-22 13:32:56 +04:00
|
|
|
int ln = NUM2INT(line);
|
2012-10-27 05:16:25 +04:00
|
|
|
NODE *node;
|
* iseq.c, vm_eval.c: set th->base_block properly.
th->base_block is information for (a) parsing, (b) compiling
and (c) setting up the frame to execute the program passed by
`eval' method. For example, (1) parser need to know up-level
variables to detect it is variable or method without paren.
Befor (a), (b) and (c), VM set th->base_block by passed bindng
(or previous frame information). After execute (a), (b) and (c),
VM should clear th->base_block. However, if (a), (b) or (c)
raises an exception, then th->base_block is not cleared.
Problem is that the uncleared value th->balo_block is used for
irrelevant iseq compilation. It causes SEGV or critical error.
I tried to solve this problem: to clear them before exception,
but finally I found out that it is difficult to do it (Ruby
program can be run in many places).
Because of this background, I set th->base_block before
compiling iseq and restore it after compiling.
Basically, th->base_block is dirty hack (similar to global
variable) and this patch is also dirty.
* bootstraptest/test_eval.rb: add a test for above.
* internal.h: remove unused decl.
* iseq.c (rb_iseq_compile_with_option): add base_block parameter.
set th->base_block before compation and restore it after
compilation.
* ruby.c (require_libraries): pass 0 as base_block instead of
setting th->base_block
* tool/compile_prelude.rb (prelude_eval): apply above changes.
* vm.c, vm_eval.c: ditto.
* vm_core.h: add comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-22 13:32:56 +04: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
|
|
|
|
2013-07-29 12:00:34 +04:00
|
|
|
StringValueCStr(file);
|
* iseq.c, vm_eval.c: set th->base_block properly.
th->base_block is information for (a) parsing, (b) compiling
and (c) setting up the frame to execute the program passed by
`eval' method. For example, (1) parser need to know up-level
variables to detect it is variable or method without paren.
Befor (a), (b) and (c), VM set th->base_block by passed bindng
(or previous frame information). After execute (a), (b) and (c),
VM should clear th->base_block. However, if (a), (b) or (c)
raises an exception, then th->base_block is not cleared.
Problem is that the uncleared value th->balo_block is used for
irrelevant iseq compilation. It causes SEGV or critical error.
I tried to solve this problem: to clear them before exception,
but finally I found out that it is difficult to do it (Ruby
program can be run in many places).
Because of this background, I set th->base_block before
compiling iseq and restore it after compiling.
Basically, th->base_block is dirty hack (similar to global
variable) and this patch is also dirty.
* bootstraptest/test_eval.rb: add a test for above.
* internal.h: remove unused decl.
* iseq.c (rb_iseq_compile_with_option): add base_block parameter.
set th->base_block before compation and restore it after
compilation.
* ruby.c (require_libraries): pass 0 as base_block instead of
setting th->base_block
* tool/compile_prelude.rb (prelude_eval): apply above changes.
* vm.c, vm_eval.c: ditto.
* vm_core.h: add comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-22 13:32:56 +04:00
|
|
|
make_compile_option(&option, opt);
|
|
|
|
|
2013-07-29 12:00:34 +04:00
|
|
|
parser = rb_parser_new();
|
|
|
|
|
2012-10-27 05:16:25 +04:00
|
|
|
if (RB_TYPE_P((src), T_FILE))
|
2013-07-29 12:00:34 +04:00
|
|
|
node = rb_parser_compile_file_path(parser, file, src, ln);
|
|
|
|
else {
|
|
|
|
node = rb_parser_compile_string_path(parser, file, src, ln);
|
|
|
|
|
|
|
|
if (!node) {
|
|
|
|
rb_exc_raise(GET_THREAD()->errinfo); /* TODO: check err */
|
|
|
|
}
|
|
|
|
}
|
2012-10-27 05:16:25 +04:00
|
|
|
|
* iseq.c, vm_eval.c: set th->base_block properly.
th->base_block is information for (a) parsing, (b) compiling
and (c) setting up the frame to execute the program passed by
`eval' method. For example, (1) parser need to know up-level
variables to detect it is variable or method without paren.
Befor (a), (b) and (c), VM set th->base_block by passed bindng
(or previous frame information). After execute (a), (b) and (c),
VM should clear th->base_block. However, if (a), (b) or (c)
raises an exception, then th->base_block is not cleared.
Problem is that the uncleared value th->balo_block is used for
irrelevant iseq compilation. It causes SEGV or critical error.
I tried to solve this problem: to clear them before exception,
but finally I found out that it is difficult to do it (Ruby
program can be run in many places).
Because of this background, I set th->base_block before
compiling iseq and restore it after compiling.
Basically, th->base_block is dirty hack (similar to global
variable) and this patch is also dirty.
* bootstraptest/test_eval.rb: add a test for above.
* internal.h: remove unused decl.
* iseq.c (rb_iseq_compile_with_option): add base_block parameter.
set th->base_block before compation and restore it after
compilation.
* ruby.c (require_libraries): pass 0 as base_block instead of
setting th->base_block
* tool/compile_prelude.rb (prelude_eval): apply above changes.
* vm.c, vm_eval.c: ditto.
* vm_core.h: add comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-22 13:32:56 +04:00
|
|
|
if (base_block && base_block->iseq) {
|
|
|
|
iseqval = rb_iseq_new_with_opt(node, base_block->iseq->location.label,
|
|
|
|
file, absolute_path, line, base_block->iseq->self,
|
|
|
|
ISEQ_TYPE_EVAL, &option);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
iseqval = rb_iseq_new_with_opt(node, rb_str_new2("<compiled>"), file, absolute_path, line, Qfalse,
|
|
|
|
ISEQ_TYPE_TOP, &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.c, vm_eval.c: set th->base_block properly.
th->base_block is information for (a) parsing, (b) compiling
and (c) setting up the frame to execute the program passed by
`eval' method. For example, (1) parser need to know up-level
variables to detect it is variable or method without paren.
Befor (a), (b) and (c), VM set th->base_block by passed bindng
(or previous frame information). After execute (a), (b) and (c),
VM should clear th->base_block. However, if (a), (b) or (c)
raises an exception, then th->base_block is not cleared.
Problem is that the uncleared value th->balo_block is used for
irrelevant iseq compilation. It causes SEGV or critical error.
I tried to solve this problem: to clear them before exception,
but finally I found out that it is difficult to do it (Ruby
program can be run in many places).
Because of this background, I set th->base_block before
compiling iseq and restore it after compiling.
Basically, th->base_block is dirty hack (similar to global
variable) and this patch is also dirty.
* bootstraptest/test_eval.rb: add a test for above.
* internal.h: remove unused decl.
* iseq.c (rb_iseq_compile_with_option): add base_block parameter.
set th->base_block before compation and restore it after
compilation.
* ruby.c (require_libraries): pass 0 as base_block instead of
setting th->base_block
* tool/compile_prelude.rb (prelude_eval): apply above changes.
* vm.c, vm_eval.c: ditto.
* vm_core.h: add comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-22 13:32:56 +04:00
|
|
|
TH_POP_TAG();
|
|
|
|
|
|
|
|
th->base_block = prev_base_block;
|
|
|
|
|
|
|
|
if (state) {
|
|
|
|
JUMP_TAG(state);
|
* 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.c, vm_eval.c: set th->base_block properly.
th->base_block is information for (a) parsing, (b) compiling
and (c) setting up the frame to execute the program passed by
`eval' method. For example, (1) parser need to know up-level
variables to detect it is variable or method without paren.
Befor (a), (b) and (c), VM set th->base_block by passed bindng
(or previous frame information). After execute (a), (b) and (c),
VM should clear th->base_block. However, if (a), (b) or (c)
raises an exception, then th->base_block is not cleared.
Problem is that the uncleared value th->balo_block is used for
irrelevant iseq compilation. It causes SEGV or critical error.
I tried to solve this problem: to clear them before exception,
but finally I found out that it is difficult to do it (Ruby
program can be run in many places).
Because of this background, I set th->base_block before
compiling iseq and restore it after compiling.
Basically, th->base_block is dirty hack (similar to global
variable) and this patch is also dirty.
* bootstraptest/test_eval.rb: add a test for above.
* internal.h: remove unused decl.
* iseq.c (rb_iseq_compile_with_option): add base_block parameter.
set th->base_block before compation and restore it after
compilation.
* ruby.c (require_libraries): pass 0 as base_block instead of
setting th->base_block
* tool/compile_prelude.rb (prelude_eval): apply above changes.
* vm.c, vm_eval.c: ditto.
* vm_core.h: add comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-22 13:32:56 +04:00
|
|
|
|
|
|
|
return iseqval;
|
* 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(VALUE src, VALUE file, VALUE line)
|
|
|
|
{
|
* iseq.c, vm_eval.c: set th->base_block properly.
th->base_block is information for (a) parsing, (b) compiling
and (c) setting up the frame to execute the program passed by
`eval' method. For example, (1) parser need to know up-level
variables to detect it is variable or method without paren.
Befor (a), (b) and (c), VM set th->base_block by passed bindng
(or previous frame information). After execute (a), (b) and (c),
VM should clear th->base_block. However, if (a), (b) or (c)
raises an exception, then th->base_block is not cleared.
Problem is that the uncleared value th->balo_block is used for
irrelevant iseq compilation. It causes SEGV or critical error.
I tried to solve this problem: to clear them before exception,
but finally I found out that it is difficult to do it (Ruby
program can be run in many places).
Because of this background, I set th->base_block before
compiling iseq and restore it after compiling.
Basically, th->base_block is dirty hack (similar to global
variable) and this patch is also dirty.
* bootstraptest/test_eval.rb: add a test for above.
* internal.h: remove unused decl.
* iseq.c (rb_iseq_compile_with_option): add base_block parameter.
set th->base_block before compation and restore it after
compilation.
* ruby.c (require_libraries): pass 0 as base_block instead of
setting th->base_block
* tool/compile_prelude.rb (prelude_eval): apply above changes.
* vm.c, vm_eval.c: ditto.
* vm_core.h: add comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-22 13:32:56 +04:00
|
|
|
return rb_iseq_compile_with_option(src, file, Qnil, line, 0, Qnil);
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_iseq_compile_on_base(VALUE src, VALUE file, VALUE line, rb_block_t *base_block)
|
|
|
|
{
|
|
|
|
return rb_iseq_compile_with_option(src, file, Qnil, line, base_block, Qnil);
|
* 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
|
|
|
}
|
2007-05-11 10:26:06 +04:00
|
|
|
|
2012-07-25 01:29:24 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* InstructionSequence.compile(source[, file[, path[, line[, options]]]]) -> iseq
|
|
|
|
* InstructionSequence.new(source[, file[, path[, line[, options]]]]) -> iseq
|
|
|
|
*
|
|
|
|
* Takes +source+, a String of Ruby code and compiles it to an
|
|
|
|
* InstructionSequence.
|
|
|
|
*
|
|
|
|
* Optionally takes +file+, +path+, and +line+ which describe the filename,
|
|
|
|
* absolute path and first line number of the ruby code in +source+ which are
|
|
|
|
* metadata attached to the returned +iseq+.
|
|
|
|
*
|
|
|
|
* +options+, which can be +true+, +false+ or a +Hash+, is used to
|
2012-12-29 11:44:54 +04:00
|
|
|
* modify the default behavior of the Ruby iseq compiler.
|
|
|
|
*
|
|
|
|
* For details regarding valid compile options see ::compile_option=.
|
2012-07-25 01:29:24 +04:00
|
|
|
*
|
|
|
|
* RubyVM::InstructionSequence.compile("a = 1 + 2")
|
|
|
|
* #=> <RubyVM::InstructionSequence:<compiled>@<compiled>>
|
|
|
|
*
|
|
|
|
*/
|
* 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)
|
|
|
|
{
|
2010-03-16 20:40:00 +03:00
|
|
|
VALUE src, file = Qnil, path = 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);
|
|
|
|
|
2010-10-29 19:36:33 +04:00
|
|
|
rb_scan_args(argc, argv, "14", &src, &file, &path, &line, &opt);
|
2009-03-10 04:54:01 +03:00
|
|
|
if (NIL_P(file)) file = rb_str_new2("<compiled>");
|
|
|
|
if (NIL_P(line)) line = INT2FIX(1);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* iseq.c, vm_eval.c: set th->base_block properly.
th->base_block is information for (a) parsing, (b) compiling
and (c) setting up the frame to execute the program passed by
`eval' method. For example, (1) parser need to know up-level
variables to detect it is variable or method without paren.
Befor (a), (b) and (c), VM set th->base_block by passed bindng
(or previous frame information). After execute (a), (b) and (c),
VM should clear th->base_block. However, if (a), (b) or (c)
raises an exception, then th->base_block is not cleared.
Problem is that the uncleared value th->balo_block is used for
irrelevant iseq compilation. It causes SEGV or critical error.
I tried to solve this problem: to clear them before exception,
but finally I found out that it is difficult to do it (Ruby
program can be run in many places).
Because of this background, I set th->base_block before
compiling iseq and restore it after compiling.
Basically, th->base_block is dirty hack (similar to global
variable) and this patch is also dirty.
* bootstraptest/test_eval.rb: add a test for above.
* internal.h: remove unused decl.
* iseq.c (rb_iseq_compile_with_option): add base_block parameter.
set th->base_block before compation and restore it after
compilation.
* ruby.c (require_libraries): pass 0 as base_block instead of
setting th->base_block
* tool/compile_prelude.rb (prelude_eval): apply above changes.
* vm.c, vm_eval.c: ditto.
* vm_core.h: add comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-22 13:32:56 +04:00
|
|
|
return rb_iseq_compile_with_option(src, file, path, line, 0, opt);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2012-07-25 01:29:24 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* InstructionSequence.compile_file(file[, options]) -> iseq
|
|
|
|
*
|
|
|
|
* Takes +file+, a String with the location of a Ruby source file, reads,
|
|
|
|
* parses and compiles the file, and returns +iseq+, the compiled
|
|
|
|
* InstructionSequence with source location metadata set.
|
|
|
|
*
|
|
|
|
* Optionally takes +options+, which can be +true+, +false+ or a +Hash+, to
|
2012-12-29 11:44:54 +04:00
|
|
|
* modify the default behavior of the Ruby iseq compiler.
|
|
|
|
*
|
|
|
|
* For details regarding valid compile options see ::compile_option=.
|
2012-07-25 01:29:24 +04:00
|
|
|
*
|
|
|
|
* # /tmp/hello.rb
|
|
|
|
* puts "Hello, world!"
|
|
|
|
*
|
|
|
|
* # elsewhere
|
|
|
|
* RubyVM::InstructionSequence.compile_file("/tmp/hello.rb")
|
|
|
|
* #=> <RubyVM::InstructionSequence:<main>@/tmp/hello.rb>
|
|
|
|
*/
|
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);
|
2008-09-12 22:32:19 +04:00
|
|
|
FilePathValue(file);
|
2006-12-31 18:02:22 +03:00
|
|
|
fname = StringValueCStr(file);
|
|
|
|
|
2008-09-12 22:32:19 +04:00
|
|
|
f = rb_file_open_str(file, "r");
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
parser = rb_parser_new();
|
|
|
|
node = rb_parser_compile_file(parser, fname, f, NUM2INT(line));
|
2014-11-26 05:03:06 +03:00
|
|
|
|
|
|
|
rb_io_close(f);
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
make_compile_option(&option, opt);
|
2010-06-17 18:32:20 +04:00
|
|
|
return rb_iseq_new_with_opt(node, rb_str_new2("<main>"), file,
|
|
|
|
rb_realpath_internal(Qnil, file, 1), line, Qfalse,
|
* 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_TYPE_TOP, &option);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2012-07-25 01:29:24 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* InstructionSequence.compile_option = options
|
|
|
|
*
|
|
|
|
* Sets the default values for various optimizations in the Ruby iseq
|
2012-12-29 11:44:54 +04:00
|
|
|
* compiler.
|
|
|
|
*
|
|
|
|
* Possible values for +options+ include +true+, which enables all options,
|
|
|
|
* +false+ which disables all options, and +nil+ which leaves all options
|
|
|
|
* unchanged.
|
|
|
|
*
|
|
|
|
* You can also pass a +Hash+ of +options+ that you want to change, any
|
|
|
|
* options not present in the hash will be left unchanged.
|
2012-07-25 01:29:24 +04:00
|
|
|
*
|
|
|
|
* Possible option names (which are keys in +options+) which can be set to
|
|
|
|
* +true+ or +false+ include:
|
|
|
|
*
|
|
|
|
* * +:inline_const_cache+
|
|
|
|
* * +:instructions_unification+
|
|
|
|
* * +:operands_unification+
|
|
|
|
* * +:peephole_optimization+
|
|
|
|
* * +:specialized_instruction+
|
|
|
|
* * +:stack_caching+
|
|
|
|
* * +:tailcall_optimization+
|
|
|
|
* * +:trace_instruction+
|
|
|
|
*
|
|
|
|
* Additionally, +:debug_level+ can be set to an integer.
|
|
|
|
*
|
|
|
|
* These default options can be overwritten for a single run of the iseq
|
|
|
|
* compiler by passing any of the above values as the +options+ parameter to
|
2012-12-29 11:44:54 +04:00
|
|
|
* ::new, ::compile and ::compile_file.
|
2012-07-25 01:29:24 +04:00
|
|
|
*/
|
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;
|
|
|
|
}
|
|
|
|
|
2012-07-25 01:29:24 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* InstructionSequence.compile_option -> options
|
|
|
|
*
|
|
|
|
* Returns a hash of default options used by the Ruby iseq compiler.
|
2012-12-29 11:44:54 +04:00
|
|
|
*
|
2012-07-25 01:29:24 +04:00
|
|
|
* For details, see InstructionSequence.compile_option=.
|
|
|
|
*/
|
2007-08-06 08:34:11 +04:00
|
|
|
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);
|
2012-06-04 06:49:37 +04:00
|
|
|
if (!iseq->location.label) {
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_raise(rb_eTypeError, "uninitialized InstructionSequence");
|
|
|
|
}
|
|
|
|
return iseq;
|
|
|
|
}
|
|
|
|
|
2012-07-25 01:29:24 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* iseq.eval -> obj
|
|
|
|
*
|
|
|
|
* Evaluates the instruction sequence and returns the result.
|
|
|
|
*
|
|
|
|
* RubyVM::InstructionSequence.compile("1 + 2").eval #=> 3
|
|
|
|
*/
|
2006-12-31 18:02:22 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-07-25 01:29:24 +04:00
|
|
|
/*
|
2012-12-29 10:29:47 +04:00
|
|
|
* Returns a human-readable string representation of this instruction
|
|
|
|
* sequence, including the #label and #path.
|
2012-07-25 01:29:24 +04:00
|
|
|
*/
|
2006-12-31 18:02:22 +03:00
|
|
|
static VALUE
|
|
|
|
iseq_inspect(VALUE self)
|
|
|
|
{
|
2008-08-21 21:25:43 +04:00
|
|
|
rb_iseq_t *iseq;
|
|
|
|
GetISeqPtr(self, iseq);
|
2012-06-04 06:49:37 +04:00
|
|
|
if (!iseq->location.label) {
|
2008-08-21 21:25:43 +04:00
|
|
|
return rb_sprintf("#<%s: uninitialized>", rb_obj_classname(self));
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2008-08-21 21:25:43 +04:00
|
|
|
return rb_sprintf("<%s:%s@%s>",
|
|
|
|
rb_obj_classname(self),
|
2012-06-04 06:49:37 +04:00
|
|
|
RSTRING_PTR(iseq->location.label), RSTRING_PTR(iseq->location.path));
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2012-12-29 10:29:47 +04:00
|
|
|
/*
|
|
|
|
* Returns the path of this instruction sequence.
|
|
|
|
*
|
2012-12-29 11:44:54 +04:00
|
|
|
* <code><compiled></code> if the iseq was evaluated from a string.
|
|
|
|
*
|
2012-12-29 10:29:47 +04:00
|
|
|
* For example, using irb:
|
|
|
|
*
|
2012-12-29 11:44:54 +04:00
|
|
|
* iseq = RubyVM::InstructionSequence.compile('num = 1 + 2')
|
2012-12-29 10:29:47 +04:00
|
|
|
* #=> <RubyVM::InstructionSequence:<compiled>@<compiled>>
|
2012-12-29 11:44:54 +04:00
|
|
|
* iseq.path
|
2012-12-29 10:29:47 +04:00
|
|
|
* #=> "<compiled>"
|
|
|
|
*
|
|
|
|
* Using ::compile_file:
|
|
|
|
*
|
|
|
|
* # /tmp/method.rb
|
|
|
|
* def hello
|
|
|
|
* puts "hello, world"
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* # in irb
|
2012-12-29 11:44:54 +04:00
|
|
|
* > iseq = RubyVM::InstructionSequence.compile_file('/tmp/method.rb')
|
|
|
|
* > iseq.path #=> /tmp/method.rb
|
2012-12-29 10:29:47 +04:00
|
|
|
*/
|
2013-10-07 09:12:08 +04:00
|
|
|
VALUE
|
|
|
|
rb_iseq_path(VALUE self)
|
2012-11-30 22:02:43 +04:00
|
|
|
{
|
|
|
|
rb_iseq_t *iseq;
|
|
|
|
GetISeqPtr(self, iseq);
|
|
|
|
return iseq->location.path;
|
|
|
|
}
|
|
|
|
|
2012-12-29 10:29:47 +04:00
|
|
|
/*
|
|
|
|
* Returns the absolute path of this instruction sequence.
|
|
|
|
*
|
2012-12-29 11:44:54 +04:00
|
|
|
* +nil+ if the iseq was evaluated from a string.
|
|
|
|
*
|
2012-12-29 10:29:47 +04:00
|
|
|
* For example, using ::compile_file:
|
|
|
|
*
|
|
|
|
* # /tmp/method.rb
|
|
|
|
* def hello
|
|
|
|
* puts "hello, world"
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* # in irb
|
2012-12-29 11:44:54 +04:00
|
|
|
* > iseq = RubyVM::InstructionSequence.compile_file('/tmp/method.rb')
|
|
|
|
* > iseq.absolute_path #=> /tmp/method.rb
|
2012-12-29 10:29:47 +04:00
|
|
|
*/
|
2013-10-07 09:12:08 +04:00
|
|
|
VALUE
|
|
|
|
rb_iseq_absolute_path(VALUE self)
|
2012-11-30 22:02:43 +04:00
|
|
|
{
|
|
|
|
rb_iseq_t *iseq;
|
|
|
|
GetISeqPtr(self, iseq);
|
|
|
|
return iseq->location.absolute_path;
|
|
|
|
}
|
|
|
|
|
2012-12-29 10:29:47 +04:00
|
|
|
/* Returns the label of this instruction sequence.
|
2012-12-29 11:44:54 +04:00
|
|
|
*
|
|
|
|
* <code><main></code> if it's at the top level, <code><compiled></code> if it
|
|
|
|
* was evaluated from a string.
|
2012-12-29 10:29:47 +04:00
|
|
|
*
|
|
|
|
* For example, using irb:
|
|
|
|
*
|
2012-12-29 11:44:54 +04:00
|
|
|
* iseq = RubyVM::InstructionSequence.compile('num = 1 + 2')
|
2012-12-29 10:29:47 +04:00
|
|
|
* #=> <RubyVM::InstructionSequence:<compiled>@<compiled>>
|
2012-12-29 11:44:54 +04:00
|
|
|
* iseq.label
|
2012-12-29 10:29:47 +04:00
|
|
|
* #=> "<compiled>"
|
|
|
|
*
|
|
|
|
* Using ::compile_file:
|
|
|
|
*
|
|
|
|
* # /tmp/method.rb
|
|
|
|
* def hello
|
|
|
|
* puts "hello, world"
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* # in irb
|
2012-12-29 11:44:54 +04:00
|
|
|
* > iseq = RubyVM::InstructionSequence.compile_file('/tmp/method.rb')
|
|
|
|
* > iseq.label #=> <main>
|
2012-12-29 10:29:47 +04:00
|
|
|
*/
|
2013-10-07 09:12:08 +04:00
|
|
|
VALUE
|
|
|
|
rb_iseq_label(VALUE self)
|
2012-11-30 22:02:43 +04:00
|
|
|
{
|
|
|
|
rb_iseq_t *iseq;
|
|
|
|
GetISeqPtr(self, iseq);
|
|
|
|
return iseq->location.label;
|
|
|
|
}
|
|
|
|
|
2012-12-29 10:29:47 +04:00
|
|
|
/* Returns the base label of this instruction sequence.
|
|
|
|
*
|
|
|
|
* For example, using irb:
|
|
|
|
*
|
2012-12-29 11:44:54 +04:00
|
|
|
* iseq = RubyVM::InstructionSequence.compile('num = 1 + 2')
|
2012-12-29 10:29:47 +04:00
|
|
|
* #=> <RubyVM::InstructionSequence:<compiled>@<compiled>>
|
2012-12-29 11:44:54 +04:00
|
|
|
* iseq.base_label
|
2012-12-29 10:29:47 +04:00
|
|
|
* #=> "<compiled>"
|
|
|
|
*
|
|
|
|
* Using ::compile_file:
|
|
|
|
*
|
|
|
|
* # /tmp/method.rb
|
|
|
|
* def hello
|
|
|
|
* puts "hello, world"
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* # in irb
|
2012-12-29 11:44:54 +04:00
|
|
|
* > iseq = RubyVM::InstructionSequence.compile_file('/tmp/method.rb')
|
|
|
|
* > iseq.base_label #=> <main>
|
2012-12-29 10:29:47 +04:00
|
|
|
*/
|
2013-10-07 09:12:08 +04:00
|
|
|
VALUE
|
|
|
|
rb_iseq_base_label(VALUE self)
|
2012-11-30 22:02:43 +04:00
|
|
|
{
|
|
|
|
rb_iseq_t *iseq;
|
|
|
|
GetISeqPtr(self, iseq);
|
|
|
|
return iseq->location.base_label;
|
|
|
|
}
|
|
|
|
|
2012-12-29 11:44:54 +04:00
|
|
|
/* Returns the number of the first source line where the instruction sequence
|
|
|
|
* was loaded from.
|
2012-12-29 10:29:47 +04:00
|
|
|
*
|
|
|
|
* For example, using irb:
|
|
|
|
*
|
2012-12-29 11:44:54 +04:00
|
|
|
* iseq = RubyVM::InstructionSequence.compile('num = 1 + 2')
|
2012-12-29 10:29:47 +04:00
|
|
|
* #=> <RubyVM::InstructionSequence:<compiled>@<compiled>>
|
2012-12-29 11:44:54 +04:00
|
|
|
* iseq.first_lineno
|
2012-12-29 10:29:47 +04:00
|
|
|
* #=> 1
|
|
|
|
*/
|
2013-10-07 09:12:08 +04:00
|
|
|
VALUE
|
|
|
|
rb_iseq_first_lineno(VALUE self)
|
2012-11-30 22:02:43 +04:00
|
|
|
{
|
|
|
|
rb_iseq_t *iseq;
|
|
|
|
GetISeqPtr(self, iseq);
|
|
|
|
return iseq->location.first_lineno;
|
|
|
|
}
|
|
|
|
|
2013-10-07 09:12:08 +04:00
|
|
|
VALUE
|
|
|
|
rb_iseq_klass(VALUE self)
|
|
|
|
{
|
|
|
|
rb_iseq_t *iseq;
|
|
|
|
GetISeqPtr(self, iseq);
|
2013-10-07 11:21:11 +04:00
|
|
|
return iseq->local_iseq->klass;
|
2013-10-07 09:12:08 +04:00
|
|
|
}
|
|
|
|
|
2013-10-08 16:08:20 +04:00
|
|
|
VALUE
|
|
|
|
rb_iseq_method_name(VALUE self)
|
|
|
|
{
|
|
|
|
rb_iseq_t *iseq, *local_iseq;
|
|
|
|
GetISeqPtr(self, iseq);
|
|
|
|
local_iseq = iseq->local_iseq;
|
|
|
|
if (local_iseq->type == ISEQ_TYPE_METHOD) {
|
|
|
|
return local_iseq->location.base_label;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-04 22:23:27 +04:00
|
|
|
static
|
* 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
|
|
|
|
2012-07-25 01:29:24 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* iseq.to_a -> ary
|
|
|
|
*
|
2012-12-29 11:44:54 +04:00
|
|
|
* Returns an Array with 14 elements representing the instruction sequence
|
|
|
|
* with the following data:
|
2012-07-25 01:29:24 +04:00
|
|
|
*
|
|
|
|
* [magic]
|
2012-12-29 11:44:54 +04:00
|
|
|
* A string identifying the data format. <b>Always
|
|
|
|
* +YARVInstructionSequence/SimpleDataFormat+.</b>
|
2012-07-25 01:29:24 +04:00
|
|
|
*
|
|
|
|
* [major_version]
|
|
|
|
* The major version of the instruction sequence.
|
|
|
|
*
|
|
|
|
* [minor_version]
|
|
|
|
* The minor version of the instruction sequence.
|
|
|
|
*
|
|
|
|
* [format_type]
|
2012-12-29 11:44:54 +04:00
|
|
|
* A number identifying the data format. <b>Always 1</b>.
|
2012-07-25 01:29:24 +04:00
|
|
|
*
|
|
|
|
* [misc]
|
2012-12-29 11:44:54 +04:00
|
|
|
* A hash containing:
|
|
|
|
*
|
|
|
|
* [+:arg_size+]
|
|
|
|
* the total number of arguments taken by the method or the block (0 if
|
|
|
|
* _iseq_ doesn't represent a method or block)
|
|
|
|
* [+:local_size+]
|
|
|
|
* the number of local variables + 1
|
|
|
|
* [+:stack_max+]
|
|
|
|
* used in calculating the stack depth at which a SystemStackError is
|
|
|
|
* thrown.
|
|
|
|
*
|
|
|
|
* [#label]
|
2012-07-25 01:29:24 +04:00
|
|
|
* The name of the context (block, method, class, module, etc.) that this
|
2012-12-29 11:44:54 +04:00
|
|
|
* instruction sequence belongs to.
|
|
|
|
*
|
|
|
|
* <code><main></code> if it's at the top level, <code><compiled></code> if
|
|
|
|
* it was evaluated from a string.
|
2012-07-25 01:29:24 +04:00
|
|
|
*
|
2012-12-29 11:44:54 +04:00
|
|
|
* [#path]
|
2012-07-25 01:29:24 +04:00
|
|
|
* The relative path to the Ruby file where the instruction sequence was
|
2012-12-29 11:44:54 +04:00
|
|
|
* loaded from.
|
|
|
|
*
|
|
|
|
* <code><compiled></code> if the iseq was evaluated from a string.
|
2012-07-25 01:29:24 +04:00
|
|
|
*
|
2012-12-29 11:44:54 +04:00
|
|
|
* [#absolute_path]
|
2012-07-25 01:29:24 +04:00
|
|
|
* The absolute path to the Ruby file where the instruction sequence was
|
2012-12-29 11:44:54 +04:00
|
|
|
* loaded from.
|
2012-07-25 01:29:24 +04:00
|
|
|
*
|
2012-12-29 11:44:54 +04:00
|
|
|
* +nil+ if the iseq was evaluated from a string.
|
|
|
|
*
|
|
|
|
* [#first_lineno]
|
2012-07-25 01:29:24 +04:00
|
|
|
* The number of the first source line where the instruction sequence was
|
|
|
|
* loaded from.
|
|
|
|
*
|
|
|
|
* [type]
|
2012-12-29 11:44:54 +04:00
|
|
|
* The type of the instruction sequence.
|
|
|
|
*
|
|
|
|
* Valid values are +:top+, +:method+, +:block+, +:class+, +:rescue+,
|
|
|
|
* +:ensure+, +:eval+, +:main+, and +:defined_guard+.
|
2012-07-25 01:29:24 +04:00
|
|
|
*
|
|
|
|
* [locals]
|
|
|
|
* An array containing the names of all arguments and local variables as
|
|
|
|
* symbols.
|
|
|
|
*
|
2014-11-03 02:14:21 +03:00
|
|
|
* [params]
|
|
|
|
* An Hash object containing parameter information.
|
2012-07-25 01:29:24 +04:00
|
|
|
*
|
|
|
|
* More info about these values can be found in +vm_core.h+.
|
|
|
|
*
|
|
|
|
* [catch_table]
|
|
|
|
* A list of exceptions and control flow operators (rescue, next, redo,
|
|
|
|
* break, etc.).
|
|
|
|
*
|
|
|
|
* [bytecode]
|
|
|
|
* An array of arrays containing the instruction names and operands that
|
|
|
|
* make up the body of the instruction sequence.
|
|
|
|
*
|
2014-11-03 02:14:21 +03:00
|
|
|
* Note that this format is MRI specific and version dependent.
|
|
|
|
*
|
2012-07-25 01:29:24 +04:00
|
|
|
*/
|
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. */
|
|
|
|
|
2011-08-24 10:31:15 +04:00
|
|
|
static struct iseq_line_info_entry *
|
|
|
|
get_line_info(const rb_iseq_t *iseq, size_t pos)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2011-08-24 10:31:15 +04:00
|
|
|
size_t i = 0, size = iseq->line_info_size;
|
|
|
|
struct iseq_line_info_entry *table = iseq->line_info_table;
|
|
|
|
const int debug = 0;
|
|
|
|
|
|
|
|
if (debug) {
|
2011-08-29 07:54:35 +04:00
|
|
|
printf("size: %"PRIdSIZE"\n", size);
|
|
|
|
printf("table[%"PRIdSIZE"]: position: %d, line: %d, pos: %"PRIdSIZE"\n",
|
2011-08-24 10:31:15 +04:00
|
|
|
i, table[i].position, table[i].line_no, pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if (size == 1) {
|
|
|
|
return &table[0];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (i=1; i<size; i++) {
|
2011-08-29 07:54:35 +04:00
|
|
|
if (debug) printf("table[%"PRIdSIZE"]: position: %d, line: %d, pos: %"PRIdSIZE"\n",
|
2011-08-24 10:31:15 +04:00
|
|
|
i, table[i].position, table[i].line_no, pos);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2011-09-15 09:24:42 +04:00
|
|
|
if (table[i].position == pos) {
|
|
|
|
return &table[i];
|
|
|
|
}
|
2011-08-24 10:31:15 +04:00
|
|
|
if (table[i].position > pos) {
|
|
|
|
return &table[i-1];
|
2011-09-15 09:24:42 +04:00
|
|
|
}
|
2011-08-24 10:31:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return &table[i-1];
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2011-08-24 10:31:15 +04:00
|
|
|
static unsigned int
|
|
|
|
find_line_no(const rb_iseq_t *iseq, size_t pos)
|
2007-12-20 00:39:08 +03:00
|
|
|
{
|
2011-08-24 10:31:15 +04:00
|
|
|
struct iseq_line_info_entry *entry = get_line_info(iseq, pos);
|
2007-12-20 00:39:08 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-08-24 10:31:15 +04:00
|
|
|
unsigned int
|
|
|
|
rb_iseq_line_no(const rb_iseq_t *iseq, size_t pos)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2011-08-24 10:31:15 +04:00
|
|
|
if (pos == 0) {
|
|
|
|
return find_line_no(iseq, pos);
|
2011-09-15 09:24:42 +04:00
|
|
|
}
|
|
|
|
else {
|
2011-08-24 10:31:15 +04:00
|
|
|
return find_line_no(iseq, pos - 1);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2011-09-15 09:24:42 +04:00
|
|
|
}
|
2007-08-12 23:09:15 +04:00
|
|
|
|
2012-06-09 18:36:56 +04:00
|
|
|
static VALUE
|
|
|
|
id_to_name(ID id, VALUE default_value)
|
|
|
|
{
|
|
|
|
VALUE str = rb_id2str(id);
|
|
|
|
if (!str) {
|
|
|
|
str = default_value;
|
|
|
|
}
|
|
|
|
else if (!rb_str_symname_p(str)) {
|
|
|
|
str = rb_str_inspect(str);
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2012-10-04 16:31:05 +04:00
|
|
|
VALUE
|
2014-06-18 10:16:39 +04:00
|
|
|
rb_insn_operand_intern(const rb_iseq_t *iseq,
|
2013-03-06 10:30:03 +04:00
|
|
|
VALUE insn, int op_no, VALUE op,
|
2014-06-18 10:16:39 +04:00
|
|
|
int len, size_t pos, const VALUE *pnop, VALUE child)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2008-04-03 04:00:48 +04:00
|
|
|
const char *types = insn_op_types(insn);
|
2006-12-31 18:02:22 +03:00
|
|
|
char type = types[op_no];
|
|
|
|
VALUE ret;
|
|
|
|
|
|
|
|
switch (type) {
|
2007-05-11 10:26:06 +04:00
|
|
|
case TS_OFFSET: /* LONG */
|
2010-10-15 18:11:26 +04:00
|
|
|
ret = rb_sprintf("%"PRIdVALUE, (VALUE)(pos + len + op));
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
|
2007-05-11 10:26:06 +04:00
|
|
|
case TS_NUM: /* ULONG */
|
2010-10-13 18:07:22 +04:00
|
|
|
ret = rb_sprintf("%"PRIuVALUE, op);
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
|
2012-10-04 17:52:20 +04:00
|
|
|
case TS_LINDEX:{
|
|
|
|
if (insn == BIN(getlocal) || insn == BIN(setlocal)) {
|
2012-10-04 16:31:05 +04:00
|
|
|
if (pnop) {
|
2014-06-18 10:16:39 +04:00
|
|
|
const rb_iseq_t *diseq = iseq;
|
2012-10-04 16:31:05 +04:00
|
|
|
VALUE level = *pnop, i;
|
2012-06-09 18:36:56 +04:00
|
|
|
|
2012-10-04 16:31:05 +04:00
|
|
|
for (i = 0; i < level; i++) {
|
|
|
|
diseq = diseq->parent_iseq;
|
|
|
|
}
|
|
|
|
ret = id_to_name(diseq->local_table[diseq->local_size - op], INT2FIX('*'));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ret = rb_sprintf("%"PRIuVALUE, op);
|
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);
|
2008-05-14 07:48:39 +04:00
|
|
|
|
2007-05-11 10:26:06 +04:00
|
|
|
case TS_VALUE: /* VALUE */
|
2009-02-18 08:33:36 +03:00
|
|
|
op = obj_resurrect(op);
|
2008-05-14 07:48:39 +04:00
|
|
|
ret = rb_inspect(op);
|
|
|
|
if (CLASS_OF(op) == rb_cISeq) {
|
2012-10-04 16:31:05 +04:00
|
|
|
if (child) {
|
|
|
|
rb_ary_push(child, op);
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
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) {
|
2012-06-04 06:49:37 +04:00
|
|
|
ret = iseq->location.label;
|
2006-12-31 18:02:22 +03:00
|
|
|
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
|
|
|
{
|
2009-07-16 04:01:06 +04:00
|
|
|
struct rb_global_entry *entry = (struct rb_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:
|
2013-08-20 21:41:13 +04:00
|
|
|
ret = rb_sprintf("<is:%"PRIdPTRDIFF">", (union iseq_inline_storage_entry *)op - iseq->is_entries);
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
|
2012-10-10 21:52:24 +04:00
|
|
|
case TS_CALLINFO:
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
{
|
|
|
|
rb_call_info_t *ci = (rb_call_info_t *)op;
|
|
|
|
VALUE ary = rb_ary_new();
|
|
|
|
|
|
|
|
if (ci->mid) {
|
2014-11-23 20:03:32 +03:00
|
|
|
rb_ary_push(ary, rb_sprintf("mid:%"PRIsVALUE, rb_id2str(ci->mid)));
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
rb_ary_push(ary, rb_sprintf("argc:%d", ci->orig_argc));
|
|
|
|
|
* rewrite method/block parameter fitting logic to optimize
keyword arguments/parameters and a splat argument.
[Feature #10440] (Details are described in this ticket)
Most of complex part is moved to vm_args.c.
Now, ISeq#to_a does not catch up new instruction format.
* vm_core.h: change iseq data structures.
* introduce rb_call_info_kw_arg_t to represent keyword arguments.
* add rb_call_info_t::kw_arg.
* rename rb_iseq_t::arg_post_len to rb_iseq_t::arg_post_num.
* rename rb_iseq_t::arg_keywords to arg_keyword_num.
* rename rb_iseq_t::arg_keyword to rb_iseq_t::arg_keyword_bits.
to represent keyword bitmap parameter index.
This bitmap parameter shows that which keyword parameters are given
or not given (0 for given).
It is refered by `checkkeyword' instruction described bellow.
* rename rb_iseq_t::arg_keyword_check to rb_iseq_t::arg_keyword_rest
to represent keyword rest parameter index.
* add rb_iseq_t::arg_keyword_default_values to represent default
keyword values.
* rename VM_CALL_ARGS_SKIP_SETUP to VM_CALL_ARGS_SIMPLE
to represent
(ci->flag & (SPLAT|BLOCKARG)) &&
ci->blockiseq == NULL &&
ci->kw_arg == NULL.
* vm_insnhelper.c, vm_args.c: rewrite with refactoring.
* rewrite splat argument code.
* rewrite keyword arguments/parameters code.
* merge method and block parameter fitting code into one code base.
* vm.c, vm_eval.c: catch up these changes.
* compile.c (new_callinfo): callinfo requires kw_arg parameter.
* compile.c (compile_array_): check the last argument Hash object or
not. If Hash object and all keys are Symbol literals, they are
compiled to keyword arguments.
* insns.def (checkkeyword): add new instruction.
This instruction check the availability of corresponding keyword.
For example, a method "def foo k1: 'v1'; end" is cimpiled to the
following instructions.
0000 checkkeyword 2, 0 # check k1 is given.
0003 branchif 9 # if given, jump to address #9
0005 putstring "v1"
0007 setlocal_OP__WC__0 3 # k1 = 'v1'
0009 trace 8
0011 putnil
0012 trace 16
0014 leave
* insns.def (opt_send_simple): removed and add new instruction
"opt_send_without_block".
* parse.y (new_args_tail_gen): reorder variables.
Before this patch, a method "def foo(k1: 1, kr1:, k2: 2, **krest, &b)"
has parameter variables "k1, kr1, k2, &b, internal_id, krest",
but this patch reorders to "kr1, k1, k2, internal_id, krest, &b".
(locate a block variable at last)
* parse.y (vtable_pop): added.
This function remove latest `n' variables from vtable.
* iseq.c: catch up iseq data changes.
* proc.c: ditto.
* class.c (keyword_error): export as rb_keyword_error().
* common.mk: depend vm_args.c for vm.o.
* hash.c (rb_hash_has_key): export.
* internal.h: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-02 21:02:55 +03:00
|
|
|
if (ci->kw_arg) {
|
|
|
|
rb_ary_push(ary, rb_sprintf("kw:%d", ci->kw_arg->keyword_len));
|
|
|
|
}
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
if (ci->blockiseq) {
|
|
|
|
if (child) {
|
|
|
|
rb_ary_push(child, ci->blockiseq->self);
|
|
|
|
}
|
|
|
|
rb_ary_push(ary, rb_sprintf("block:%"PRIsVALUE, ci->blockiseq->location.label));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ci->flag) {
|
|
|
|
VALUE flags = rb_ary_new();
|
2012-10-15 21:22:57 +04:00
|
|
|
if (ci->flag & VM_CALL_ARGS_SPLAT) rb_ary_push(flags, rb_str_new2("ARGS_SPLAT"));
|
|
|
|
if (ci->flag & VM_CALL_ARGS_BLOCKARG) rb_ary_push(flags, rb_str_new2("ARGS_BLOCKARG"));
|
|
|
|
if (ci->flag & VM_CALL_FCALL) rb_ary_push(flags, rb_str_new2("FCALL"));
|
|
|
|
if (ci->flag & VM_CALL_VCALL) rb_ary_push(flags, rb_str_new2("VCALL"));
|
|
|
|
if (ci->flag & VM_CALL_TAILCALL) rb_ary_push(flags, rb_str_new2("TAILCALL"));
|
|
|
|
if (ci->flag & VM_CALL_SUPER) rb_ary_push(flags, rb_str_new2("SUPER"));
|
|
|
|
if (ci->flag & VM_CALL_OPT_SEND) rb_ary_push(flags, rb_str_new2("SNED")); /* maybe not reachable */
|
* rewrite method/block parameter fitting logic to optimize
keyword arguments/parameters and a splat argument.
[Feature #10440] (Details are described in this ticket)
Most of complex part is moved to vm_args.c.
Now, ISeq#to_a does not catch up new instruction format.
* vm_core.h: change iseq data structures.
* introduce rb_call_info_kw_arg_t to represent keyword arguments.
* add rb_call_info_t::kw_arg.
* rename rb_iseq_t::arg_post_len to rb_iseq_t::arg_post_num.
* rename rb_iseq_t::arg_keywords to arg_keyword_num.
* rename rb_iseq_t::arg_keyword to rb_iseq_t::arg_keyword_bits.
to represent keyword bitmap parameter index.
This bitmap parameter shows that which keyword parameters are given
or not given (0 for given).
It is refered by `checkkeyword' instruction described bellow.
* rename rb_iseq_t::arg_keyword_check to rb_iseq_t::arg_keyword_rest
to represent keyword rest parameter index.
* add rb_iseq_t::arg_keyword_default_values to represent default
keyword values.
* rename VM_CALL_ARGS_SKIP_SETUP to VM_CALL_ARGS_SIMPLE
to represent
(ci->flag & (SPLAT|BLOCKARG)) &&
ci->blockiseq == NULL &&
ci->kw_arg == NULL.
* vm_insnhelper.c, vm_args.c: rewrite with refactoring.
* rewrite splat argument code.
* rewrite keyword arguments/parameters code.
* merge method and block parameter fitting code into one code base.
* vm.c, vm_eval.c: catch up these changes.
* compile.c (new_callinfo): callinfo requires kw_arg parameter.
* compile.c (compile_array_): check the last argument Hash object or
not. If Hash object and all keys are Symbol literals, they are
compiled to keyword arguments.
* insns.def (checkkeyword): add new instruction.
This instruction check the availability of corresponding keyword.
For example, a method "def foo k1: 'v1'; end" is cimpiled to the
following instructions.
0000 checkkeyword 2, 0 # check k1 is given.
0003 branchif 9 # if given, jump to address #9
0005 putstring "v1"
0007 setlocal_OP__WC__0 3 # k1 = 'v1'
0009 trace 8
0011 putnil
0012 trace 16
0014 leave
* insns.def (opt_send_simple): removed and add new instruction
"opt_send_without_block".
* parse.y (new_args_tail_gen): reorder variables.
Before this patch, a method "def foo(k1: 1, kr1:, k2: 2, **krest, &b)"
has parameter variables "k1, kr1, k2, &b, internal_id, krest",
but this patch reorders to "kr1, k1, k2, internal_id, krest, &b".
(locate a block variable at last)
* parse.y (vtable_pop): added.
This function remove latest `n' variables from vtable.
* iseq.c: catch up iseq data changes.
* proc.c: ditto.
* class.c (keyword_error): export as rb_keyword_error().
* common.mk: depend vm_args.c for vm.o.
* hash.c (rb_hash_has_key): export.
* internal.h: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-02 21:02:55 +03:00
|
|
|
if (ci->flag & VM_CALL_ARGS_SIMPLE) rb_ary_push(flags, rb_str_new2("ARGS_SIMPLE")); /* maybe not reachable */
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
rb_ary_push(ary, rb_ary_join(flags, rb_str_new2("|")));
|
|
|
|
}
|
|
|
|
ret = rb_sprintf("<callinfo!%"PRIsVALUE">", rb_ary_join(ary, rb_str_new2(", ")));
|
|
|
|
}
|
2012-10-10 21:52:24 +04:00
|
|
|
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:
|
2014-12-16 04:14:27 +03:00
|
|
|
{
|
|
|
|
#ifdef HAVE_DLADDR
|
|
|
|
Dl_info info;
|
|
|
|
if (dladdr((void *)op, &info) && info.dli_sname) {
|
|
|
|
ret = rb_str_new_cstr(info.dli_sname);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
ret = rb_str_new2("<funcptr>");
|
|
|
|
}
|
2007-08-12 23:09:15 +04:00
|
|
|
break;
|
|
|
|
|
2007-05-11 10:26:06 +04:00
|
|
|
default:
|
2012-10-04 16:31:05 +04:00
|
|
|
rb_bug("insn_operand_intern: unknown operand type: %c", type);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disassemble a instruction
|
|
|
|
* Iseq -> Iseq inspect object
|
|
|
|
*/
|
* compile.c, cont.c, gc.c, insns.def, iseq.c, iseq.h, process.c,
thread.c, vm.c, vm_core.h, vm_dump.c, vm_eval.c,
vm_insnhelper.c, vm_method.c, template/insns_info.inc.tmpl,
tool/instruction.rb: fixed types.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-09-22 00:58:26 +04:00
|
|
|
int
|
2014-06-18 10:16:39 +04:00
|
|
|
rb_iseq_disasm_insn(VALUE ret, const VALUE *iseq, size_t pos,
|
|
|
|
const rb_iseq_t *iseqdat, VALUE child)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
* compile.c, cont.c, gc.c, insns.def, iseq.c, iseq.h, process.c,
thread.c, vm.c, vm_core.h, vm_dump.c, vm_eval.c,
vm_insnhelper.c, vm_method.c, template/insns_info.inc.tmpl,
tool/instruction.rb: fixed types.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-09-22 00:58:26 +04:00
|
|
|
VALUE insn = iseq[pos];
|
2006-12-31 18:02:22 +03:00
|
|
|
int len = insn_len(insn);
|
* compile.c (insn_data_to_s_detail), file.c (rb_stat_inspect),
iseq.c (ruby_iseq_disasm_insn, ruby_iseq_disasm),
process.c (pst_message), re.c (match_inspect): use rb_str_catf.
* dir.c (dir_inspect), iseq.c (iseq_inspect, insn_operand_intern): use
rb_sprintf.
* error.c (rb_name_error, rb_raise, rb_loaderror, rb_fatal): use
rb_vsprintf.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-07-22 12:53:34 +04:00
|
|
|
int j;
|
2008-04-03 04:00:48 +04:00
|
|
|
const char *types = insn_op_types(insn);
|
2006-12-31 18:02:22 +03:00
|
|
|
VALUE str = rb_str_new(0, 0);
|
* compile.c (insn_data_to_s_detail), file.c (rb_stat_inspect),
iseq.c (ruby_iseq_disasm_insn, ruby_iseq_disasm),
process.c (pst_message), re.c (match_inspect): use rb_str_catf.
* dir.c (dir_inspect), iseq.c (iseq_inspect, insn_operand_intern): use
rb_sprintf.
* error.c (rb_name_error, rb_raise, rb_loaderror, rb_fatal): use
rb_vsprintf.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-07-22 12:53:34 +04:00
|
|
|
const char *insn_name_buff;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
* compile.c (insn_data_to_s_detail), file.c (rb_stat_inspect),
iseq.c (ruby_iseq_disasm_insn, ruby_iseq_disasm),
process.c (pst_message), re.c (match_inspect): use rb_str_catf.
* dir.c (dir_inspect), iseq.c (iseq_inspect, insn_operand_intern): use
rb_sprintf.
* error.c (rb_name_error, rb_raise, rb_loaderror, rb_fatal): use
rb_vsprintf.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-07-22 12:53:34 +04:00
|
|
|
insn_name_buff = insn_name(insn);
|
|
|
|
if (1) {
|
* compile.c, cont.c, gc.c, insns.def, iseq.c, iseq.h, process.c,
thread.c, vm.c, vm_core.h, vm_dump.c, vm_eval.c,
vm_insnhelper.c, vm_method.c, template/insns_info.inc.tmpl,
tool/instruction.rb: fixed types.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-09-22 00:58:26 +04:00
|
|
|
rb_str_catf(str, "%04"PRIdSIZE" %-16s ", pos, insn_name_buff);
|
* compile.c (insn_data_to_s_detail), file.c (rb_stat_inspect),
iseq.c (ruby_iseq_disasm_insn, ruby_iseq_disasm),
process.c (pst_message), re.c (match_inspect): use rb_str_catf.
* dir.c (dir_inspect), iseq.c (iseq_inspect, insn_operand_intern): use
rb_sprintf.
* error.c (rb_name_error, rb_raise, rb_loaderror, rb_fatal): use
rb_vsprintf.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-07-22 12:53:34 +04:00
|
|
|
}
|
|
|
|
else {
|
* compile.c, cont.c, gc.c, insns.def, iseq.c, iseq.h, process.c,
thread.c, vm.c, vm_core.h, vm_dump.c, vm_eval.c,
vm_insnhelper.c, vm_method.c, template/insns_info.inc.tmpl,
tool/instruction.rb: fixed types.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-09-22 00:58:26 +04:00
|
|
|
rb_str_catf(str, "%04"PRIdSIZE" %-16.*s ", pos,
|
2008-07-31 05:51:44 +04:00
|
|
|
(int)strcspn(insn_name_buff, "_"), insn_name_buff);
|
* compile.c (insn_data_to_s_detail), file.c (rb_stat_inspect),
iseq.c (ruby_iseq_disasm_insn, ruby_iseq_disasm),
process.c (pst_message), re.c (match_inspect): use rb_str_catf.
* dir.c (dir_inspect), iseq.c (iseq_inspect, insn_operand_intern): use
rb_sprintf.
* error.c (rb_name_error, rb_raise, rb_loaderror, rb_fatal): use
rb_vsprintf.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-07-22 12:53:34 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
for (j = 0; types[j]; j++) {
|
2008-04-03 04:00:48 +04:00
|
|
|
const char *types = insn_op_types(insn);
|
2013-03-06 10:30:03 +04:00
|
|
|
VALUE opstr = rb_insn_operand_intern(iseqdat, insn, j, iseq[pos + j + 1],
|
|
|
|
len, pos, &iseq[pos + j + 2],
|
|
|
|
child);
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_str_concat(str, opstr);
|
|
|
|
|
|
|
|
if (types[j + 1]) {
|
|
|
|
rb_str_cat2(str, ", ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-24 10:31:15 +04:00
|
|
|
{
|
|
|
|
unsigned int line_no = find_line_no(iseqdat, pos);
|
|
|
|
unsigned int prev = pos == 0 ? 0 : find_line_no(iseqdat, pos - 1);
|
2006-12-31 18:02:22 +03:00
|
|
|
if (line_no && line_no != prev) {
|
* compile.c (insn_data_to_s_detail), file.c (rb_stat_inspect),
iseq.c (ruby_iseq_disasm_insn, ruby_iseq_disasm),
process.c (pst_message), re.c (match_inspect): use rb_str_catf.
* dir.c (dir_inspect), iseq.c (iseq_inspect, insn_operand_intern): use
rb_sprintf.
* error.c (rb_name_error, rb_raise, rb_loaderror, rb_fatal): use
rb_vsprintf.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-07-22 12:53:34 +04:00
|
|
|
long slen = RSTRING_LEN(str);
|
|
|
|
slen = (slen > 70) ? 0 : (70 - slen);
|
|
|
|
str = rb_str_catf(str, "%*s(%4d)", (int)slen, "", line_no);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
2007-12-20 00:39:08 +03:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-05-31 13:28:20 +04:00
|
|
|
static const char *
|
2006-12-31 18:02:22 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-25 01:29:24 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* iseq.disasm -> str
|
|
|
|
* iseq.disassemble -> str
|
|
|
|
*
|
|
|
|
* Returns the instruction sequence as a +String+ in human readable form.
|
|
|
|
*
|
|
|
|
* puts RubyVM::InstructionSequence.compile('1 + 2').disasm
|
|
|
|
*
|
|
|
|
* Produces:
|
|
|
|
*
|
|
|
|
* == disasm: <RubyVM::InstructionSequence:<compiled>@<compiled>>==========
|
|
|
|
* 0000 trace 1 ( 1)
|
|
|
|
* 0002 putobject 1
|
|
|
|
* 0004 putobject 2
|
|
|
|
* 0006 opt_plus <ic:1>
|
|
|
|
* 0008 leave
|
|
|
|
*/
|
2006-12-31 18:02:22 +03:00
|
|
|
VALUE
|
2009-01-19 04:06:56 +03:00
|
|
|
rb_iseq_disasm(VALUE self)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2014-11-03 02:14:21 +03:00
|
|
|
rb_iseq_t *iseqdat = iseq_check(self); /* TODO: rename to iseq */
|
2006-12-31 18:02:22 +03:00
|
|
|
VALUE *iseq;
|
|
|
|
VALUE str = rb_str_new(0, 0);
|
|
|
|
VALUE child = rb_ary_new();
|
2014-07-26 11:30:26 +04:00
|
|
|
unsigned int 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;
|
2009-03-11 23:19:24 +03:00
|
|
|
long l;
|
2006-12-31 18:02:22 +03:00
|
|
|
ID *tbl;
|
* compile.c, cont.c, gc.c, insns.def, iseq.c, iseq.h, process.c,
thread.c, vm.c, vm_core.h, vm_dump.c, vm_eval.c,
vm_insnhelper.c, vm_method.c, template/insns_info.inc.tmpl,
tool/instruction.rb: fixed types.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-09-22 00:58:26 +04:00
|
|
|
size_t n;
|
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);
|
|
|
|
|
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));
|
2009-03-11 23:19:24 +03:00
|
|
|
if ((l = RSTRING_LEN(str)) < header_minlen) {
|
2007-08-06 08:34:11 +04:00
|
|
|
rb_str_resize(str, header_minlen);
|
2009-03-11 23:19:24 +03:00
|
|
|
memset(RSTRING_PTR(str) + l, '=', header_minlen - l);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
rb_str_cat2(str, "\n");
|
|
|
|
|
|
|
|
/* show catch table information */
|
2014-07-14 11:06:26 +04:00
|
|
|
if (iseqdat->catch_table) {
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_str_cat2(str, "== catch table\n");
|
|
|
|
}
|
2014-07-14 11:06:26 +04:00
|
|
|
if (iseqdat->catch_table) for (i = 0; i < iseqdat->catch_table->size; i++) {
|
|
|
|
struct iseq_catch_table_entry *entry = &iseqdat->catch_table->entries[i];
|
* compile.c (insn_data_to_s_detail), file.c (rb_stat_inspect),
iseq.c (ruby_iseq_disasm_insn, ruby_iseq_disasm),
process.c (pst_message), re.c (match_inspect): use rb_str_catf.
* dir.c (dir_inspect), iseq.c (iseq_inspect, insn_operand_intern): use
rb_sprintf.
* error.c (rb_name_error, rb_raise, rb_loaderror, rb_fatal): use
rb_vsprintf.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-07-22 12:53:34 +04:00
|
|
|
rb_str_catf(str,
|
|
|
|
"| 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);
|
2006-12-31 18:02:22 +03:00
|
|
|
if (entry->iseq) {
|
2009-01-19 04:06:56 +03:00
|
|
|
rb_str_concat(str, rb_iseq_disasm(entry->iseq));
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
2014-07-14 11:06:26 +04:00
|
|
|
if (iseqdat->catch_table) {
|
2006-12-31 18:02:22 +03:00
|
|
|
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) {
|
* compile.c (insn_data_to_s_detail), file.c (rb_stat_inspect),
iseq.c (ruby_iseq_disasm_insn, ruby_iseq_disasm),
process.c (pst_message), re.c (match_inspect): use rb_str_catf.
* dir.c (dir_inspect), iseq.c (iseq_inspect, insn_operand_intern): use
rb_sprintf.
* error.c (rb_name_error, rb_raise, rb_loaderror, rb_fatal): use
rb_vsprintf.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-07-22 12:53:34 +04:00
|
|
|
rb_str_catf(str,
|
|
|
|
"local table (size: %d, argc: %d "
|
2014-11-03 02:14:21 +03:00
|
|
|
"[opts: %d, rest: %d, post: %d, block: %d, kw: %d@%d, kwrest: %d])\n",
|
|
|
|
iseqdat->local_size,
|
|
|
|
iseqdat->param.lead_num,
|
2014-11-03 07:43:07 +03:00
|
|
|
iseqdat->param.opt_num,
|
2014-11-03 02:14:21 +03:00
|
|
|
iseqdat->param.flags.has_rest ? iseqdat->param.rest_start : -1,
|
|
|
|
iseqdat->param.post_num,
|
|
|
|
iseqdat->param.flags.has_block ? iseqdat->param.block_start : -1,
|
|
|
|
iseqdat->param.flags.has_kw ? iseqdat->param.keyword->num : -1,
|
|
|
|
iseqdat->param.flags.has_kw ? iseqdat->param.keyword->required_num : -1,
|
|
|
|
iseqdat->param.flags.has_kwrest ? iseqdat->param.keyword->rest_start : -1);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-02-25 04:34:33 +03:00
|
|
|
for (i = 0; i < iseqdat->local_table_size; i++) {
|
2012-06-09 18:36:56 +04:00
|
|
|
long width;
|
|
|
|
VALUE name = id_to_name(tbl[i], 0);
|
2006-12-31 18:02:22 +03:00
|
|
|
char argi[0x100] = "";
|
|
|
|
char opti[0x100] = "";
|
|
|
|
|
2014-11-03 02:14:21 +03:00
|
|
|
if (iseqdat->param.flags.has_opt) {
|
|
|
|
int argc = iseqdat->param.lead_num;
|
|
|
|
int opts = iseqdat->param.opt_num;
|
2014-11-03 07:43:07 +03:00
|
|
|
if (i >= argc && i < argc + opts) {
|
2010-10-13 18:07:22 +04:00
|
|
|
snprintf(opti, sizeof(opti), "Opt=%"PRIdVALUE,
|
2014-11-03 02:14:21 +03:00
|
|
|
iseqdat->param.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 */
|
2014-11-03 02:14:21 +03:00
|
|
|
iseqdat->param.lead_num > i ? "Arg" : "",
|
2006-12-31 18:02:22 +03:00
|
|
|
opti,
|
2014-11-03 02:14:21 +03:00
|
|
|
(iseqdat->param.flags.has_rest && iseqdat->param.rest_start == i) ? "Rest" : "",
|
|
|
|
(iseqdat->param.flags.has_post && iseqdat->param.post_start <= i && i < iseqdat->param.post_start + iseqdat->param.post_num) ? "Post" : "",
|
|
|
|
(iseqdat->param.flags.has_block && iseqdat->param.block_start == i) ? "Block" : "");
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2012-06-09 18:36:56 +04:00
|
|
|
rb_str_catf(str, "[%2d] ", iseqdat->local_size - i);
|
|
|
|
width = RSTRING_LEN(str) + 11;
|
|
|
|
if (name)
|
|
|
|
rb_str_append(str, name);
|
|
|
|
else
|
|
|
|
rb_str_cat2(str, "?");
|
|
|
|
if (*argi) rb_str_catf(str, "<%s>", argi);
|
|
|
|
if ((width -= RSTRING_LEN(str)) > 0) rb_str_catf(str, "%*s", (int)width, "");
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
rb_str_cat2(str, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* show each line */
|
compile: translate iseq in-place
running "ruby -rpp -e 'pp GC.stat'", a reduction in
malloc usage is shown:
before:
:malloc_increase=>118784,
:oldmalloc_increase=>1178736,
after:
:malloc_increase=>99832,
:oldmalloc_increase=>1031976,
For "ruby -e exit", valgrind reports over 300K reduction in
overall allocations (and unnecessary memory copies).
before:
total heap usage: 49,622 allocs, 20,492 frees, 8,697,493 bytes allocated
after:
total heap usage: 48,935 allocs, 19,805 frees, 8,373,773 bytes allocated
(numbers from x86-64)
v2 changes based on ko1 recommendations [ruby-core:64883]:
- squashed in-place direct thread translation to avoid alloc+copy
- renamed rb_iseq_untranslate_threaded_code to rb_iseq_original_iseq,
cache new iseq->iseq_original field.
* compile.c (rb_iseq_translate_threaded_code): modify in-place w/o copy
(rb_vm_addr2insn): new function for debug
(rb_iseq_original_iseq): ditto
(iseq_set_sequence): assign iseq_encoded directly
[Feature #10185]
* vm_core (rb_iseq_t): move original ->iseq to bottom
* iseq.c (iseq_free, iseq_free): adjust for new layout
(rb_iseq_disasm): use original iseq for dump
(iseq_data_to_ary): ditto
(rb_iseq_line_trace_each): ditto
(rb_iseq_build_for_ruby2cext): use iseq_encoded directly
* vm_dump.c (rb_vmdebug_debug_print_pre): use original iseq
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 10:14:07 +04:00
|
|
|
iseq = rb_iseq_original_iseq(iseqdat);
|
* compile.c, cont.c, gc.c, insns.def, iseq.c, iseq.h, process.c,
thread.c, vm.c, vm_core.h, vm_dump.c, vm_eval.c,
vm_insnhelper.c, vm_method.c, template/insns_info.inc.tmpl,
tool/instruction.rb: fixed types.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-09-22 00:58:26 +04:00
|
|
|
for (n = 0; n < size;) {
|
|
|
|
n += rb_iseq_disasm_insn(str, iseq, n, 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);
|
2009-01-19 04:06:56 +03:00
|
|
|
rb_str_concat(str, rb_iseq_disasm(isv));
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2012-12-29 10:29:47 +04:00
|
|
|
/*
|
|
|
|
* Returns the instruction sequence containing the given proc or method.
|
|
|
|
*
|
|
|
|
* For example, using irb:
|
|
|
|
*
|
|
|
|
* # a proc
|
|
|
|
* > p = proc { num = 1 + 2 }
|
|
|
|
* > RubyVM::InstructionSequence.of(p)
|
|
|
|
* > #=> <RubyVM::InstructionSequence:block in irb_binding@(irb)>
|
|
|
|
*
|
|
|
|
* # for a method
|
|
|
|
* > def foo(bar); puts bar; end
|
|
|
|
* > RubyVM::InstructionSequence.of(method(:foo))
|
|
|
|
* > #=> <RubyVM::InstructionSequence:foo@(irb)>
|
|
|
|
*
|
|
|
|
* Using ::compile_file:
|
|
|
|
*
|
|
|
|
* # /tmp/iseq_of.rb
|
|
|
|
* def hello
|
|
|
|
* puts "hello, world"
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* $a_global_proc = proc { str = 'a' + 'b' }
|
|
|
|
*
|
|
|
|
* # in irb
|
|
|
|
* > require '/tmp/iseq_of.rb'
|
|
|
|
*
|
|
|
|
* # first the method hello
|
|
|
|
* > RubyVM::InstructionSequence.of(method(:hello))
|
|
|
|
* > #=> #<RubyVM::InstructionSequence:0x007fb73d7cb1d0>
|
|
|
|
*
|
|
|
|
* # then the global proc
|
|
|
|
* > RubyVM::InstructionSequence.of($a_global_proc)
|
|
|
|
* > #=> #<RubyVM::InstructionSequence:0x007fb73d7caf78>
|
|
|
|
*/
|
2012-11-30 22:02:43 +04:00
|
|
|
static VALUE
|
|
|
|
iseq_s_of(VALUE klass, VALUE body)
|
|
|
|
{
|
|
|
|
VALUE ret = Qnil;
|
|
|
|
rb_iseq_t *iseq;
|
|
|
|
|
|
|
|
rb_secure(1);
|
|
|
|
|
|
|
|
if (rb_obj_is_proc(body)) {
|
|
|
|
rb_proc_t *proc;
|
|
|
|
GetProcPtr(body, proc);
|
|
|
|
iseq = proc->block.iseq;
|
|
|
|
if (RUBY_VM_NORMAL_ISEQ_P(iseq)) {
|
|
|
|
ret = iseq->self;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((iseq = rb_method_get_iseq(body)) != 0) {
|
|
|
|
ret = iseq->self;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-07-25 01:29:24 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* InstructionSequence.disasm(body) -> str
|
|
|
|
* InstructionSequence.disassemble(body) -> str
|
|
|
|
*
|
|
|
|
* Takes +body+, a Method or Proc object, and returns a String with the
|
|
|
|
* human readable instructions for +body+.
|
|
|
|
*
|
|
|
|
* For a Method object:
|
|
|
|
*
|
|
|
|
* # /tmp/method.rb
|
|
|
|
* def hello
|
|
|
|
* puts "hello, world"
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* puts RubyVM::InstructionSequence.disasm(method(:hello))
|
|
|
|
*
|
|
|
|
* Produces:
|
|
|
|
*
|
|
|
|
* == disasm: <RubyVM::InstructionSequence:hello@/tmp/method.rb>============
|
|
|
|
* 0000 trace 8 ( 1)
|
|
|
|
* 0002 trace 1 ( 2)
|
|
|
|
* 0004 putself
|
|
|
|
* 0005 putstring "hello, world"
|
|
|
|
* 0007 send :puts, 1, nil, 8, <ic:0>
|
|
|
|
* 0013 trace 16 ( 3)
|
|
|
|
* 0015 leave ( 2)
|
|
|
|
*
|
|
|
|
* For a Proc:
|
|
|
|
*
|
|
|
|
* # /tmp/proc.rb
|
|
|
|
* p = proc { num = 1 + 2 }
|
|
|
|
* puts RubyVM::InstructionSequence.disasm(p)
|
|
|
|
*
|
|
|
|
* Produces:
|
|
|
|
*
|
|
|
|
* == disasm: <RubyVM::InstructionSequence:block in <main>@/tmp/proc.rb>===
|
|
|
|
* == catch table
|
|
|
|
* | catch type: redo st: 0000 ed: 0012 sp: 0000 cont: 0000
|
|
|
|
* | catch type: next st: 0000 ed: 0012 sp: 0000 cont: 0012
|
|
|
|
* |------------------------------------------------------------------------
|
|
|
|
* local table (size: 2, argc: 0 [opts: 0, rest: -1, post: 0, block: -1] s1)
|
|
|
|
* [ 2] num
|
|
|
|
* 0000 trace 1 ( 1)
|
|
|
|
* 0002 putobject 1
|
|
|
|
* 0004 putobject 2
|
|
|
|
* 0006 opt_plus <ic:1>
|
|
|
|
* 0008 dup
|
2012-10-04 17:52:20 +04:00
|
|
|
* 0009 setlocal num, 0
|
2012-07-25 01:29:24 +04:00
|
|
|
* 0012 leave
|
|
|
|
*
|
|
|
|
*/
|
2012-11-30 22:02:43 +04:00
|
|
|
|
2007-12-24 12:09:21 +03:00
|
|
|
static VALUE
|
|
|
|
iseq_s_disasm(VALUE klass, VALUE body)
|
|
|
|
{
|
2012-11-30 22:02:43 +04:00
|
|
|
VALUE iseqval = iseq_s_of(klass, body);
|
|
|
|
return NIL_P(iseqval) ? Qnil : rb_iseq_disasm(iseqval);
|
2007-12-24 12:09:21 +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
|
|
|
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
|
* compile.c, cont.c, gc.c, insns.def, iseq.c, iseq.h, process.c,
thread.c, vm.c, vm_core.h, vm_dump.c, vm_eval.c,
vm_insnhelper.c, vm_method.c, template/insns_info.inc.tmpl,
tool/instruction.rb: fixed types.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-09-22 00:58:26 +04:00
|
|
|
register_label(struct st_table *table, unsigned long idx)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2014-10-14 11:23:01 +04:00
|
|
|
VALUE sym = rb_str_intern(rb_sprintf("label_%lu", idx));
|
2006-12-31 18:02:22 +03:00
|
|
|
st_insert(table, idx, sym);
|
|
|
|
return sym;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
exception_type2symbol(VALUE type)
|
|
|
|
{
|
|
|
|
ID id;
|
2012-12-29 16:22:04 +04:00
|
|
|
switch (type) {
|
2008-06-09 13:25:32 +04:00
|
|
|
case CATCH_TYPE_RESCUE: CONST_ID(id, "rescue"); break;
|
|
|
|
case CATCH_TYPE_ENSURE: CONST_ID(id, "ensure"); break;
|
|
|
|
case CATCH_TYPE_RETRY: CONST_ID(id, "retry"); break;
|
|
|
|
case CATCH_TYPE_BREAK: CONST_ID(id, "break"); break;
|
|
|
|
case CATCH_TYPE_REDO: CONST_ID(id, "redo"); break;
|
|
|
|
case CATCH_TYPE_NEXT: CONST_ID(id, "next"); break;
|
2006-12-31 18:02:22 +03:00
|
|
|
default:
|
|
|
|
rb_bug("...");
|
|
|
|
}
|
|
|
|
return ID2SYM(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
cdhash_each(VALUE key, VALUE value, VALUE ary)
|
|
|
|
{
|
2009-02-26 07:23:21 +03:00
|
|
|
rb_ary_push(ary, obj_resurrect(key));
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_ary_push(ary, value);
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2008-09-04 22:23:27 +04: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
|
|
|
iseq_data_to_ary(rb_iseq_t *iseq)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2012-01-14 16:56:46 +04:00
|
|
|
long i;
|
|
|
|
size_t ti;
|
2011-08-26 23:04:39 +04:00
|
|
|
unsigned int pos;
|
2011-08-24 10:31:15 +04:00
|
|
|
unsigned int line = 0;
|
compile: translate iseq in-place
running "ruby -rpp -e 'pp GC.stat'", a reduction in
malloc usage is shown:
before:
:malloc_increase=>118784,
:oldmalloc_increase=>1178736,
after:
:malloc_increase=>99832,
:oldmalloc_increase=>1031976,
For "ruby -e exit", valgrind reports over 300K reduction in
overall allocations (and unnecessary memory copies).
before:
total heap usage: 49,622 allocs, 20,492 frees, 8,697,493 bytes allocated
after:
total heap usage: 48,935 allocs, 19,805 frees, 8,373,773 bytes allocated
(numbers from x86-64)
v2 changes based on ko1 recommendations [ruby-core:64883]:
- squashed in-place direct thread translation to avoid alloc+copy
- renamed rb_iseq_untranslate_threaded_code to rb_iseq_original_iseq,
cache new iseq->iseq_original field.
* compile.c (rb_iseq_translate_threaded_code): modify in-place w/o copy
(rb_vm_addr2insn): new function for debug
(rb_iseq_original_iseq): ditto
(iseq_set_sequence): assign iseq_encoded directly
[Feature #10185]
* vm_core (rb_iseq_t): move original ->iseq to bottom
* iseq.c (iseq_free, iseq_free): adjust for new layout
(rb_iseq_disasm): use original iseq for dump
(iseq_data_to_ary): ditto
(rb_iseq_line_trace_each): ditto
(rb_iseq_build_for_ruby2cext): use iseq_encoded directly
* vm_dump.c (rb_vmdebug_debug_print_pre): use original iseq
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 10:14:07 +04:00
|
|
|
VALUE *seq, *iseq_original;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
VALUE val = rb_ary_new();
|
|
|
|
VALUE type; /* Symbol */
|
|
|
|
VALUE locals = rb_ary_new();
|
2014-11-03 02:14:21 +03:00
|
|
|
VALUE params = rb_hash_new();
|
2006-12-31 18:02:22 +03:00
|
|
|
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);
|
2008-12-27 08:58:23 +03:00
|
|
|
DECL_SYMBOL(main);
|
2008-05-22 15:16:40 +04:00
|
|
|
DECL_SYMBOL(defined_guard);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
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);
|
2008-12-27 08:58:23 +03:00
|
|
|
INIT_SYMBOL(main);
|
2008-05-22 15:16:40 +04:00
|
|
|
INIT_SYMBOL(defined_guard);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2007-05-11 10:26:06 +04:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
/* type */
|
2012-12-29 16:22:04 +04:00
|
|
|
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;
|
2008-12-27 08:58:23 +03:00
|
|
|
case ISEQ_TYPE_MAIN: type = sym_main; break;
|
2008-05-22 15:16:40 +04:00
|
|
|
case ISEQ_TYPE_DEFINED_GUARD: type = sym_defined_guard; 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) {
|
2014-12-02 01:32:56 +03:00
|
|
|
if (rb_id2str(lid)) {
|
|
|
|
rb_ary_push(locals, ID2SYM(lid));
|
|
|
|
}
|
|
|
|
else { /* hidden variable from id_internal() */
|
2014-12-02 07:54:57 +03:00
|
|
|
rb_ary_push(locals, ULONG2NUM(iseq->local_table_size-i+1));
|
2014-12-02 01:32:56 +03:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_ary_push(locals, ID2SYM(rb_intern("#arg_rest")));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-03 02:14:21 +03:00
|
|
|
/* params */
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
int j;
|
|
|
|
|
2014-12-04 01:16:58 +03:00
|
|
|
if (iseq->param.flags.has_opt) {
|
|
|
|
int len = iseq->param.opt_num + 1;
|
|
|
|
VALUE arg_opt_labels = rb_ary_new2(len);
|
|
|
|
|
|
|
|
for (j = 0; j < len; j++) {
|
|
|
|
VALUE l = register_label(labels_table, iseq->param.opt_table[j]);
|
|
|
|
rb_ary_push(arg_opt_labels, l);
|
|
|
|
}
|
|
|
|
rb_hash_aset(params, ID2SYM(rb_intern("opt")), arg_opt_labels);
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
/* commit */
|
2014-11-03 02:14:21 +03:00
|
|
|
if (iseq->param.flags.has_lead) rb_hash_aset(params, ID2SYM(rb_intern("lead_num")), INT2FIX(iseq->param.lead_num));
|
|
|
|
if (iseq->param.flags.has_post) rb_hash_aset(params, ID2SYM(rb_intern("post_num")), INT2FIX(iseq->param.post_num));
|
|
|
|
if (iseq->param.flags.has_post) rb_hash_aset(params, ID2SYM(rb_intern("post_start")), INT2FIX(iseq->param.post_start));
|
|
|
|
if (iseq->param.flags.has_rest) rb_hash_aset(params, ID2SYM(rb_intern("rest_start")), INT2FIX(iseq->param.rest_start));
|
|
|
|
if (iseq->param.flags.has_block) rb_hash_aset(params, ID2SYM(rb_intern("block_start")), INT2FIX(iseq->param.block_start));
|
|
|
|
if (iseq->param.flags.has_kw) {
|
|
|
|
VALUE keywords = rb_ary_new();
|
|
|
|
int i, j;
|
|
|
|
for (i=0; i<iseq->param.keyword->required_num; i++) {
|
|
|
|
rb_ary_push(keywords, ID2SYM(iseq->param.keyword->table[i]));
|
|
|
|
}
|
|
|
|
for (j=0; i<iseq->param.keyword->num; i++, j++) {
|
|
|
|
VALUE key = rb_ary_new_from_args(1, ID2SYM(iseq->param.keyword->table[i]));
|
|
|
|
if (iseq->param.keyword->default_values[j] != Qundef) {
|
|
|
|
rb_ary_push(key, iseq->param.keyword->default_values[j]);
|
|
|
|
}
|
|
|
|
rb_ary_push(keywords, key);
|
|
|
|
}
|
2014-12-04 01:16:58 +03:00
|
|
|
|
|
|
|
rb_hash_aset(params, ID2SYM(rb_intern("kwbits")),
|
|
|
|
INT2FIX(iseq->param.keyword->bits_start));
|
2014-11-03 02:14:21 +03:00
|
|
|
rb_hash_aset(params, ID2SYM(rb_intern("keyword")), keywords);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2014-11-03 02:14:21 +03:00
|
|
|
if (iseq->param.flags.has_kwrest) rb_hash_aset(params, ID2SYM(rb_intern("kwrest")), INT2FIX(iseq->param.keyword->rest_start));
|
|
|
|
if (iseq->param.flags.ambiguous_param0) rb_hash_aset(params, ID2SYM(rb_intern("ambiguous_param0")), Qtrue);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* body */
|
compile: translate iseq in-place
running "ruby -rpp -e 'pp GC.stat'", a reduction in
malloc usage is shown:
before:
:malloc_increase=>118784,
:oldmalloc_increase=>1178736,
after:
:malloc_increase=>99832,
:oldmalloc_increase=>1031976,
For "ruby -e exit", valgrind reports over 300K reduction in
overall allocations (and unnecessary memory copies).
before:
total heap usage: 49,622 allocs, 20,492 frees, 8,697,493 bytes allocated
after:
total heap usage: 48,935 allocs, 19,805 frees, 8,373,773 bytes allocated
(numbers from x86-64)
v2 changes based on ko1 recommendations [ruby-core:64883]:
- squashed in-place direct thread translation to avoid alloc+copy
- renamed rb_iseq_untranslate_threaded_code to rb_iseq_original_iseq,
cache new iseq->iseq_original field.
* compile.c (rb_iseq_translate_threaded_code): modify in-place w/o copy
(rb_vm_addr2insn): new function for debug
(rb_iseq_original_iseq): ditto
(iseq_set_sequence): assign iseq_encoded directly
[Feature #10185]
* vm_core (rb_iseq_t): move original ->iseq to bottom
* iseq.c (iseq_free, iseq_free): adjust for new layout
(rb_iseq_disasm): use original iseq for dump
(iseq_data_to_ary): ditto
(rb_iseq_line_trace_each): ditto
(rb_iseq_build_for_ruby2cext): use iseq_encoded directly
* vm_dump.c (rb_vmdebug_debug_print_pre): use original iseq
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 10:14:07 +04:00
|
|
|
iseq_original = rb_iseq_original_iseq(iseq);
|
|
|
|
|
|
|
|
for (seq = iseq_original; seq < iseq_original + 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: {
|
compile: translate iseq in-place
running "ruby -rpp -e 'pp GC.stat'", a reduction in
malloc usage is shown:
before:
:malloc_increase=>118784,
:oldmalloc_increase=>1178736,
after:
:malloc_increase=>99832,
:oldmalloc_increase=>1031976,
For "ruby -e exit", valgrind reports over 300K reduction in
overall allocations (and unnecessary memory copies).
before:
total heap usage: 49,622 allocs, 20,492 frees, 8,697,493 bytes allocated
after:
total heap usage: 48,935 allocs, 19,805 frees, 8,373,773 bytes allocated
(numbers from x86-64)
v2 changes based on ko1 recommendations [ruby-core:64883]:
- squashed in-place direct thread translation to avoid alloc+copy
- renamed rb_iseq_untranslate_threaded_code to rb_iseq_original_iseq,
cache new iseq->iseq_original field.
* compile.c (rb_iseq_translate_threaded_code): modify in-place w/o copy
(rb_vm_addr2insn): new function for debug
(rb_iseq_original_iseq): ditto
(iseq_set_sequence): assign iseq_encoded directly
[Feature #10185]
* vm_core (rb_iseq_t): move original ->iseq to bottom
* iseq.c (iseq_free, iseq_free): adjust for new layout
(rb_iseq_disasm): use original iseq for dump
(iseq_data_to_ary): ditto
(rb_iseq_line_trace_each): ditto
(rb_iseq_build_for_ruby2cext): use iseq_encoded directly
* vm_dump.c (rb_vmdebug_debug_print_pre): use original iseq
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 10:14:07 +04:00
|
|
|
unsigned long idx = nseq - iseq_original + *seq;
|
2007-05-11 10:26:06 +04:00
|
|
|
rb_ary_push(ary, register_label(labels_table, idx));
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
case TS_LINDEX:
|
|
|
|
case TS_NUM:
|
|
|
|
rb_ary_push(ary, INT2FIX(*seq));
|
|
|
|
break;
|
|
|
|
case TS_VALUE:
|
2009-02-18 08:33:36 +03:00
|
|
|
rb_ary_push(ary, obj_resurrect(*seq));
|
2006-12-31 18:02:22 +03:00
|
|
|
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:
|
|
|
|
{
|
2009-07-16 04:01:06 +04:00
|
|
|
struct rb_global_entry *entry = (struct rb_global_entry *)*seq;
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_ary_push(ary, ID2SYM(entry->id));
|
|
|
|
}
|
|
|
|
break;
|
2013-08-20 21:41:13 +04:00
|
|
|
case TS_IC:
|
|
|
|
{
|
|
|
|
union iseq_inline_storage_entry *is = (union iseq_inline_storage_entry *)*seq;
|
|
|
|
rb_ary_push(ary, INT2FIX(is - iseq->is_entries));
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
case TS_CALLINFO:
|
|
|
|
{
|
|
|
|
rb_call_info_t *ci = (rb_call_info_t *)*seq;
|
|
|
|
VALUE e = rb_hash_new();
|
2014-12-04 01:16:58 +03:00
|
|
|
int orig_argc = ci->orig_argc;
|
|
|
|
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
rb_hash_aset(e, ID2SYM(rb_intern("mid")), ci->mid ? ID2SYM(ci->mid) : Qnil);
|
2014-12-04 01:16:58 +03:00
|
|
|
rb_hash_aset(e, ID2SYM(rb_intern("flag")), UINT2NUM(ci->flag));
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
rb_hash_aset(e, ID2SYM(rb_intern("blockptr")), ci->blockiseq ? iseq_data_to_ary(ci->blockiseq) : Qnil);
|
2014-12-04 01:16:58 +03:00
|
|
|
|
|
|
|
if (ci->kw_arg) {
|
|
|
|
int i;
|
|
|
|
VALUE kw = rb_ary_new2((long)ci->kw_arg->keyword_len);
|
|
|
|
|
|
|
|
orig_argc -= ci->kw_arg->keyword_len;
|
|
|
|
for (i = 0; i < ci->kw_arg->keyword_len; i++) {
|
|
|
|
rb_ary_push(kw, ID2SYM(ci->kw_arg->keywords[i]));
|
|
|
|
}
|
|
|
|
rb_hash_aset(e, ID2SYM(rb_intern("kw_arg")), kw);
|
|
|
|
}
|
|
|
|
|
|
|
|
rb_hash_aset(e, ID2SYM(rb_intern("orig_argc")),
|
|
|
|
INT2FIX(orig_argc));
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 20:59:05 +04:00
|
|
|
rb_ary_push(ary, e);
|
|
|
|
}
|
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
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));
|
compile: translate iseq in-place
running "ruby -rpp -e 'pp GC.stat'", a reduction in
malloc usage is shown:
before:
:malloc_increase=>118784,
:oldmalloc_increase=>1178736,
after:
:malloc_increase=>99832,
:oldmalloc_increase=>1031976,
For "ruby -e exit", valgrind reports over 300K reduction in
overall allocations (and unnecessary memory copies).
before:
total heap usage: 49,622 allocs, 20,492 frees, 8,697,493 bytes allocated
after:
total heap usage: 48,935 allocs, 19,805 frees, 8,373,773 bytes allocated
(numbers from x86-64)
v2 changes based on ko1 recommendations [ruby-core:64883]:
- squashed in-place direct thread translation to avoid alloc+copy
- renamed rb_iseq_untranslate_threaded_code to rb_iseq_original_iseq,
cache new iseq->iseq_original field.
* compile.c (rb_iseq_translate_threaded_code): modify in-place w/o copy
(rb_vm_addr2insn): new function for debug
(rb_iseq_original_iseq): ditto
(iseq_set_sequence): assign iseq_encoded directly
[Feature #10185]
* vm_core (rb_iseq_t): move original ->iseq to bottom
* iseq.c (iseq_free, iseq_free): adjust for new layout
(rb_iseq_disasm): use original iseq for dump
(iseq_data_to_ary): ditto
(rb_iseq_line_trace_each): ditto
(rb_iseq_build_for_ruby2cext): use iseq_encoded directly
* vm_dump.c (rb_vmdebug_debug_print_pre): use original iseq
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 10:14:07 +04:00
|
|
|
unsigned long idx = nseq - iseq_original + pos;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
rb_ary_store(val, i+1,
|
|
|
|
register_label(labels_table, idx));
|
|
|
|
}
|
|
|
|
rb_ary_push(ary, val);
|
|
|
|
}
|
|
|
|
break;
|
2014-12-16 04:14:20 +03:00
|
|
|
case TS_FUNCPTR:
|
2014-12-16 08:54:32 +03:00
|
|
|
{
|
|
|
|
#if SIZEOF_VALUE <= SIZEOF_LONG
|
|
|
|
VALUE val = LONG2NUM((SIGNED_VALUE)*seq);
|
|
|
|
#else
|
|
|
|
VALUE val = LL2NUM((SIGNED_VALUE)*seq);
|
|
|
|
#endif
|
|
|
|
rb_ary_push(ary, val);
|
|
|
|
}
|
2014-12-16 04:14:20 +03:00
|
|
|
break;
|
2006-12-31 18:02:22 +03:00
|
|
|
default:
|
|
|
|
rb_bug("unknown operand: %c", insn_op_type(insn, j));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rb_ary_push(body, ary);
|
|
|
|
}
|
|
|
|
|
|
|
|
nbody = body;
|
|
|
|
|
|
|
|
/* exception */
|
2014-07-14 11:06:26 +04:00
|
|
|
if (iseq->catch_table) for (i=0; i<iseq->catch_table->size; i++) {
|
2006-12-31 18:02:22 +03:00
|
|
|
VALUE ary = rb_ary_new();
|
2014-07-14 11:06:26 +04:00
|
|
|
struct iseq_catch_table_entry *entry = &iseq->catch_table->entries[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));
|
2014-12-04 01:16:58 +03:00
|
|
|
rb_ary_push(ary, UINT2NUM(entry->sp));
|
2006-12-31 18:02:22 +03:00
|
|
|
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();
|
2011-08-24 10:31:15 +04:00
|
|
|
ti = 0;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
for (i=0, pos=0; i<RARRAY_LEN(nbody); i++) {
|
2013-05-13 13:56:22 +04:00
|
|
|
VALUE ary = RARRAY_AREF(nbody, i);
|
* compile.c (iseq_build_body), error.c (set_syserr, get_syserr),
(syserr_initialize), gc.c (define_final, rb_gc_copy_finalizer),
(run_final), hash.c (rb_hash_aref, rb_hash_lookup2),
(rb_hash_fetch_m, rb_hash_clear, rb_hash_aset, eql_i),
iseq.c (iseq_load, iseq_data_to_ary), marshal.c (r_symlink),
thread.c (rb_thread_local_aref),
variable.c (generic_ivar_remove, ivar_get, rb_const_get_0),
(rb_cvar_get), vm.c (rb_vm_check_redefinition_opt_method),
vm_insnhelper.c (vm_get_ev_const), vm_method.c (remove_method),
ext/iconv/iconv.c (map_charset): use st_data_t.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-10-12 18:47:23 +04:00
|
|
|
st_data_t label;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
if (st_lookup(labels_table, pos, &label)) {
|
2010-10-12 18:35:40 +04:00
|
|
|
rb_ary_push(body, (VALUE)label);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2013-02-28 15:26:23 +04:00
|
|
|
if (ti < iseq->line_info_size && iseq->line_info_table[ti].position == pos) {
|
2011-08-24 10:31:15 +04:00
|
|
|
line = iseq->line_info_table[ti].line_no;
|
2007-07-02 01:43:30 +04:00
|
|
|
rb_ary_push(body, INT2FIX(line));
|
2011-08-24 10:31:15 +04:00
|
|
|
ti++;
|
2007-07-02 01:43:30 +04:00
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_ary_push(body, ary);
|
2011-09-25 11:42:38 +04:00
|
|
|
pos += RARRAY_LENINT(ary); /* reject too huge data */
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2014-11-27 05:48:14 +03:00
|
|
|
RB_GC_GUARD(nbody);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
st_free_table(labels_table);
|
|
|
|
|
2014-11-03 02:14:21 +03:00
|
|
|
rb_hash_aset(misc, ID2SYM(rb_intern("arg_size")), INT2FIX(iseq->param.size));
|
2007-07-02 01:43:30 +04:00
|
|
|
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
|
|
|
|
2012-06-04 06:49:37 +04:00
|
|
|
/* TODO: compatibility issue */
|
2009-02-22 17:23:33 +03:00
|
|
|
/*
|
2007-07-02 01:43:30 +04:00
|
|
|
* [:magic, :major_version, :minor_version, :format_type, :misc,
|
2012-06-04 06:49:37 +04:00
|
|
|
* :name, :path, :absolute_path, :start_lineno, :type, :locals, :args,
|
2007-07-02 01:43:30 +04:00
|
|
|
* :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"));
|
2010-10-31 04:42:54 +03:00
|
|
|
rb_ary_push(val, INT2FIX(ISEQ_MAJOR_VERSION)); /* major */
|
|
|
|
rb_ary_push(val, INT2FIX(ISEQ_MINOR_VERSION)); /* minor */
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_ary_push(val, INT2FIX(1));
|
2007-07-02 01:43:30 +04:00
|
|
|
rb_ary_push(val, misc);
|
2012-06-04 06:49:37 +04:00
|
|
|
rb_ary_push(val, iseq->location.label);
|
|
|
|
rb_ary_push(val, iseq->location.path);
|
|
|
|
rb_ary_push(val, iseq->location.absolute_path);
|
|
|
|
rb_ary_push(val, iseq->location.first_lineno);
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_ary_push(val, type);
|
|
|
|
rb_ary_push(val, locals);
|
2014-11-03 02:14:21 +03:00
|
|
|
rb_ary_push(val, params);
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_ary_push(val, exception);
|
|
|
|
rb_ary_push(val, body);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2008-08-11 12:13:42 +04:00
|
|
|
VALUE
|
|
|
|
rb_iseq_clone(VALUE iseqval, VALUE newcbase)
|
|
|
|
{
|
|
|
|
VALUE newiseq = iseq_alloc(rb_cISeq);
|
|
|
|
rb_iseq_t *iseq0, *iseq1;
|
|
|
|
|
|
|
|
GetISeqPtr(iseqval, iseq0);
|
|
|
|
GetISeqPtr(newiseq, iseq1);
|
|
|
|
|
2013-06-19 10:26:01 +04:00
|
|
|
MEMCPY(iseq1, iseq0, rb_iseq_t, 1); /* TODO: write barrier? */
|
|
|
|
|
2008-08-11 12:13:42 +04:00
|
|
|
iseq1->self = newiseq;
|
|
|
|
if (!iseq1->orig) {
|
* include/ruby/ruby.h: rename OBJ_WRITE and OBJ_WRITTEN into
RB_OBJ_WRITE and RB_OBJ_WRITTEN.
* array.c, class.c, compile.c, hash.c, internal.h, iseq.c,
proc.c, process.c, re.c, string.c, variable.c, vm.c,
vm_eval.c, vm_insnhelper.c, vm_insnhelper.h,
vm_method.c: catch up this change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-20 12:07:47 +04:00
|
|
|
RB_OBJ_WRITE(iseq1->self, &iseq1->orig, iseqval);
|
2008-08-11 12:13:42 +04:00
|
|
|
}
|
2010-03-10 19:07:06 +03:00
|
|
|
if (iseq0->local_iseq == iseq0) {
|
|
|
|
iseq1->local_iseq = iseq1;
|
|
|
|
}
|
2008-08-11 12:13:42 +04:00
|
|
|
if (newcbase) {
|
2013-06-19 10:26:01 +04:00
|
|
|
ISEQ_SET_CREF(iseq1, NEW_CREF(newcbase));
|
* include/ruby/ruby.h: rename OBJ_WRITE and OBJ_WRITTEN into
RB_OBJ_WRITE and RB_OBJ_WRITTEN.
* array.c, class.c, compile.c, hash.c, internal.h, iseq.c,
proc.c, process.c, re.c, string.c, variable.c, vm.c,
vm_eval.c, vm_insnhelper.c, vm_insnhelper.h,
vm_method.c: catch up this change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-20 12:07:47 +04:00
|
|
|
RB_OBJ_WRITE(iseq1->cref_stack, &iseq1->cref_stack->nd_refinements, iseq0->cref_stack->nd_refinements);
|
2012-08-02 15:34:19 +04:00
|
|
|
iseq1->cref_stack->nd_visi = iseq0->cref_stack->nd_visi;
|
2008-08-11 15:39:09 +04:00
|
|
|
if (iseq0->cref_stack->nd_next) {
|
* include/ruby/ruby.h: rename OBJ_WRITE and OBJ_WRITTEN into
RB_OBJ_WRITE and RB_OBJ_WRITTEN.
* array.c, class.c, compile.c, hash.c, internal.h, iseq.c,
proc.c, process.c, re.c, string.c, variable.c, vm.c,
vm_eval.c, vm_insnhelper.c, vm_insnhelper.h,
vm_method.c: catch up this change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-20 12:07:47 +04:00
|
|
|
RB_OBJ_WRITE(iseq1->cref_stack, &iseq1->cref_stack->nd_next, iseq0->cref_stack->nd_next);
|
2008-08-11 15:39:09 +04:00
|
|
|
}
|
2014-08-15 14:39:27 +04:00
|
|
|
RB_OBJ_WRITE(iseq1->self, &iseq1->klass, newcbase);
|
2008-08-11 12:13:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return newiseq;
|
|
|
|
}
|
|
|
|
|
2008-11-28 07:19:37 +03:00
|
|
|
VALUE
|
2008-12-05 07:05:48 +03:00
|
|
|
rb_iseq_parameters(const rb_iseq_t *iseq, int is_proc)
|
2008-11-28 07:19:37 +03:00
|
|
|
{
|
2011-12-05 13:50:12 +04:00
|
|
|
int i, r;
|
2014-11-03 02:14:21 +03:00
|
|
|
VALUE a, args = rb_ary_new2(iseq->param.size);
|
2011-12-26 18:20:15 +04:00
|
|
|
ID req, opt, rest, block, key, keyrest;
|
2008-11-28 07:19:37 +03:00
|
|
|
#define PARAM_TYPE(type) rb_ary_push(a = rb_ary_new2(2), ID2SYM(type))
|
2010-12-17 01:05:58 +03:00
|
|
|
#define PARAM_ID(i) iseq->local_table[(i)]
|
2008-11-28 07:19:37 +03:00
|
|
|
#define PARAM(i, type) ( \
|
|
|
|
PARAM_TYPE(type), \
|
2012-06-09 18:36:56 +04:00
|
|
|
rb_id2str(PARAM_ID(i)) ? \
|
2008-11-28 07:19:37 +03:00
|
|
|
rb_ary_push(a, ID2SYM(PARAM_ID(i))) : \
|
|
|
|
a)
|
|
|
|
|
|
|
|
CONST_ID(req, "req");
|
2008-12-05 07:05:48 +03:00
|
|
|
CONST_ID(opt, "opt");
|
|
|
|
if (is_proc) {
|
2014-11-03 02:14:21 +03:00
|
|
|
for (i = 0; i < iseq->param.lead_num; i++) {
|
2008-12-05 07:05:48 +03:00
|
|
|
PARAM_TYPE(opt);
|
2012-06-09 18:36:56 +04:00
|
|
|
rb_ary_push(a, rb_id2str(PARAM_ID(i)) ? ID2SYM(PARAM_ID(i)) : Qnil);
|
2008-12-05 07:05:48 +03:00
|
|
|
rb_ary_push(args, a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2014-11-03 02:14:21 +03:00
|
|
|
for (i = 0; i < iseq->param.lead_num; i++) {
|
2008-12-05 07:05:48 +03:00
|
|
|
rb_ary_push(args, PARAM(i, req));
|
|
|
|
}
|
2008-11-28 07:19:37 +03:00
|
|
|
}
|
2014-11-03 07:43:07 +03:00
|
|
|
r = iseq->param.lead_num + iseq->param.opt_num;
|
2011-12-05 13:50:12 +04:00
|
|
|
for (; i < r; i++) {
|
2008-11-28 07:19:37 +03:00
|
|
|
PARAM_TYPE(opt);
|
2012-06-09 18:36:56 +04:00
|
|
|
if (rb_id2str(PARAM_ID(i))) {
|
2008-11-28 07:19:37 +03:00
|
|
|
rb_ary_push(a, ID2SYM(PARAM_ID(i)));
|
|
|
|
}
|
|
|
|
rb_ary_push(args, a);
|
|
|
|
}
|
2014-11-03 02:14:21 +03:00
|
|
|
if (iseq->param.flags.has_rest) {
|
2008-11-28 07:19:37 +03:00
|
|
|
CONST_ID(rest, "rest");
|
2014-11-03 02:14:21 +03:00
|
|
|
rb_ary_push(args, PARAM(iseq->param.rest_start, rest));
|
2008-11-28 07:19:37 +03:00
|
|
|
}
|
2014-11-03 02:14:21 +03:00
|
|
|
r = iseq->param.post_start + iseq->param.post_num;
|
2008-12-05 07:05:48 +03:00
|
|
|
if (is_proc) {
|
2014-11-03 02:14:21 +03:00
|
|
|
for (i = iseq->param.post_start; i < r; i++) {
|
2008-12-05 07:05:48 +03:00
|
|
|
PARAM_TYPE(opt);
|
2012-06-09 18:36:56 +04:00
|
|
|
rb_ary_push(a, rb_id2str(PARAM_ID(i)) ? ID2SYM(PARAM_ID(i)) : Qnil);
|
2008-12-05 07:05:48 +03:00
|
|
|
rb_ary_push(args, a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2014-11-03 02:14:21 +03:00
|
|
|
for (i = iseq->param.post_start; i < r; i++) {
|
2008-12-05 07:05:48 +03:00
|
|
|
rb_ary_push(args, PARAM(i, req));
|
|
|
|
}
|
2008-11-28 07:19:37 +03:00
|
|
|
}
|
2014-11-03 02:14:21 +03:00
|
|
|
if (iseq->param.flags.has_kw) {
|
2013-03-12 17:20:50 +04:00
|
|
|
i = 0;
|
2014-11-03 02:14:21 +03:00
|
|
|
if (iseq->param.keyword->required_num > 0) {
|
2013-03-12 17:20:50 +04:00
|
|
|
ID keyreq;
|
|
|
|
CONST_ID(keyreq, "keyreq");
|
2014-11-03 02:14:21 +03:00
|
|
|
for (; i < iseq->param.keyword->required_num; i++) {
|
2013-03-12 17:20:50 +04:00
|
|
|
PARAM_TYPE(keyreq);
|
2014-11-03 02:14:21 +03:00
|
|
|
if (rb_id2str(iseq->param.keyword->table[i])) {
|
|
|
|
rb_ary_push(a, ID2SYM(iseq->param.keyword->table[i]));
|
2013-03-12 17:20:50 +04:00
|
|
|
}
|
|
|
|
rb_ary_push(args, a);
|
|
|
|
}
|
|
|
|
}
|
2011-12-26 18:20:15 +04:00
|
|
|
CONST_ID(key, "key");
|
2014-11-03 02:14:21 +03:00
|
|
|
for (; i < iseq->param.keyword->num; i++) {
|
2011-12-26 18:20:15 +04:00
|
|
|
PARAM_TYPE(key);
|
2014-11-03 02:14:21 +03:00
|
|
|
if (rb_id2str(iseq->param.keyword->table[i])) {
|
|
|
|
rb_ary_push(a, ID2SYM(iseq->param.keyword->table[i]));
|
2011-12-26 18:20:15 +04:00
|
|
|
}
|
|
|
|
rb_ary_push(args, a);
|
|
|
|
}
|
* rewrite method/block parameter fitting logic to optimize
keyword arguments/parameters and a splat argument.
[Feature #10440] (Details are described in this ticket)
Most of complex part is moved to vm_args.c.
Now, ISeq#to_a does not catch up new instruction format.
* vm_core.h: change iseq data structures.
* introduce rb_call_info_kw_arg_t to represent keyword arguments.
* add rb_call_info_t::kw_arg.
* rename rb_iseq_t::arg_post_len to rb_iseq_t::arg_post_num.
* rename rb_iseq_t::arg_keywords to arg_keyword_num.
* rename rb_iseq_t::arg_keyword to rb_iseq_t::arg_keyword_bits.
to represent keyword bitmap parameter index.
This bitmap parameter shows that which keyword parameters are given
or not given (0 for given).
It is refered by `checkkeyword' instruction described bellow.
* rename rb_iseq_t::arg_keyword_check to rb_iseq_t::arg_keyword_rest
to represent keyword rest parameter index.
* add rb_iseq_t::arg_keyword_default_values to represent default
keyword values.
* rename VM_CALL_ARGS_SKIP_SETUP to VM_CALL_ARGS_SIMPLE
to represent
(ci->flag & (SPLAT|BLOCKARG)) &&
ci->blockiseq == NULL &&
ci->kw_arg == NULL.
* vm_insnhelper.c, vm_args.c: rewrite with refactoring.
* rewrite splat argument code.
* rewrite keyword arguments/parameters code.
* merge method and block parameter fitting code into one code base.
* vm.c, vm_eval.c: catch up these changes.
* compile.c (new_callinfo): callinfo requires kw_arg parameter.
* compile.c (compile_array_): check the last argument Hash object or
not. If Hash object and all keys are Symbol literals, they are
compiled to keyword arguments.
* insns.def (checkkeyword): add new instruction.
This instruction check the availability of corresponding keyword.
For example, a method "def foo k1: 'v1'; end" is cimpiled to the
following instructions.
0000 checkkeyword 2, 0 # check k1 is given.
0003 branchif 9 # if given, jump to address #9
0005 putstring "v1"
0007 setlocal_OP__WC__0 3 # k1 = 'v1'
0009 trace 8
0011 putnil
0012 trace 16
0014 leave
* insns.def (opt_send_simple): removed and add new instruction
"opt_send_without_block".
* parse.y (new_args_tail_gen): reorder variables.
Before this patch, a method "def foo(k1: 1, kr1:, k2: 2, **krest, &b)"
has parameter variables "k1, kr1, k2, &b, internal_id, krest",
but this patch reorders to "kr1, k1, k2, internal_id, krest, &b".
(locate a block variable at last)
* parse.y (vtable_pop): added.
This function remove latest `n' variables from vtable.
* iseq.c: catch up iseq data changes.
* proc.c: ditto.
* class.c (keyword_error): export as rb_keyword_error().
* common.mk: depend vm_args.c for vm.o.
* hash.c (rb_hash_has_key): export.
* internal.h: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-02 21:02:55 +03:00
|
|
|
}
|
2014-11-03 02:14:21 +03:00
|
|
|
if (iseq->param.flags.has_kwrest) {
|
* rewrite method/block parameter fitting logic to optimize
keyword arguments/parameters and a splat argument.
[Feature #10440] (Details are described in this ticket)
Most of complex part is moved to vm_args.c.
Now, ISeq#to_a does not catch up new instruction format.
* vm_core.h: change iseq data structures.
* introduce rb_call_info_kw_arg_t to represent keyword arguments.
* add rb_call_info_t::kw_arg.
* rename rb_iseq_t::arg_post_len to rb_iseq_t::arg_post_num.
* rename rb_iseq_t::arg_keywords to arg_keyword_num.
* rename rb_iseq_t::arg_keyword to rb_iseq_t::arg_keyword_bits.
to represent keyword bitmap parameter index.
This bitmap parameter shows that which keyword parameters are given
or not given (0 for given).
It is refered by `checkkeyword' instruction described bellow.
* rename rb_iseq_t::arg_keyword_check to rb_iseq_t::arg_keyword_rest
to represent keyword rest parameter index.
* add rb_iseq_t::arg_keyword_default_values to represent default
keyword values.
* rename VM_CALL_ARGS_SKIP_SETUP to VM_CALL_ARGS_SIMPLE
to represent
(ci->flag & (SPLAT|BLOCKARG)) &&
ci->blockiseq == NULL &&
ci->kw_arg == NULL.
* vm_insnhelper.c, vm_args.c: rewrite with refactoring.
* rewrite splat argument code.
* rewrite keyword arguments/parameters code.
* merge method and block parameter fitting code into one code base.
* vm.c, vm_eval.c: catch up these changes.
* compile.c (new_callinfo): callinfo requires kw_arg parameter.
* compile.c (compile_array_): check the last argument Hash object or
not. If Hash object and all keys are Symbol literals, they are
compiled to keyword arguments.
* insns.def (checkkeyword): add new instruction.
This instruction check the availability of corresponding keyword.
For example, a method "def foo k1: 'v1'; end" is cimpiled to the
following instructions.
0000 checkkeyword 2, 0 # check k1 is given.
0003 branchif 9 # if given, jump to address #9
0005 putstring "v1"
0007 setlocal_OP__WC__0 3 # k1 = 'v1'
0009 trace 8
0011 putnil
0012 trace 16
0014 leave
* insns.def (opt_send_simple): removed and add new instruction
"opt_send_without_block".
* parse.y (new_args_tail_gen): reorder variables.
Before this patch, a method "def foo(k1: 1, kr1:, k2: 2, **krest, &b)"
has parameter variables "k1, kr1, k2, &b, internal_id, krest",
but this patch reorders to "kr1, k1, k2, internal_id, krest, &b".
(locate a block variable at last)
* parse.y (vtable_pop): added.
This function remove latest `n' variables from vtable.
* iseq.c: catch up iseq data changes.
* proc.c: ditto.
* class.c (keyword_error): export as rb_keyword_error().
* common.mk: depend vm_args.c for vm.o.
* hash.c (rb_hash_has_key): export.
* internal.h: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-02 21:02:55 +03:00
|
|
|
CONST_ID(keyrest, "keyrest");
|
2014-11-03 02:14:21 +03:00
|
|
|
rb_ary_push(args, PARAM(iseq->param.keyword->rest_start, keyrest));
|
2011-12-26 18:20:15 +04:00
|
|
|
}
|
2014-11-03 02:14:21 +03:00
|
|
|
if (iseq->param.flags.has_block) {
|
2008-11-28 07:19:37 +03:00
|
|
|
CONST_ID(block, "block");
|
2014-11-03 02:14:21 +03:00
|
|
|
rb_ary_push(args, PARAM(iseq->param.block_start, block));
|
2008-11-28 07:19:37 +03:00
|
|
|
}
|
|
|
|
return args;
|
|
|
|
}
|
|
|
|
|
2012-09-24 12:36:53 +04:00
|
|
|
VALUE
|
|
|
|
rb_iseq_defined_string(enum defined_type type)
|
|
|
|
{
|
|
|
|
static const char expr_names[][18] = {
|
|
|
|
"nil",
|
|
|
|
"instance-variable",
|
|
|
|
"local-variable",
|
|
|
|
"global-variable",
|
|
|
|
"class variable",
|
|
|
|
"constant",
|
|
|
|
"method",
|
|
|
|
"yield",
|
|
|
|
"super",
|
|
|
|
"self",
|
|
|
|
"true",
|
|
|
|
"false",
|
|
|
|
"assignment",
|
|
|
|
"expression",
|
|
|
|
};
|
|
|
|
const char *estr;
|
|
|
|
VALUE *defs, str;
|
|
|
|
|
|
|
|
if ((unsigned)(type - 1) >= (unsigned)numberof(expr_names)) return 0;
|
|
|
|
estr = expr_names[type - 1];
|
|
|
|
if (!estr[0]) return 0;
|
|
|
|
defs = GET_VM()->defined_strings;
|
|
|
|
if (!defs) {
|
|
|
|
defs = ruby_xcalloc(numberof(expr_names), sizeof(VALUE));
|
|
|
|
GET_VM()->defined_strings = defs;
|
|
|
|
}
|
2012-09-25 03:17:59 +04:00
|
|
|
str = defs[type-1];
|
2012-09-24 12:36:53 +04:00
|
|
|
if (!str) {
|
2014-09-21 07:50:23 +04:00
|
|
|
str = rb_str_new_cstr(estr);
|
2012-09-24 12:36:53 +04:00
|
|
|
OBJ_FREEZE(str);
|
2012-09-25 03:17:59 +04:00
|
|
|
defs[type-1] = str;
|
2014-07-16 13:09:40 +04:00
|
|
|
rb_gc_register_mark_object(str);
|
2012-09-24 12:36:53 +04:00
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
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,
|
2011-08-24 10:31:15 +04:00
|
|
|
const struct iseq_line_info_entry *line_info_table,
|
2007-07-01 22:16:02 +04:00
|
|
|
const char **local_table,
|
|
|
|
const VALUE *arg_opt_table,
|
|
|
|
const struct iseq_catch_table_entry *catch_table,
|
|
|
|
const char *name,
|
2012-06-04 06:49:37 +04:00
|
|
|
const char *path,
|
|
|
|
const unsigned short first_lineno)
|
2007-07-01 22:16:02 +04:00
|
|
|
{
|
2009-07-07 05:12:17 +04:00
|
|
|
unsigned long i;
|
2007-07-01 22:16:02 +04:00
|
|
|
VALUE iseqval = iseq_alloc(rb_cISeq);
|
|
|
|
rb_iseq_t *iseq;
|
|
|
|
GetISeqPtr(iseqval, iseq);
|
|
|
|
|
|
|
|
/* copy iseq */
|
2013-06-19 10:26:01 +04:00
|
|
|
MEMCPY(iseq, iseq_template, rb_iseq_t, 1); /* TODO: write barrier, *iseq = *iseq_template; */
|
* include/ruby/ruby.h: rename OBJ_WRITE and OBJ_WRITTEN into
RB_OBJ_WRITE and RB_OBJ_WRITTEN.
* array.c, class.c, compile.c, hash.c, internal.h, iseq.c,
proc.c, process.c, re.c, string.c, variable.c, vm.c,
vm_eval.c, vm_insnhelper.c, vm_insnhelper.h,
vm_method.c: catch up this change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-20 12:07:47 +04:00
|
|
|
RB_OBJ_WRITE(iseq->self, &iseq->location.label, rb_str_new2(name));
|
|
|
|
RB_OBJ_WRITE(iseq->self, &iseq->location.path, rb_str_new2(path));
|
2014-08-25 06:24:10 +04:00
|
|
|
iseq->location.first_lineno = UINT2NUM(first_lineno);
|
* include/ruby/ruby.h: rename OBJ_WRITE and OBJ_WRITTEN into
RB_OBJ_WRITE and RB_OBJ_WRITTEN.
* array.c, class.c, compile.c, hash.c, internal.h, iseq.c,
proc.c, process.c, re.c, string.c, variable.c, vm.c,
vm_eval.c, vm_insnhelper.c, vm_insnhelper.h,
vm_method.c: catch up this change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-20 12:07:47 +04:00
|
|
|
RB_OBJ_WRITE(iseq->self, &iseq->mark_ary, 0);
|
2007-07-04 00:12:55 +04:00
|
|
|
iseq->self = iseqval;
|
2007-07-01 22:16:02 +04:00
|
|
|
|
compile: translate iseq in-place
running "ruby -rpp -e 'pp GC.stat'", a reduction in
malloc usage is shown:
before:
:malloc_increase=>118784,
:oldmalloc_increase=>1178736,
after:
:malloc_increase=>99832,
:oldmalloc_increase=>1031976,
For "ruby -e exit", valgrind reports over 300K reduction in
overall allocations (and unnecessary memory copies).
before:
total heap usage: 49,622 allocs, 20,492 frees, 8,697,493 bytes allocated
after:
total heap usage: 48,935 allocs, 19,805 frees, 8,373,773 bytes allocated
(numbers from x86-64)
v2 changes based on ko1 recommendations [ruby-core:64883]:
- squashed in-place direct thread translation to avoid alloc+copy
- renamed rb_iseq_untranslate_threaded_code to rb_iseq_original_iseq,
cache new iseq->iseq_original field.
* compile.c (rb_iseq_translate_threaded_code): modify in-place w/o copy
(rb_vm_addr2insn): new function for debug
(rb_iseq_original_iseq): ditto
(iseq_set_sequence): assign iseq_encoded directly
[Feature #10185]
* vm_core (rb_iseq_t): move original ->iseq to bottom
* iseq.c (iseq_free, iseq_free): adjust for new layout
(rb_iseq_disasm): use original iseq for dump
(iseq_data_to_ary): ditto
(rb_iseq_line_trace_each): ditto
(rb_iseq_build_for_ruby2cext): use iseq_encoded directly
* vm_dump.c (rb_vmdebug_debug_print_pre): use original iseq
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 10:14:07 +04:00
|
|
|
iseq->iseq_encoded = ALLOC_N(VALUE, iseq->iseq_size);
|
2007-07-02 16:49:35 +04:00
|
|
|
|
|
|
|
for (i=0; i<iseq->iseq_size; i+=2) {
|
compile: translate iseq in-place
running "ruby -rpp -e 'pp GC.stat'", a reduction in
malloc usage is shown:
before:
:malloc_increase=>118784,
:oldmalloc_increase=>1178736,
after:
:malloc_increase=>99832,
:oldmalloc_increase=>1031976,
For "ruby -e exit", valgrind reports over 300K reduction in
overall allocations (and unnecessary memory copies).
before:
total heap usage: 49,622 allocs, 20,492 frees, 8,697,493 bytes allocated
after:
total heap usage: 48,935 allocs, 19,805 frees, 8,373,773 bytes allocated
(numbers from x86-64)
v2 changes based on ko1 recommendations [ruby-core:64883]:
- squashed in-place direct thread translation to avoid alloc+copy
- renamed rb_iseq_untranslate_threaded_code to rb_iseq_original_iseq,
cache new iseq->iseq_original field.
* compile.c (rb_iseq_translate_threaded_code): modify in-place w/o copy
(rb_vm_addr2insn): new function for debug
(rb_iseq_original_iseq): ditto
(iseq_set_sequence): assign iseq_encoded directly
[Feature #10185]
* vm_core (rb_iseq_t): move original ->iseq to bottom
* iseq.c (iseq_free, iseq_free): adjust for new layout
(rb_iseq_disasm): use original iseq for dump
(iseq_data_to_ary): ditto
(rb_iseq_line_trace_each): ditto
(rb_iseq_build_for_ruby2cext): use iseq_encoded directly
* vm_dump.c (rb_vmdebug_debug_print_pre): use original iseq
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 10:14:07 +04:00
|
|
|
iseq->iseq_encoded[i] = BIN(opt_call_c_function);
|
|
|
|
iseq->iseq_encoded[i+1] = (VALUE)func;
|
2007-07-02 16:49:35 +04:00
|
|
|
}
|
|
|
|
|
2009-01-19 04:06:56 +03:00
|
|
|
rb_iseq_translate_threaded_code(iseq);
|
2007-07-02 16:49:35 +04:00
|
|
|
|
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)
|
|
|
|
|
2011-08-24 10:31:15 +04:00
|
|
|
ALLOC_AND_COPY(iseq->line_info_table, line_info_table,
|
|
|
|
struct iseq_line_info_entry, iseq->line_info_size);
|
2007-07-01 22:16:02 +04:00
|
|
|
|
2014-07-14 11:06:26 +04:00
|
|
|
/*
|
|
|
|
* FIXME: probably broken, but this function is probably unused
|
|
|
|
* and should be removed
|
|
|
|
*/
|
|
|
|
if (iseq->catch_table) {
|
|
|
|
MEMCPY(&iseq->catch_table->entries, catch_table,
|
|
|
|
struct iseq_catch_table_entry, iseq->catch_table->size);
|
|
|
|
}
|
2007-07-01 22:16:02 +04:00
|
|
|
|
2014-11-03 07:43:07 +03:00
|
|
|
ALLOC_AND_COPY(iseq->param.opt_table, arg_opt_table, VALUE, iseq->param.opt_num + 1);
|
2007-07-01 22:16:02 +04:00
|
|
|
|
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
|
|
|
|
2012-11-30 21:00:30 +04:00
|
|
|
/* Experimental tracing support: trace(line) -> trace(specified_line)
|
|
|
|
* MRI Specific.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
rb_iseq_line_trace_each(VALUE iseqval, int (*func)(int line, rb_event_flag_t *events_ptr, void *d), void *data)
|
|
|
|
{
|
|
|
|
int trace_num = 0;
|
2014-07-26 11:30:26 +04:00
|
|
|
unsigned int pos;
|
|
|
|
size_t insn;
|
2012-11-30 21:00:30 +04:00
|
|
|
rb_iseq_t *iseq;
|
|
|
|
int cont = 1;
|
compile: translate iseq in-place
running "ruby -rpp -e 'pp GC.stat'", a reduction in
malloc usage is shown:
before:
:malloc_increase=>118784,
:oldmalloc_increase=>1178736,
after:
:malloc_increase=>99832,
:oldmalloc_increase=>1031976,
For "ruby -e exit", valgrind reports over 300K reduction in
overall allocations (and unnecessary memory copies).
before:
total heap usage: 49,622 allocs, 20,492 frees, 8,697,493 bytes allocated
after:
total heap usage: 48,935 allocs, 19,805 frees, 8,373,773 bytes allocated
(numbers from x86-64)
v2 changes based on ko1 recommendations [ruby-core:64883]:
- squashed in-place direct thread translation to avoid alloc+copy
- renamed rb_iseq_untranslate_threaded_code to rb_iseq_original_iseq,
cache new iseq->iseq_original field.
* compile.c (rb_iseq_translate_threaded_code): modify in-place w/o copy
(rb_vm_addr2insn): new function for debug
(rb_iseq_original_iseq): ditto
(iseq_set_sequence): assign iseq_encoded directly
[Feature #10185]
* vm_core (rb_iseq_t): move original ->iseq to bottom
* iseq.c (iseq_free, iseq_free): adjust for new layout
(rb_iseq_disasm): use original iseq for dump
(iseq_data_to_ary): ditto
(rb_iseq_line_trace_each): ditto
(rb_iseq_build_for_ruby2cext): use iseq_encoded directly
* vm_dump.c (rb_vmdebug_debug_print_pre): use original iseq
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 10:14:07 +04:00
|
|
|
VALUE *iseq_original;
|
2012-11-30 21:00:30 +04:00
|
|
|
GetISeqPtr(iseqval, iseq);
|
|
|
|
|
compile: translate iseq in-place
running "ruby -rpp -e 'pp GC.stat'", a reduction in
malloc usage is shown:
before:
:malloc_increase=>118784,
:oldmalloc_increase=>1178736,
after:
:malloc_increase=>99832,
:oldmalloc_increase=>1031976,
For "ruby -e exit", valgrind reports over 300K reduction in
overall allocations (and unnecessary memory copies).
before:
total heap usage: 49,622 allocs, 20,492 frees, 8,697,493 bytes allocated
after:
total heap usage: 48,935 allocs, 19,805 frees, 8,373,773 bytes allocated
(numbers from x86-64)
v2 changes based on ko1 recommendations [ruby-core:64883]:
- squashed in-place direct thread translation to avoid alloc+copy
- renamed rb_iseq_untranslate_threaded_code to rb_iseq_original_iseq,
cache new iseq->iseq_original field.
* compile.c (rb_iseq_translate_threaded_code): modify in-place w/o copy
(rb_vm_addr2insn): new function for debug
(rb_iseq_original_iseq): ditto
(iseq_set_sequence): assign iseq_encoded directly
[Feature #10185]
* vm_core (rb_iseq_t): move original ->iseq to bottom
* iseq.c (iseq_free, iseq_free): adjust for new layout
(rb_iseq_disasm): use original iseq for dump
(iseq_data_to_ary): ditto
(rb_iseq_line_trace_each): ditto
(rb_iseq_build_for_ruby2cext): use iseq_encoded directly
* vm_dump.c (rb_vmdebug_debug_print_pre): use original iseq
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 10:14:07 +04:00
|
|
|
iseq_original = rb_iseq_original_iseq(iseq);
|
2012-11-30 21:00:30 +04:00
|
|
|
for (pos = 0; cont && pos < iseq->iseq_size; pos += insn_len(insn)) {
|
compile: translate iseq in-place
running "ruby -rpp -e 'pp GC.stat'", a reduction in
malloc usage is shown:
before:
:malloc_increase=>118784,
:oldmalloc_increase=>1178736,
after:
:malloc_increase=>99832,
:oldmalloc_increase=>1031976,
For "ruby -e exit", valgrind reports over 300K reduction in
overall allocations (and unnecessary memory copies).
before:
total heap usage: 49,622 allocs, 20,492 frees, 8,697,493 bytes allocated
after:
total heap usage: 48,935 allocs, 19,805 frees, 8,373,773 bytes allocated
(numbers from x86-64)
v2 changes based on ko1 recommendations [ruby-core:64883]:
- squashed in-place direct thread translation to avoid alloc+copy
- renamed rb_iseq_untranslate_threaded_code to rb_iseq_original_iseq,
cache new iseq->iseq_original field.
* compile.c (rb_iseq_translate_threaded_code): modify in-place w/o copy
(rb_vm_addr2insn): new function for debug
(rb_iseq_original_iseq): ditto
(iseq_set_sequence): assign iseq_encoded directly
[Feature #10185]
* vm_core (rb_iseq_t): move original ->iseq to bottom
* iseq.c (iseq_free, iseq_free): adjust for new layout
(rb_iseq_disasm): use original iseq for dump
(iseq_data_to_ary): ditto
(rb_iseq_line_trace_each): ditto
(rb_iseq_build_for_ruby2cext): use iseq_encoded directly
* vm_dump.c (rb_vmdebug_debug_print_pre): use original iseq
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 10:14:07 +04:00
|
|
|
insn = iseq_original[pos];
|
2012-11-30 21:00:30 +04:00
|
|
|
|
|
|
|
if (insn == BIN(trace)) {
|
2014-10-02 03:03:35 +04:00
|
|
|
rb_event_flag_t current_events;
|
|
|
|
|
|
|
|
current_events = (rb_event_flag_t)iseq_original[pos+1];
|
2012-12-02 00:07:58 +04:00
|
|
|
|
|
|
|
if (current_events & RUBY_EVENT_LINE) {
|
|
|
|
rb_event_flag_t events = current_events & RUBY_EVENT_SPECIFIED_LINE;
|
|
|
|
trace_num++;
|
|
|
|
|
|
|
|
if (func) {
|
|
|
|
int line = find_line_no(iseq, pos);
|
|
|
|
/* printf("line: %d\n", line); */
|
|
|
|
cont = (*func)(line, &events, data);
|
|
|
|
if (current_events != events) {
|
compile: translate iseq in-place
running "ruby -rpp -e 'pp GC.stat'", a reduction in
malloc usage is shown:
before:
:malloc_increase=>118784,
:oldmalloc_increase=>1178736,
after:
:malloc_increase=>99832,
:oldmalloc_increase=>1031976,
For "ruby -e exit", valgrind reports over 300K reduction in
overall allocations (and unnecessary memory copies).
before:
total heap usage: 49,622 allocs, 20,492 frees, 8,697,493 bytes allocated
after:
total heap usage: 48,935 allocs, 19,805 frees, 8,373,773 bytes allocated
(numbers from x86-64)
v2 changes based on ko1 recommendations [ruby-core:64883]:
- squashed in-place direct thread translation to avoid alloc+copy
- renamed rb_iseq_untranslate_threaded_code to rb_iseq_original_iseq,
cache new iseq->iseq_original field.
* compile.c (rb_iseq_translate_threaded_code): modify in-place w/o copy
(rb_vm_addr2insn): new function for debug
(rb_iseq_original_iseq): ditto
(iseq_set_sequence): assign iseq_encoded directly
[Feature #10185]
* vm_core (rb_iseq_t): move original ->iseq to bottom
* iseq.c (iseq_free, iseq_free): adjust for new layout
(rb_iseq_disasm): use original iseq for dump
(iseq_data_to_ary): ditto
(rb_iseq_line_trace_each): ditto
(rb_iseq_build_for_ruby2cext): use iseq_encoded directly
* vm_dump.c (rb_vmdebug_debug_print_pre): use original iseq
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 10:14:07 +04:00
|
|
|
iseq_original[pos+1] = iseq->iseq_encoded[pos+1] =
|
2012-12-02 00:07:58 +04:00
|
|
|
(VALUE)(current_events | (events & RUBY_EVENT_SPECIFIED_LINE));
|
|
|
|
}
|
2012-11-30 21:00:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return trace_num;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
collect_trace(int line, rb_event_flag_t *events_ptr, void *ptr)
|
|
|
|
{
|
|
|
|
VALUE result = (VALUE)ptr;
|
|
|
|
rb_ary_push(result, INT2NUM(line));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-12-29 09:09:18 +04:00
|
|
|
/*
|
|
|
|
* <b>Experimental MRI specific feature, only available as C level api.</b>
|
|
|
|
*
|
|
|
|
* Returns all +specified_line+ events.
|
|
|
|
*/
|
2012-11-30 21:00:30 +04:00
|
|
|
VALUE
|
|
|
|
rb_iseq_line_trace_all(VALUE iseqval)
|
|
|
|
{
|
|
|
|
VALUE result = rb_ary_new();
|
|
|
|
rb_iseq_line_trace_each(iseqval, collect_trace, (void *)result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct set_specifc_data {
|
|
|
|
int pos;
|
|
|
|
int set;
|
|
|
|
int prev; /* 1: set, 2: unset, 0: not found */
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
line_trace_specify(int line, rb_event_flag_t *events_ptr, void *ptr)
|
|
|
|
{
|
|
|
|
struct set_specifc_data *data = (struct set_specifc_data *)ptr;
|
|
|
|
|
|
|
|
if (data->pos == 0) {
|
|
|
|
data->prev = *events_ptr & RUBY_EVENT_SPECIFIED_LINE ? 1 : 2;
|
|
|
|
if (data->set) {
|
|
|
|
*events_ptr = *events_ptr | RUBY_EVENT_SPECIFIED_LINE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*events_ptr = *events_ptr & ~RUBY_EVENT_SPECIFIED_LINE;
|
|
|
|
}
|
|
|
|
return 0; /* found */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
data->pos--;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-29 09:09:18 +04:00
|
|
|
/*
|
|
|
|
* <b>Experimental MRI specific feature, only available as C level api.</b>
|
|
|
|
*
|
|
|
|
* Set a +specified_line+ event at the given line position, if the +set+
|
|
|
|
* parameter is +true+.
|
|
|
|
*
|
|
|
|
* This method is useful for building a debugger breakpoint at a specific line.
|
|
|
|
*
|
|
|
|
* A TypeError is raised if +set+ is not boolean.
|
|
|
|
*
|
|
|
|
* If +pos+ is a negative integer a TypeError exception is raised.
|
|
|
|
*/
|
2012-11-30 21:00:30 +04:00
|
|
|
VALUE
|
|
|
|
rb_iseq_line_trace_specify(VALUE iseqval, VALUE pos, VALUE set)
|
|
|
|
{
|
|
|
|
struct set_specifc_data data;
|
|
|
|
|
|
|
|
data.prev = 0;
|
|
|
|
data.pos = NUM2INT(pos);
|
|
|
|
if (data.pos < 0) rb_raise(rb_eTypeError, "`pos' is negative");
|
|
|
|
|
|
|
|
switch (set) {
|
|
|
|
case Qtrue: data.set = 1; break;
|
|
|
|
case Qfalse: data.set = 0; break;
|
|
|
|
default:
|
|
|
|
rb_raise(rb_eTypeError, "`set' should be true/false");
|
|
|
|
}
|
|
|
|
|
|
|
|
rb_iseq_line_trace_each(iseqval, line_trace_specify, (void *)&data);
|
|
|
|
|
|
|
|
if (data.prev == 0) {
|
|
|
|
rb_raise(rb_eTypeError, "`pos' is out of range.");
|
|
|
|
}
|
|
|
|
return data.prev == 1 ? Qtrue : Qfalse;
|
|
|
|
}
|
|
|
|
|
2012-07-25 01:29:24 +04:00
|
|
|
/*
|
|
|
|
* Document-class: RubyVM::InstructionSequence
|
|
|
|
*
|
|
|
|
* The InstructionSequence class represents a compiled sequence of
|
2012-12-29 11:44:54 +04:00
|
|
|
* instructions for the Ruby Virtual Machine.
|
|
|
|
*
|
|
|
|
* With it, you can get a handle to the instructions that make up a method or
|
|
|
|
* a proc, compile strings of Ruby code down to VM instructions, and
|
|
|
|
* disassemble instruction sequences to strings for easy inspection. It is
|
|
|
|
* mostly useful if you want to learn how the Ruby VM works, but it also lets
|
|
|
|
* you control various settings for the Ruby iseq compiler.
|
|
|
|
*
|
|
|
|
* You can find the source for the VM instructions in +insns.def+ in the Ruby
|
|
|
|
* source.
|
|
|
|
*
|
|
|
|
* The instruction sequence results will almost certainly change as Ruby
|
|
|
|
* changes, so example output in this documentation may be different from what
|
|
|
|
* you see.
|
2012-07-25 01:29:24 +04:00
|
|
|
*/
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
void
|
|
|
|
Init_ISeq(void)
|
|
|
|
{
|
2011-12-30 09:55:37 +04:00
|
|
|
/* declare ::RubyVM::InstructionSequence */
|
2008-06-29 21:26:16 +04:00
|
|
|
rb_cISeq = rb_define_class_under(rb_cRubyVM, "InstructionSequence", rb_cObject);
|
2007-01-17 11:48:52 +03:00
|
|
|
rb_define_alloc_func(rb_cISeq, iseq_alloc);
|
|
|
|
rb_define_method(rb_cISeq, "inspect", iseq_inspect, 0);
|
2009-01-19 04:06:56 +03:00
|
|
|
rb_define_method(rb_cISeq, "disasm", rb_iseq_disasm, 0);
|
|
|
|
rb_define_method(rb_cISeq, "disassemble", rb_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);
|
|
|
|
|
2012-11-30 22:02:43 +04:00
|
|
|
/* location APIs */
|
2013-10-07 09:12:08 +04:00
|
|
|
rb_define_method(rb_cISeq, "path", rb_iseq_path, 0);
|
|
|
|
rb_define_method(rb_cISeq, "absolute_path", rb_iseq_absolute_path, 0);
|
|
|
|
rb_define_method(rb_cISeq, "label", rb_iseq_label, 0);
|
|
|
|
rb_define_method(rb_cISeq, "base_label", rb_iseq_base_label, 0);
|
|
|
|
rb_define_method(rb_cISeq, "first_lineno", rb_iseq_first_lineno, 0);
|
2012-11-30 22:02:43 +04:00
|
|
|
|
2012-12-21 15:44:09 +04:00
|
|
|
#if 0
|
|
|
|
/* Now, it is experimental. No discussions, no tests. */
|
|
|
|
/* They can be used from C level. Please give us feedback. */
|
2012-11-30 21:00:30 +04:00
|
|
|
rb_define_method(rb_cISeq, "line_trace_all", rb_iseq_line_trace_all, 0);
|
|
|
|
rb_define_method(rb_cISeq, "line_trace_specify", rb_iseq_line_trace_specify, 2);
|
2012-12-21 15:44:09 +04:00
|
|
|
#else
|
|
|
|
(void)rb_iseq_line_trace_all;
|
|
|
|
(void)rb_iseq_line_trace_specify;
|
|
|
|
#endif
|
2012-11-30 21:00:30 +04:00
|
|
|
|
2010-10-31 04:42:54 +03:00
|
|
|
#if 0 /* TBD */
|
2012-12-01 13:17:02 +04:00
|
|
|
rb_define_private_method(rb_cISeq, "marshal_dump", iseq_marshal_dump, 0);
|
|
|
|
rb_define_private_method(rb_cISeq, "marshal_load", iseq_marshal_load, 1);
|
2010-10-31 04:42:54 +03:00
|
|
|
#endif
|
|
|
|
|
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); */
|
2008-06-01 23:55:25 +04:00
|
|
|
(void)iseq_s_load;
|
2007-12-24 12:09:21 +03:00
|
|
|
|
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);
|
2012-11-30 22:02:43 +04:00
|
|
|
rb_define_singleton_method(rb_cISeq, "of", iseq_s_of, 1);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|