1#ifndef INTERNAL_IMEMO_H
2#define INTERNAL_IMEMO_H
11#include "ruby/internal/config.h"
14#include "internal/array.h"
18#define IMEMO_MASK 0x0f
21#define IMEMO_FL_USHIFT (FL_USHIFT + 4)
22#define IMEMO_FL_USER0 FL_USER4
23#define IMEMO_FL_USER1 FL_USER5
24#define IMEMO_FL_USER2 FL_USER6
25#define IMEMO_FL_USER3 FL_USER7
26#define IMEMO_FL_USER4 FL_USER8
27#define IMEMO_FL_USER5 FL_USER9
28#define IMEMO_FL_USER6 FL_USER10
43 imemo_constcache = 12,
62 const VALUE throw_obj;
67#define THROW_DATA_CONSUMED IMEMO_FL_USER0
72#if SIZEOF_INT * 2 > SIZEOF_VALUE
93#define IFUNC_YIELD_OPTIMIZABLE IMEMO_FL_USER0
118#define IMEMO_NEW(T, type, v0) ((T *)rb_imemo_new((type), (v0), sizeof(T), false))
119#define SHAREABLE_IMEMO_NEW(T, type, v0) ((T *)rb_imemo_new((type), (v0), sizeof(T), true))
123#define THROW_DATA_P(err) imemo_throw_data_p((VALUE)err)
124#define MEMO_CAST(m) ((struct MEMO *)(m))
125#define MEMO_FOR(type, value) ((type *)RARRAY_PTR(value))
126#define NEW_MEMO_FOR(type, value) \
127 ((value) = rb_ary_hidden_new_fill(type_roomof(type, VALUE)), MEMO_FOR(type, value))
128#define NEW_PARTIAL_MEMO_FOR(type, value, member) \
129 ((value) = rb_ary_hidden_new_fill(type_roomof(type, VALUE)), \
130 rb_ary_set_len((value), offsetof(type, member) / sizeof(VALUE)), \
131 MEMO_FOR(type, value))
133#ifndef RUBY_RUBYPARSER_H
136VALUE rb_imemo_new(
enum imemo_type
type,
VALUE v0,
size_t size,
bool is_shareable);
137VALUE rb_imemo_tmpbuf_new(
void);
139static inline enum imemo_type imemo_type(
VALUE imemo);
140static inline int imemo_type_p(
VALUE imemo,
enum imemo_type imemo_type);
141static inline bool imemo_throw_data_p(
VALUE imemo);
143static inline void *RB_IMEMO_TMPBUF_PTR(
VALUE v);
144static inline void *rb_imemo_tmpbuf_set_ptr(
VALUE v,
void *ptr);
145static inline void MEMO_V1_SET(
struct MEMO *m,
VALUE v);
146static inline void MEMO_V2_SET(
struct MEMO *m,
VALUE v);
148size_t rb_imemo_memsize(
VALUE obj);
149void rb_imemo_mark_and_move(
VALUE obj,
bool reference_updating);
150void rb_imemo_free(
VALUE obj);
152RUBY_SYMBOL_EXPORT_BEGIN
153const char *rb_imemo_name(
enum imemo_type
type);
154RUBY_SYMBOL_EXPORT_END
156static inline struct MEMO *
159 struct MEMO *memo = IMEMO_NEW(
struct MEMO, imemo_memo, 0);
160 *((
VALUE *)&memo->v1) = a;
161 *((
VALUE *)&memo->v2) = b;
162 *((
VALUE *)&memo->u3.value) = c;
167static inline enum imemo_type
168imemo_type(
VALUE imemo)
174imemo_type_p(
VALUE imemo,
enum imemo_type imemo_type)
181 return expected_type == (
RBASIC(imemo)->flags & mask);
188#define IMEMO_TYPE_P(v, t) imemo_type_p((VALUE)(v), t)
191imemo_throw_data_p(
VALUE imemo)
203RB_IMEMO_TMPBUF_PTR(
VALUE v)
210rb_imemo_tmpbuf_set_ptr(
VALUE v,
void *ptr)
212 return ((rb_imemo_tmpbuf_t *)v)->ptr = ptr;
216rb_imemo_tmpbuf_new_from_an_RString(
VALUE str)
220 rb_imemo_tmpbuf_t *tmpbuf;
226 imemo = rb_imemo_tmpbuf_new();
227 tmpbuf = (rb_imemo_tmpbuf_t *)imemo;
228 len = RSTRING_LEN(str);
229 src = RSTRING_PTR(str);
230 dst = ruby_xmalloc(
len);
231 memcpy(dst, src,
len);
267#define OBJ_FIELD_HEAP ROBJECT_HEAP
268STATIC_ASSERT(imemo_fields_flags, OBJ_FIELD_HEAP == IMEMO_FL_USER0);
269STATIC_ASSERT(imemo_fields_embed_offset, offsetof(
struct RObject, as.ary) == offsetof(
struct rb_fields, as.embed.fields));
270STATIC_ASSERT(imemo_fields_embed_offset, offsetof(
struct RObject, as.
heap.
fields) == offsetof(
struct rb_fields, as.external.ptr));
271STATIC_ASSERT(imemo_fields_embed_offset, offsetof(
struct RObject, as.
heap.
fields) == offsetof(
struct rb_fields, as.complex.table));
273#define IMEMO_OBJ_FIELDS(fields) ((struct rb_fields *)fields)
275VALUE rb_imemo_fields_new(
VALUE owner,
size_t capa,
bool shareable);
276VALUE rb_imemo_fields_new_complex(
VALUE owner,
size_t capa,
bool shareable);
277VALUE rb_imemo_fields_new_complex_tbl(
VALUE owner, st_table *tbl,
bool shareable);
279void rb_imemo_fields_clear(
VALUE fields_obj);
282rb_imemo_fields_owner(
VALUE fields_obj)
284 RUBY_ASSERT(IMEMO_TYPE_P(fields_obj, imemo_fields));
290rb_imemo_fields_ptr(
VALUE fields_obj)
298 if (UNLIKELY(
FL_TEST_RAW(fields_obj, OBJ_FIELD_HEAP))) {
299 return IMEMO_OBJ_FIELDS(fields_obj)->as.external.ptr;
302 return IMEMO_OBJ_FIELDS(fields_obj)->as.embed.fields;
306static inline st_table *
307rb_imemo_fields_complex_tbl(
VALUE fields_obj)
318 RUBY_ASSERT((st_table *)rb_imemo_fields_ptr(fields_obj) == IMEMO_OBJ_FIELDS(fields_obj)->as.complex.table);
320 return IMEMO_OBJ_FIELDS(fields_obj)->as.complex.table;
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
#define T_IMEMO
Old name of RUBY_T_IMEMO.
#define CLASS_OF
Old name of rb_class_of.
#define FL_TEST_RAW
Old name of RB_FL_TEST_RAW.
#define T_OBJECT
Old name of RUBY_T_OBJECT.
#define FL_USHIFT
Old name of RUBY_FL_USHIFT.
#define RB_OBJ_WRITE(old, slot, young)
Declaration of a "back" pointer.
#define UNLIMITED_ARGUMENTS
This macro is used in conjunction with rb_check_arity().
int capa
Designed capacity of the buffer.
int len
Length of the buffer.
rb_block_call_func * rb_block_call_func_t
Shorthand type that represents an iterator-written-in-C function pointer.
VALUE type(ANYARGS)
ANYARGS-ed function type.
#define RBASIC(obj)
Convenient casting macro.
#define StringValue(v)
Ensures that the parameter object is a String.
static bool RB_SPECIAL_CONST_P(VALUE obj)
Checks if the given object is of enum ruby_special_consts.
C99 shim for <stdbool.h>.
Ruby object's base components.
VALUE * fields
Pointer to a C array that holds instance variables.
struct RObject::@210145204263252121304200074116325373231002256127::@364327012272247144206277021107154033016101046306 heap
Object that use separated memory region for instance variables use this pattern.
IFUNC (Internal FUNCtion).
const VALUE cref_or_me
class reference or rb_method_entry_t
#define SIZEOF_VALUE
Identical to sizeof(VALUE), except it is a macro that can also be used inside of preprocessor directi...
uintptr_t VALUE
Type that represents a Ruby object.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.
@ RUBY_T_MASK
Bitmask of ruby_value_type.