2020-04-10 01:11:40 -04:00
|
|
|
#ifndef RUBY_ISEQ_H
|
|
|
|
#define RUBY_ISEQ_H 1
|
* 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 03:49:45 -04:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
iseq.h -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
created at: 04/01/01 23:36:57 JST
|
|
|
|
|
|
|
|
Copyright (C) 2004-2008 Koichi Sasada
|
|
|
|
|
|
|
|
**********************************************************************/
|
2019-12-04 03:16:30 -05:00
|
|
|
#include "internal/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 03:49:45 -04:00
|
|
|
|
2018-10-13 12:21:06 -04:00
|
|
|
RUBY_EXTERN const int ruby_api_version[];
|
|
|
|
#define ISEQ_MAJOR_VERSION ((unsigned int)ruby_api_version[0])
|
|
|
|
#define ISEQ_MINOR_VERSION ((unsigned int)ruby_api_version[1])
|
2015-12-08 08:58:50 -05:00
|
|
|
|
2022-06-17 18:28:14 -04:00
|
|
|
#define ISEQ_MBITS_SIZE sizeof(iseq_bits_t)
|
|
|
|
#define ISEQ_MBITS_BITLENGTH (ISEQ_MBITS_SIZE * CHAR_BIT)
|
|
|
|
#define ISEQ_MBITS_SET(buf, i) (buf[(i) / ISEQ_MBITS_BITLENGTH] |= ((iseq_bits_t)1 << ((i) % ISEQ_MBITS_BITLENGTH)))
|
|
|
|
#define ISEQ_MBITS_SET_P(buf, i) ((buf[(i) / ISEQ_MBITS_BITLENGTH] >> ((i) % ISEQ_MBITS_BITLENGTH)) & 0x1)
|
2022-07-07 23:11:56 -04:00
|
|
|
#define ISEQ_MBITS_BUFLEN(size) roomof(size, ISEQ_MBITS_BITLENGTH)
|
2022-06-17 18:28:14 -04:00
|
|
|
|
2021-06-08 04:57:44 -04:00
|
|
|
#ifndef USE_ISEQ_NODE_ID
|
|
|
|
#define USE_ISEQ_NODE_ID 1
|
|
|
|
#endif
|
2021-04-30 05:54:46 -04:00
|
|
|
|
2015-09-18 21:53:34 -04:00
|
|
|
#ifndef rb_iseq_t
|
|
|
|
typedef struct rb_iseq_struct rb_iseq_t;
|
|
|
|
#define rb_iseq_t rb_iseq_t
|
|
|
|
#endif
|
2022-10-18 12:07:11 -04:00
|
|
|
typedef void (*rb_iseq_callback)(const rb_iseq_t *, void *);
|
2015-09-18 21:53:34 -04:00
|
|
|
|
2019-04-11 06:36:36 -04:00
|
|
|
extern const ID rb_iseq_shared_exc_local_tbl[];
|
|
|
|
|
2022-03-23 15:19:48 -04:00
|
|
|
#define ISEQ_COVERAGE(iseq) ISEQ_BODY(iseq)->variable.coverage
|
|
|
|
#define ISEQ_COVERAGE_SET(iseq, cov) RB_OBJ_WRITE(iseq, &ISEQ_BODY(iseq)->variable.coverage, cov)
|
2017-09-03 10:26:06 -04:00
|
|
|
#define ISEQ_LINE_COVERAGE(iseq) RARRAY_AREF(ISEQ_COVERAGE(iseq), COVERAGE_INDEX_LINES)
|
|
|
|
#define ISEQ_BRANCH_COVERAGE(iseq) RARRAY_AREF(ISEQ_COVERAGE(iseq), COVERAGE_INDEX_BRANCHES)
|
2015-12-02 08:58:07 -05:00
|
|
|
|
2022-03-23 15:19:48 -04:00
|
|
|
#define ISEQ_PC2BRANCHINDEX(iseq) ISEQ_BODY(iseq)->variable.pc2branchindex
|
|
|
|
#define ISEQ_PC2BRANCHINDEX_SET(iseq, h) RB_OBJ_WRITE(iseq, &ISEQ_BODY(iseq)->variable.pc2branchindex, h)
|
2018-10-20 06:45:48 -04:00
|
|
|
|
2022-03-23 15:19:48 -04:00
|
|
|
#define ISEQ_FLIP_CNT(iseq) ISEQ_BODY(iseq)->variable.flip_count
|
2015-12-08 08:58:50 -05:00
|
|
|
|
2018-03-19 14:21:54 -04:00
|
|
|
static inline rb_snum_t
|
2015-12-02 08:58:07 -05:00
|
|
|
ISEQ_FLIP_CNT_INCREMENT(const rb_iseq_t *iseq)
|
|
|
|
{
|
2022-03-23 15:19:48 -04:00
|
|
|
rb_snum_t cnt = ISEQ_BODY(iseq)->variable.flip_count;
|
|
|
|
ISEQ_BODY(iseq)->variable.flip_count += 1;
|
2015-12-02 08:58:07 -05:00
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline VALUE *
|
|
|
|
ISEQ_ORIGINAL_ISEQ(const rb_iseq_t *iseq)
|
|
|
|
{
|
2022-03-23 15:19:48 -04:00
|
|
|
return ISEQ_BODY(iseq)->variable.original_iseq;
|
2015-12-02 08:58:07 -05:00
|
|
|
}
|
|
|
|
|
2017-11-14 07:58:36 -05:00
|
|
|
static inline void
|
|
|
|
ISEQ_ORIGINAL_ISEQ_CLEAR(const rb_iseq_t *iseq)
|
|
|
|
{
|
2022-03-23 15:19:48 -04:00
|
|
|
void *ptr = ISEQ_BODY(iseq)->variable.original_iseq;
|
|
|
|
ISEQ_BODY(iseq)->variable.original_iseq = NULL;
|
2018-05-09 01:42:06 -04:00
|
|
|
if (ptr) {
|
|
|
|
ruby_xfree(ptr);
|
|
|
|
}
|
2017-11-14 07:58:36 -05:00
|
|
|
}
|
|
|
|
|
2015-12-02 08:58:07 -05:00
|
|
|
static inline VALUE *
|
|
|
|
ISEQ_ORIGINAL_ISEQ_ALLOC(const rb_iseq_t *iseq, long size)
|
|
|
|
{
|
2022-03-23 15:19:48 -04:00
|
|
|
return ISEQ_BODY(iseq)->variable.original_iseq =
|
2019-10-07 03:56:08 -04:00
|
|
|
ALLOC_N(VALUE, size);
|
2015-12-02 08:58:07 -05:00
|
|
|
}
|
|
|
|
|
2017-11-18 04:39:41 -05:00
|
|
|
#define ISEQ_TRACE_EVENTS (RUBY_EVENT_LINE | \
|
2022-07-21 12:23:58 -04:00
|
|
|
RUBY_EVENT_CLASS | \
|
|
|
|
RUBY_EVENT_END | \
|
|
|
|
RUBY_EVENT_CALL | \
|
|
|
|
RUBY_EVENT_RETURN| \
|
2021-08-21 13:15:01 -04:00
|
|
|
RUBY_EVENT_C_CALL| \
|
|
|
|
RUBY_EVENT_C_RETURN| \
|
2022-07-21 12:23:58 -04:00
|
|
|
RUBY_EVENT_B_CALL| \
|
|
|
|
RUBY_EVENT_B_RETURN| \
|
2018-10-20 06:45:55 -04:00
|
|
|
RUBY_EVENT_COVERAGE_LINE| \
|
|
|
|
RUBY_EVENT_COVERAGE_BRANCH)
|
2017-11-18 04:39:41 -05:00
|
|
|
|
|
|
|
#define ISEQ_NOT_LOADED_YET IMEMO_FL_USER1
|
|
|
|
#define ISEQ_USE_COMPILE_DATA IMEMO_FL_USER2
|
2018-03-19 14:21:54 -04:00
|
|
|
#define ISEQ_TRANSLATED IMEMO_FL_USER3
|
2017-11-18 04:39:41 -05:00
|
|
|
|
2020-04-08 00:28:13 -04:00
|
|
|
#define ISEQ_EXECUTABLE_P(iseq) (FL_TEST_RAW(((VALUE)iseq), ISEQ_NOT_LOADED_YET | ISEQ_USE_COMPILE_DATA) == 0)
|
2018-12-06 05:52:27 -05:00
|
|
|
|
2017-11-18 04:39:41 -05:00
|
|
|
struct iseq_compile_data {
|
|
|
|
/* GC is needed */
|
|
|
|
const VALUE err_info;
|
|
|
|
const VALUE catch_table_ary; /* Array */
|
|
|
|
|
|
|
|
/* GC is not needed */
|
|
|
|
struct iseq_label_data *start_label;
|
|
|
|
struct iseq_label_data *end_label;
|
|
|
|
struct iseq_label_data *redo_label;
|
|
|
|
const rb_iseq_t *current_block;
|
|
|
|
struct iseq_compile_data_ensure_node_stack *ensure_node_stack;
|
2019-09-12 18:21:18 -04:00
|
|
|
struct {
|
|
|
|
struct iseq_compile_data_storage *storage_head;
|
|
|
|
struct iseq_compile_data_storage *storage_current;
|
|
|
|
} node;
|
|
|
|
struct {
|
|
|
|
struct iseq_compile_data_storage *storage_head;
|
|
|
|
struct iseq_compile_data_storage *storage_current;
|
|
|
|
} insn;
|
2021-04-21 21:44:52 -04:00
|
|
|
bool in_rescue;
|
2018-07-28 21:32:37 -04:00
|
|
|
int loopval_popped; /* used by NODE_BREAK */
|
2017-11-18 04:39:41 -05:00
|
|
|
int last_line;
|
|
|
|
int label_no;
|
|
|
|
int node_level;
|
2020-10-23 00:27:21 -04:00
|
|
|
int isolated_depth;
|
2017-11-18 04:39:41 -05:00
|
|
|
unsigned int ci_index;
|
New constant caching insn: opt_getconstant_path
Previously YARV bytecode implemented constant caching by having a pair
of instructions, opt_getinlinecache and opt_setinlinecache, wrapping a
series of getconstant calls (with putobject providing supporting
arguments).
This commit replaces that pattern with a new instruction,
opt_getconstant_path, handling both getting/setting the inline cache and
fetching the constant on a cache miss.
This is implemented by storing the full constant path as a
null-terminated array of IDs inside of the IC structure. idNULL is used
to signal an absolute constant reference.
$ ./miniruby --dump=insns -e '::Foo::Bar::Baz'
== disasm: #<ISeq:<main>@-e:1 (1,0)-(1,13)> (catch: FALSE)
0000 opt_getconstant_path <ic:0 ::Foo::Bar::Baz> ( 1)[Li]
0002 leave
The motivation for this is that we had increasingly found the need to
disassemble the instructions between the opt_getinlinecache and
opt_setinlinecache in order to determine the constant we are fetching,
or otherwise store metadata.
This disassembly was done:
* In opt_setinlinecache, to register the IC against the constant names
it is using for granular invalidation.
* In rb_iseq_free, to unregister the IC from the invalidation table.
* In YJIT to find the position of a opt_getinlinecache instruction to
invalidate it when the cache is populated
* In YJIT to register the constant names being used for invalidation.
With this change we no longe need disassemly for these (in fact
rb_iseq_each is now unused), as the list of constant names being
referenced is held in the IC. This should also make it possible to make
more optimizations in the future.
This may also reduce the size of iseqs, as previously each segment
required 32 bytes (on 64-bit platforms) for each constant segment. This
implementation only stores one ID per-segment.
There should be no significant performance change between this and the
previous implementation. Previously opt_getinlinecache was a "leaf"
instruction, but it included a jump (almost always to a separate cache
line). Now opt_getconstant_path is a non-leaf (it may
raise/autoload/call const_missing) but it does not jump. These seem to
even out.
2022-08-10 13:35:48 -04:00
|
|
|
unsigned int ic_index;
|
2017-11-18 04:39:41 -05:00
|
|
|
const rb_compile_option_t *option;
|
|
|
|
struct rb_id_table *ivar_cache_table;
|
2019-11-07 02:58:00 -05:00
|
|
|
const struct rb_builtin_function *builtin_function_table;
|
`Primitive.mandatory_only?` for fast path
Compare with the C methods, A built-in methods written in Ruby is
slower if only mandatory parameters are given because it needs to
check the argumens and fill default values for optional and keyword
parameters (C methods can check the number of parameters with `argc`,
so there are no overhead). Passing mandatory arguments are common
(optional arguments are exceptional, in many cases) so it is important
to provide the fast path for such common cases.
`Primitive.mandatory_only?` is a special builtin function used with
`if` expression like that:
```ruby
def self.at(time, subsec = false, unit = :microsecond, in: nil)
if Primitive.mandatory_only?
Primitive.time_s_at1(time)
else
Primitive.time_s_at(time, subsec, unit, Primitive.arg!(:in))
end
end
```
and it makes two ISeq,
```
def self.at(time, subsec = false, unit = :microsecond, in: nil)
Primitive.time_s_at(time, subsec, unit, Primitive.arg!(:in))
end
def self.at(time)
Primitive.time_s_at1(time)
end
```
and (2) is pointed by (1). Note that `Primitive.mandatory_only?`
should be used only in a condition of an `if` statement and the
`if` statement should be equal to the methdo body (you can not
put any expression before and after the `if` statement).
A method entry with `mandatory_only?` (`Time.at` on the above case)
is marked as `iseq_overload`. When the method will be dispatch only
with mandatory arguments (`Time.at(0)` for example), make another
method entry with ISeq (2) as mandatory only method entry and it
will be cached in an inline method cache.
The idea is similar discussed in https://bugs.ruby-lang.org/issues/16254
but it only checks mandatory parameters or more, because many cases
only mandatory parameters are given. If we find other cases (optional
or keyword parameters are used frequently and it hurts performance),
we can extend the feature.
2021-11-12 12:12:20 -05:00
|
|
|
const NODE *root_node;
|
2019-09-03 08:08:07 -04:00
|
|
|
#if OPT_SUPPORT_JOKE
|
2017-11-18 04:39:41 -05:00
|
|
|
st_table *labels_table;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct iseq_compile_data *
|
|
|
|
ISEQ_COMPILE_DATA(const rb_iseq_t *iseq)
|
|
|
|
{
|
|
|
|
if (iseq->flags & ISEQ_USE_COMPILE_DATA) {
|
2022-07-21 12:23:58 -04:00
|
|
|
return iseq->aux.compile_data;
|
2017-11-18 04:39:41 -05:00
|
|
|
}
|
|
|
|
else {
|
2022-07-21 12:23:58 -04:00
|
|
|
return NULL;
|
2017-11-18 04:39:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
ISEQ_COMPILE_DATA_ALLOC(rb_iseq_t *iseq)
|
|
|
|
{
|
|
|
|
iseq->aux.compile_data = ZALLOC(struct iseq_compile_data);
|
2018-12-06 05:52:27 -05:00
|
|
|
iseq->flags |= ISEQ_USE_COMPILE_DATA;
|
2017-11-18 04:39:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
ISEQ_COMPILE_DATA_CLEAR(rb_iseq_t *iseq)
|
|
|
|
{
|
|
|
|
iseq->flags &= ~ISEQ_USE_COMPILE_DATA;
|
|
|
|
iseq->aux.compile_data = NULL;
|
|
|
|
}
|
2015-12-08 08:58:50 -05:00
|
|
|
|
|
|
|
static inline rb_iseq_t *
|
|
|
|
iseq_imemo_alloc(void)
|
|
|
|
{
|
|
|
|
return (rb_iseq_t *)rb_imemo_new(imemo_iseq, 0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
2018-09-13 09:59:25 -04:00
|
|
|
VALUE rb_iseq_ibf_dump(const rb_iseq_t *iseq, VALUE opt);
|
|
|
|
void rb_ibf_load_iseq_complete(rb_iseq_t *iseq);
|
|
|
|
const rb_iseq_t *rb_iseq_ibf_load(VALUE str);
|
2019-11-08 02:16:25 -05:00
|
|
|
const rb_iseq_t *rb_iseq_ibf_load_bytes(const char *cstr, size_t);
|
2018-09-13 09:59:25 -04:00
|
|
|
VALUE rb_iseq_ibf_load_extra_data(VALUE str);
|
|
|
|
void rb_iseq_init_trace(rb_iseq_t *iseq);
|
2021-07-13 19:01:09 -04:00
|
|
|
int rb_iseq_add_local_tracepoint_recursively(const rb_iseq_t *iseq, rb_event_flag_t turnon_events, VALUE tpval, unsigned int target_line, bool target_bmethod);
|
2018-11-26 13:16:39 -05:00
|
|
|
int rb_iseq_remove_local_tracepoint_recursively(const rb_iseq_t *iseq, VALUE tpval);
|
2018-12-06 08:42:32 -05:00
|
|
|
const rb_iseq_t *rb_iseq_load_iseq(VALUE fname);
|
2018-08-23 00:12:14 -04:00
|
|
|
|
2018-06-13 00:51:43 -04:00
|
|
|
#if VM_INSN_INFO_TABLE_IMPL == 2
|
2018-04-05 03:04:39 -04:00
|
|
|
unsigned int *rb_iseq_insns_info_decode_positions(const struct rb_iseq_constant_body *body);
|
2018-06-13 00:51:43 -04:00
|
|
|
#endif
|
2015-12-02 03:20:35 -05:00
|
|
|
|
2020-10-19 09:47:39 -04:00
|
|
|
int rb_vm_insn_addr2opcode(const void *addr);
|
|
|
|
|
2013-04-05 06:29:38 -04:00
|
|
|
RUBY_SYMBOL_EXPORT_BEGIN
|
2010-07-21 17:38:25 -04:00
|
|
|
|
2008-12-04 22:35:48 -05:00
|
|
|
/* compile.c */
|
2017-10-27 08:00:38 -04:00
|
|
|
VALUE rb_iseq_compile_node(rb_iseq_t *iseq, const NODE *node);
|
2019-08-26 01:25:53 -04:00
|
|
|
VALUE rb_iseq_compile_callback(rb_iseq_t *iseq, const struct rb_iseq_new_with_callback_callback_func * ifunc);
|
2015-07-21 18:52:59 -04:00
|
|
|
VALUE *rb_iseq_original_iseq(const rb_iseq_t *iseq);
|
|
|
|
void rb_iseq_build_from_ary(rb_iseq_t *iseq, VALUE misc,
|
2022-07-21 12:23:58 -04:00
|
|
|
VALUE locals, VALUE args,
|
|
|
|
VALUE exception, VALUE body);
|
2019-09-16 20:19:44 -04:00
|
|
|
void rb_iseq_mark_insn_storage(struct iseq_compile_data_storage *arena);
|
2008-12-04 22:35:48 -05:00
|
|
|
|
* 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 14:05:15 -05:00
|
|
|
VALUE rb_iseq_load(VALUE data, VALUE parent, VALUE opt);
|
* 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-17 18:43:38 -04:00
|
|
|
VALUE rb_iseq_parameters(const rb_iseq_t *iseq, int is_proc);
|
2011-08-24 02:31:15 -04:00
|
|
|
unsigned int rb_iseq_line_no(const rb_iseq_t *iseq, size_t pos);
|
2021-06-08 04:57:44 -04:00
|
|
|
#ifdef USE_ISEQ_NODE_ID
|
2021-04-30 05:54:46 -04:00
|
|
|
int rb_iseq_node_id(const rb_iseq_t *iseq, size_t pos);
|
|
|
|
#endif
|
2017-11-17 01:24:55 -05:00
|
|
|
void rb_iseq_trace_set(const rb_iseq_t *iseq, rb_event_flag_t turnon_events);
|
2017-11-14 07:58:36 -05:00
|
|
|
void rb_iseq_trace_set_all(rb_event_flag_t turnon_events);
|
2018-01-09 09:05:23 -05:00
|
|
|
void rb_iseq_insns_info_encode_positions(const rb_iseq_t *iseq);
|
* 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 03:49:45 -04:00
|
|
|
|
2019-12-09 01:22:48 -05:00
|
|
|
struct rb_iseq_constant_body *rb_iseq_constant_body_alloc(void);
|
2015-07-21 18:52:59 -04:00
|
|
|
VALUE rb_iseqw_new(const rb_iseq_t *iseq);
|
|
|
|
const rb_iseq_t *rb_iseqw_to_iseq(VALUE iseqw);
|
|
|
|
|
2017-05-31 20:05:33 -04:00
|
|
|
VALUE rb_iseq_absolute_path(const rb_iseq_t *iseq); /* obsolete */
|
2021-05-21 14:01:06 -04:00
|
|
|
int rb_iseq_from_eval_p(const rb_iseq_t *iseq);
|
2021-12-18 13:20:00 -05:00
|
|
|
VALUE rb_iseq_type(const rb_iseq_t *iseq);
|
2015-07-21 18:52:59 -04:00
|
|
|
VALUE rb_iseq_label(const rb_iseq_t *iseq);
|
|
|
|
VALUE rb_iseq_base_label(const rb_iseq_t *iseq);
|
|
|
|
VALUE rb_iseq_first_lineno(const rb_iseq_t *iseq);
|
|
|
|
VALUE rb_iseq_method_name(const rb_iseq_t *iseq);
|
2018-01-09 03:45:35 -05:00
|
|
|
void rb_iseq_code_location(const rb_iseq_t *iseq, int *first_lineno, int *first_column, int *last_lineno, int *last_column);
|
2012-11-30 12:00:30 -05:00
|
|
|
|
2018-08-22 06:22:02 -04:00
|
|
|
void rb_iseq_remove_coverage_all(void);
|
2018-08-22 01:24:50 -04:00
|
|
|
|
* internal.h: declare more internal functions.
* iseq.h (rb_method_get_iseq): declared.
* compile.c, eval.c, eval_error.c, iseq.c, parse.y, proc.c, range.c,
ruby.c, time.c, util.c, vm.c: don't declare internal functions.
* eval.c, parse.y, thread_pthread.c: non-existing function declarations
removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-17 21:54:57 -04:00
|
|
|
/* proc.c */
|
2015-05-21 05:01:44 -04:00
|
|
|
const rb_iseq_t *rb_method_iseq(VALUE body);
|
|
|
|
const rb_iseq_t *rb_proc_get_iseq(VALUE proc, int *is_proc);
|
* internal.h: declare more internal functions.
* iseq.h (rb_method_get_iseq): declared.
* compile.c, eval.c, eval_error.c, iseq.c, parse.y, proc.c, range.c,
ruby.c, time.c, util.c, vm.c: don't declare internal functions.
* eval.c, parse.y, thread_pthread.c: non-existing function declarations
removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-17 21:54:57 -04:00
|
|
|
|
2010-10-30 21:42:54 -04:00
|
|
|
struct rb_compile_option_struct {
|
2016-03-10 02:06:39 -05:00
|
|
|
unsigned int inline_const_cache: 1;
|
|
|
|
unsigned int peephole_optimization: 1;
|
|
|
|
unsigned int tailcall_optimization: 1;
|
|
|
|
unsigned int specialized_instruction: 1;
|
|
|
|
unsigned int operands_unification: 1;
|
|
|
|
unsigned int instructions_unification: 1;
|
|
|
|
unsigned int stack_caching: 1;
|
|
|
|
unsigned int frozen_string_literal: 1;
|
|
|
|
unsigned int debug_frozen_string_literal: 1;
|
2016-03-10 03:34:18 -05:00
|
|
|
unsigned int coverage_enabled: 1;
|
2010-10-30 21:42:54 -04:00
|
|
|
int debug_level;
|
|
|
|
};
|
* 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 03:49:45 -04:00
|
|
|
|
2017-11-09 01:57:24 -05:00
|
|
|
struct iseq_insn_info_entry {
|
|
|
|
int line_no;
|
2021-06-08 04:57:44 -04:00
|
|
|
#ifdef USE_ISEQ_NODE_ID
|
2021-04-30 05:54:46 -04:00
|
|
|
int node_id;
|
|
|
|
#endif
|
2017-11-14 07:58:36 -05:00
|
|
|
rb_event_flag_t events;
|
* 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 03:49:45 -04:00
|
|
|
};
|
|
|
|
|
2022-07-22 03:49:08 -04:00
|
|
|
/*
|
|
|
|
* iseq type:
|
|
|
|
* CATCH_TYPE_RESCUE, CATCH_TYPE_ENSURE:
|
|
|
|
* use iseq as continuation.
|
|
|
|
*
|
|
|
|
* CATCH_TYPE_BREAK (iter):
|
|
|
|
* use iseq as key.
|
|
|
|
*
|
|
|
|
* CATCH_TYPE_BREAK (while), CATCH_TYPE_RETRY,
|
|
|
|
* CATCH_TYPE_REDO, CATCH_TYPE_NEXT:
|
|
|
|
* NULL.
|
|
|
|
*/
|
2022-07-22 03:57:25 -04:00
|
|
|
enum rb_catch_type {
|
2022-07-22 03:49:08 -04:00
|
|
|
CATCH_TYPE_RESCUE = INT2FIX(1),
|
|
|
|
CATCH_TYPE_ENSURE = INT2FIX(2),
|
|
|
|
CATCH_TYPE_RETRY = INT2FIX(3),
|
|
|
|
CATCH_TYPE_BREAK = INT2FIX(4),
|
|
|
|
CATCH_TYPE_REDO = INT2FIX(5),
|
|
|
|
CATCH_TYPE_NEXT = INT2FIX(6)
|
|
|
|
};
|
|
|
|
|
* 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 03:49:45 -04:00
|
|
|
struct iseq_catch_table_entry {
|
2022-07-22 03:57:25 -04:00
|
|
|
enum rb_catch_type type;
|
2019-04-19 21:19:47 -04:00
|
|
|
rb_iseq_t *iseq;
|
2017-06-08 00:13:51 -04:00
|
|
|
|
2014-07-14 03:08:55 -04:00
|
|
|
unsigned int start;
|
|
|
|
unsigned int end;
|
|
|
|
unsigned int cont;
|
|
|
|
unsigned int sp;
|
* 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 03:49:45 -04:00
|
|
|
};
|
|
|
|
|
2014-07-14 03:06:26 -04:00
|
|
|
PACKED_STRUCT_UNALIGNED(struct iseq_catch_table {
|
2015-07-24 17:44:14 -04:00
|
|
|
unsigned int size;
|
2018-01-13 07:44:17 -05:00
|
|
|
struct iseq_catch_table_entry entries[FLEX_ARY_LEN];
|
2014-07-14 03:06:26 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
iseq_catch_table_bytes(int n)
|
|
|
|
{
|
2014-07-17 12:54:59 -04:00
|
|
|
enum {
|
2022-07-21 12:23:58 -04:00
|
|
|
catch_table_entry_size = sizeof(struct iseq_catch_table_entry),
|
|
|
|
catch_table_entries_max = (INT_MAX - offsetof(struct iseq_catch_table, entries)) / catch_table_entry_size
|
2014-07-17 12:54:59 -04:00
|
|
|
};
|
|
|
|
if (n > catch_table_entries_max) rb_fatal("too large iseq_catch_table - %d", n);
|
2018-01-14 06:19:18 -05:00
|
|
|
return (int)(offsetof(struct iseq_catch_table, entries) +
|
2022-07-21 12:23:58 -04:00
|
|
|
n * catch_table_entry_size);
|
2014-07-14 03:06:26 -04: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 03:49:45 -04:00
|
|
|
#define INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE (512)
|
|
|
|
|
|
|
|
struct iseq_compile_data_storage {
|
|
|
|
struct iseq_compile_data_storage *next;
|
2014-07-26 03:57:44 -04:00
|
|
|
unsigned int pos;
|
|
|
|
unsigned int size;
|
2018-01-13 07:44:17 -05:00
|
|
|
char buff[FLEX_ARY_LEN];
|
* 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 03:49:45 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* defined? */
|
2010-10-30 21:42:54 -04:00
|
|
|
|
|
|
|
enum defined_type {
|
2018-01-19 00:18:18 -05:00
|
|
|
DEFINED_NOT_DEFINED,
|
2012-09-24 04:36:53 -04:00
|
|
|
DEFINED_NIL = 1,
|
|
|
|
DEFINED_IVAR,
|
|
|
|
DEFINED_LVAR,
|
2010-10-30 21:42:54 -04:00
|
|
|
DEFINED_GVAR,
|
|
|
|
DEFINED_CVAR,
|
|
|
|
DEFINED_CONST,
|
|
|
|
DEFINED_METHOD,
|
|
|
|
DEFINED_YIELD,
|
|
|
|
DEFINED_ZSUPER,
|
2012-09-24 04:36:53 -04:00
|
|
|
DEFINED_SELF,
|
|
|
|
DEFINED_TRUE,
|
|
|
|
DEFINED_FALSE,
|
|
|
|
DEFINED_ASGN,
|
|
|
|
DEFINED_EXPR,
|
|
|
|
DEFINED_REF,
|
2019-11-06 01:47:32 -05:00
|
|
|
DEFINED_FUNC,
|
|
|
|
DEFINED_CONST_FROM
|
2010-10-30 21:42:54 -04: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 03:49:45 -04:00
|
|
|
|
2012-09-24 04:36:53 -04:00
|
|
|
VALUE rb_iseq_defined_string(enum defined_type type);
|
|
|
|
|
2015-12-08 00:27:10 -05:00
|
|
|
/* vm.c */
|
|
|
|
VALUE rb_iseq_local_variables(const rb_iseq_t *iseq);
|
|
|
|
|
2013-04-05 06:29:38 -04:00
|
|
|
RUBY_SYMBOL_EXPORT_END
|
2010-07-21 17:38:25 -04:00
|
|
|
|
2015-09-18 21:48:48 -04:00
|
|
|
#endif /* RUBY_ISEQ_H */
|