73 if( *nest_idx == 0 )
return 0;
74 cls = nest_buf[--(*nest_idx)];
82 mrbc_printf(
"Warning: Module nest exceeds upper limit.\n");
84 nest_buf[(*nest_idx)++] = cls;
101 if( *nest_idx == 0 )
return 0;
102 return nest_buf[--(*nest_idx)];
139#if defined(MRBC_DEBUG)
141 cls->obj_mark_[0] =
'C';
142 cls->obj_mark_[1] =
'L';
144 cls->obj_mark_[0] =
'M';
145 cls->obj_mark_[1] =
'O';
190#if defined(MRBC_DEBUG)
192 cls->obj_mark_[0] =
'C';
193 cls->obj_mark_[1] =
'L';
195 cls->obj_mark_[0] =
'M';
196 cls->obj_mark_[1] =
'O';
279 "Adding methods to the %s class is not supported",
289 if( method->
sym_id < 0 ) {
292 method->
func = cfunc;
329#if MRBC_INSTANCE_DESTRUCTOR
370#if defined(MRBC_ALLOC_VMID)
397 while( cls != tcls ) {
423 if( cls->
super ) nest_buf[nest_idx++] = cls;
433 if( method->
sym_id == sym_id ) {
435 r_method->
cls = cls_save;
442 if( right == 0 )
goto next_class;
446 while( left < right ) {
447 int mid = (left + right) / 2;
492 if(
sym_id < 0 )
return NULL;
495 if( obj == NULL )
return NULL;
527 mrbc_value *recv,
const char *method_name,
int n_params, ... )
540 "Method needs to be C function. '%s' for %s",
552 va_start(ap, n_params);
554 for( i = 1; i <= n_params; i++ ) {
564 method.
func(vm, regs, n_params);
567 for(; i >= 0; i-- ) {
615#define MRBC_DEFINE_BUILTIN_CLASS_TABLE
616#include "_autogen_builtin_class.h"
617#undef MRBC_DEFINE_BUILTIN_CLASS_TABLE
627 for(
int i = 0; i <
sizeof(MRBC_BuiltinClass)/
sizeof(
struct MRBC_BuiltinClass); i++ ) {
641 extern const uint8_t mrblib_bytecode[];
void * mrbc_raw_alloc_no_free(unsigned int size)
void mrbc_raw_free(void *ptr)
static void mrbc_set_nil(mrbc_value *p)
#define mrbc_immediate_value(...)
static void mrbc_set_tt(mrbc_value *p, mrbc_vtype type)
struct RObject mrbc_value
Value object. Default version.
void mrbc_init_module_math(void)
mrbc_value mrbc_instance_new(struct VM *vm, mrbc_class *cls, int size)
mrbc_class * mrbc_get_class_by_name(const char *name)
mrbc_class * mrbc_find_method(mrbc_method *r_method, mrbc_class *cls, mrbc_sym sym_id)
void mrbc_init_class(void)
mrbc_class * mrbc_define_module_under(struct VM *vm, const mrbc_class *outer, const char *name)
void c_ineffect(struct VM *vm, mrbc_value v[], int argc)
static mrbc_class * sub_mrbc_define_class_module_under(struct VM *vm, const mrbc_class *outer, const char *name, mrbc_class *super, mrbc_vtype vtype)
int mrbc_obj_is_kind_of(const mrbc_value *obj, const mrbc_class *tcls)
void mrbc_define_method(struct VM *vm, mrbc_class *cls, const char *name, mrbc_func_t cfunc)
mrbc_value mrbc_instance_getiv(mrbc_value *obj, mrbc_sym sym_id)
mrbc_class * mrbc_traverse_class_tree(mrbc_class *cls, mrbc_class *nest_buf[], int *nest_idx)
static mrbc_class * sub_define_class_or_module(struct VM *vm, const char *name, mrbc_class *super, mrbc_vtype vtype)
void mrbc_instance_delete(mrbc_value *v)
mrbc_class * mrbc_define_module(struct VM *vm, const char *name)
int mrbc_run_mrblib(const void *bytecode)
void mrbc_instance_setiv(mrbc_value *obj, mrbc_sym sym_id, mrbc_value *v)
mrbc_value mrbc_send(struct VM *vm, mrbc_value *v, int argc, mrbc_value *recv, const char *method_name, int n_params,...)
mrbc_class * mrbc_define_class_under(struct VM *vm, const mrbc_class *outer, const char *name, mrbc_class *super)
mrbc_class *const mrbc_class_tbl[MRBC_TT_MAXVAL+1]
mrbc_class * mrbc_define_class(struct VM *vm, const char *name, mrbc_class *super)
mrbc_class * mrbc_traverse_class_tree_skip(mrbc_class *nest_buf[], int *nest_idx)
struct RInstance mrbc_instance
Instance object.
#define MRBC_TRAVERSE_NEST_LEVEL
struct RMethod mrbc_method
Method management structure.
static mrbc_class * find_class_by_object(const mrbc_value *obj)
struct RClass mrbc_class
Class object.
void mrbc_printf(const char *fstr,...)
void mrbc_raise(struct VM *vm, struct RClass *exc_cls, const char *msg)
void mrbc_print_vm_exception(const struct VM *vm)
void mrbc_raisef(struct VM *vm, struct RClass *exc_cls, const char *fstr,...)
int mrbc_set_class_const(const mrbc_class *cls, mrbc_sym sym_id, mrbc_value *v)
mrbc_value * mrbc_get_const(mrbc_sym sym_id)
int mrbc_set_const(mrbc_sym sym_id, mrbc_value *v)
mrbc_value * mrbc_get_class_const(const mrbc_class *cls, mrbc_sym sym_id)
void mrbc_kv_delete_data(mrbc_kv_handle *kvh)
mrbc_value * mrbc_kv_get(mrbc_kv_handle *kvh, mrbc_sym sym_id)
int mrbc_kv_set(mrbc_kv_handle *kvh, mrbc_sym sym_id, mrbc_value *set_val)
#define MRBC_KVH_INITIALIZER(vm)
int mrbc_load_mrb(mrbc_vm *vm, const void *bytecode)
Include at once the necessary header files.
uint8_t num_builtin_method
num of built-in method.
unsigned int flag_module
is module?
mrbc_sym sym_id
class name's symbol ID
const mrbc_sym * method_symbols
built-in method sym-id table.
const mrbc_func_t * method_functions
built-in method function table.
struct RMethod * method_link
pointer to method link.
unsigned int flag_alias
is module alias?
struct RClass * super
pointer to super class.
struct RClass * aliased
aliased class or module.
unsigned int flag_builtin
is built-in class? (= 0)
mrbc_sym sym_id
class name's symbol ID
void(* destructor)(mrbc_value *)
specify a destructor if need.
unsigned int flag_nomethod
is built-in no method class? (= 0)
unsigned int flag_module
is module?
struct RClass * cls
pointer to class of this object.
struct RKeyValueHandle ivar
instance variable.
struct RClass * cls
return value for mrbc_find_method.
mrbc_sym sym_id
function names symbol ID
uint8_t type
M:OP_DEF or OP_ALIAS, m:mrblib or define_method().
struct RMethod * next
link to next method.
uint8_t c_func
0:IREP, 1:C Func, 2:C Func (built-in)
mrbc_func_t func
to C function.
struct RInstance * instance
mrbc_sym callee_sym_id
Current called method.
mrbc_sym mrbc_search_symid(const char *str)
mrbc_value mrbc_symbol_new(struct VM *vm, const char *str)
mrbc_sym mrbc_str_to_symid(const char *str)
const char * mrbc_symid_to_str(mrbc_sym sym_id)
void make_nested_symbol_s(char *buf, mrbc_sym id1, mrbc_sym id2)
static void mrbc_decref(mrbc_value *v)
#define MRBC_INIT_OBJECT_HEADER_DI(t)
void(* mrbc_func_t)(struct VM *vm, struct RObject *v, int argc)
static void mrbc_incref(mrbc_value *v)
int16_t mrbc_sym
mruby/c symbol ID
@ MRBC_TT_OBJECT
General instance.
void mrbc_vm_close(mrbc_vm *vm)
mrbc_vm * mrbc_vm_new(int regs_size)
int mrbc_vm_run(mrbc_vm *vm)
void mrbc_vm_end(mrbc_vm *vm)
void mrbc_vm_begin(mrbc_vm *vm)
struct VM mrbc_vm
Virtual Machine.
Global configuration of mruby/c VM's.