1#ifndef INTERNAL_IMEMO_H
2#define INTERNAL_IMEMO_H
11#include "ruby/internal/config.h"
14#include "internal/array.h"
20#define IMEMO_MASK (FL_USER0 | FL_USER1 | FL_USER2 | FL_USER3 | FL_USER4)
23#define IMEMO_FL_USHIFT (FL_USHIFT + 5)
24#define IMEMO_FL_USER0 FL_USER5
25#define IMEMO_FL_USER1 FL_USER6
26#define IMEMO_FL_USER2 FL_USER7
27#define IMEMO_FL_USER3 FL_USER8
28#define IMEMO_FL_USER4 FL_USER9
29#define IMEMO_FL_USER5 FL_USER10
30#define IMEMO_FL_USER6 FL_USER11
45 imemo_constcache = 12,
47 imemo_subclasses = 14,
65 const VALUE throw_obj;
70#define THROW_DATA_CONSUMED IMEMO_FL_USER0
75#if SIZEOF_INT * 2 > SIZEOF_VALUE
96#define IFUNC_YIELD_OPTIMIZABLE IMEMO_FL_USER0
112#define MEMO_U3_IS_VALUE IMEMO_FL_USER0
130#define IMEMO_NEW(T, type, v0) ((T *)rb_imemo_new((type), (v0), sizeof(T), false))
131#define SHAREABLE_IMEMO_NEW(T, type, v0) ((T *)rb_imemo_new((type), (v0), sizeof(T), true))
135#define THROW_DATA_P(err) imemo_throw_data_p((VALUE)err)
136#define MEMO_CAST(m) ((struct MEMO *)(m))
137#define MEMO_FOR(type, value) ((type *)RARRAY_PTR(value))
138#define NEW_MEMO_FOR(type, value) \
139 ((value) = rb_ary_hidden_new_fill(type_roomof(type, VALUE)), MEMO_FOR(type, value))
140#define NEW_PARTIAL_MEMO_FOR(type, value, member) \
141 ((value) = rb_ary_hidden_new_fill(type_roomof(type, VALUE)), \
142 rb_ary_set_len((value), offsetof(type, member) / sizeof(VALUE)), \
143 MEMO_FOR(type, value))
145#ifndef RUBY_RUBYPARSER_H
148VALUE rb_imemo_new(
enum imemo_type
type,
VALUE v0,
size_t size,
bool is_shareable);
152static inline enum imemo_type imemo_type(
VALUE imemo);
153static inline int imemo_type_p(
VALUE imemo,
enum imemo_type imemo_type);
154static inline bool imemo_throw_data_p(
VALUE imemo);
156static inline void *RB_IMEMO_TMPBUF_PTR(
VALUE v);
157static inline void MEMO_V1_SET(
struct MEMO *m,
VALUE v);
158static inline void MEMO_V2_SET(
struct MEMO *m,
VALUE v);
160size_t rb_imemo_memsize(
VALUE obj);
161void rb_imemo_mark_and_move(
const struct rb_gc_mark_ctx *ctx,
VALUE obj,
bool reference_updating);
162void rb_imemo_free(
VALUE obj);
164RUBY_SYMBOL_EXPORT_BEGIN
165const char *rb_imemo_name(
enum imemo_type
type);
166ID rb_imemo_callinfo_mid(
VALUE obj);
172RUBY_SYMBOL_EXPORT_END
174static inline enum imemo_type
175imemo_type(
VALUE imemo)
181imemo_type_p(
VALUE imemo,
enum imemo_type imemo_type)
188 return expected_type == (
RBASIC(imemo)->flags & mask);
195#define IMEMO_TYPE_P(v, t) imemo_type_p((VALUE)(v), t)
198imemo_throw_data_p(
VALUE imemo)
210RB_IMEMO_TMPBUF_PTR(
VALUE v)
217rb_imemo_tmpbuf_new_from_an_RString(
VALUE str)
223 len = RSTRING_LEN(str);
224 rb_alloc_tmp_buffer(&imemo,
len,
false);
225 memcpy(RB_IMEMO_TMPBUF_PTR(imemo), RSTRING_PTR(str),
len);
244rb_imemo_cdhash_tbl(
VALUE obj)
264STATIC_ASSERT(imemo_fields_embed_offset, offsetof(
struct RObject, as.ary) == offsetof(
struct rb_fields, as.embed.fields));
266#define IMEMO_OBJ_FIELDS(fields) ((struct rb_fields *)fields)
268#define IMEMO_SUBCLASSES_HEAP IMEMO_FL_USER0
281rb_imemo_subclasses_entries(
VALUE v)
284 return FL_TEST_RAW(v, IMEMO_SUBCLASSES_HEAP) ? s->as.external : s->as.embed;
287VALUE rb_imemo_fields_new(
VALUE owner, uint32_t shape_id,
bool shareable);
288VALUE rb_imemo_subclasses_new(uint32_t capacity);
289VALUE rb_imemo_fields_new_complex(
VALUE owner, uint32_t shape_id,
size_t capa,
bool shareable);
290VALUE rb_imemo_fields_new_complex_empty(
VALUE owner);
292void rb_imemo_fields_clear(
VALUE fields_obj);
295rb_imemo_fields_owner(
VALUE fields_obj)
297 RUBY_ASSERT(IMEMO_TYPE_P(fields_obj, imemo_fields));
#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 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.
Ruby object's base components.
IFUNC (Internal FUNCtion)
const VALUE cref_or_me
class reference or rb_method_entry_t
long rb_len_t
A signed integer type for lengths and indices of objects such as String and Array.
unsigned long rb_ulen_t
An unsigned integer type that has the same width with rb_len_t.
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
#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.