mruby/c VM Source Code master (2026/08/06)
Loading...
Searching...
No Matches
class.c File Reference

Class related functions. More...

#include "mrubyc.h"
#include "_autogen_builtin_class.h"
Include dependency graph for class.c:

Go to the source code of this file.

Macros

#define IS_CLASS_OR_MODULE(v)
#define MRBC_DEFINE_BUILTIN_CLASS_TABLE

Functions

mrbc_classmrbc_traverse_class_tree (mrbc_class *cls, mrbc_class *nest_buf[], int *nest_idx)
mrbc_classmrbc_traverse_class_tree_skip (mrbc_class *nest_buf[], int *nest_idx)
static mrbc_classsub_define_class_or_module (struct VM *vm, const mrbc_class *outer, const char *name, mrbc_class *super, mrbc_vtype vtype)
mrbc_classmrbc_define_class (struct VM *vm, const char *name, mrbc_class *super)
mrbc_classmrbc_define_class_under (struct VM *vm, const mrbc_class *outer, const char *name, mrbc_class *super)
mrbc_classmrbc_define_module (struct VM *vm, const char *name)
mrbc_classmrbc_define_module_under (struct VM *vm, const mrbc_class *outer, const char *name)
void mrbc_define_method (struct VM *vm, mrbc_class *cls, const char *name, mrbc_func_t cfunc)
mrbc_value mrbc_instance_new (struct VM *vm, mrbc_class *cls, int size)
void mrbc_instance_delete (mrbc_value *v)
int mrbc_instance_setiv (mrbc_value *target, mrbc_sym sym_id, mrbc_value *v)
mrbc_value mrbc_instance_getiv (mrbc_value *target, mrbc_sym sym_id)
int mrbc_obj_is_kind_of (const mrbc_value *obj, const mrbc_class *tcls)
mrbc_classmrbc_find_method (mrbc_method *r_method, mrbc_class *cls, mrbc_sym sym_id)
mrbc_classmrbc_get_class_by_name (const char *name)
mrbc_value mrbc_send (struct VM *vm, mrbc_value *v, int argc, mrbc_value *recv, const char *method_name, int n_params,...)
void c_ineffect (struct VM *vm, mrbc_value v[], int argc)
int mrbc_run_mrblib (const void *bytecode)
void mrbc_init_class (void)
void mrbc_init_class_c (void)
void mrbc_init_class_mrblib (void)

Variables

mrbc_class *const mrbc_class_tbl [MRBC_TT_MAXVAL+1]

Detailed Description

Class related functions.

Copyright (C) 2015-      Kyushu Institute of Technology.
Copyright (C) 2015-2026  Shimane IT Open-Innovation Center.
Copyright (C) 2026-      Shimane Institute for Industrial Technology.

This file is distributed under BSD 3-Clause License.

Definition in file class.c.

Macro Definition Documentation

◆ IS_CLASS_OR_MODULE

#define IS_CLASS_OR_MODULE ( v)
Value:
#define mrbc_type(o)
Definition boxing_no.h:57
@ MRBC_TT_MODULE
Module.
Definition value.h:91
@ MRBC_TT_CLASS
Class.
Definition value.h:90

Definition at line 29 of file class.c.

◆ MRBC_DEFINE_BUILTIN_CLASS_TABLE

#define MRBC_DEFINE_BUILTIN_CLASS_TABLE

Definition at line 615 of file class.c.

Function Documentation

◆ c_ineffect()

void c_ineffect ( struct VM * vm,
mrbc_value v[],
int argc )

(method) Ineffect operator / method

Definition at line 581 of file class.c.

◆ mrbc_define_class()

mrbc_class * mrbc_define_class ( struct VM * vm,
const char * name,
mrbc_class * super )

define class

Parameters
vmpointer to vm.
nameclass name.
supersuper class.
Returns
pointer to defined class.

Definition at line 191 of file class.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mrbc_define_class_under()

mrbc_class * mrbc_define_class_under ( struct VM * vm,
const mrbc_class * outer,
const char * name,
mrbc_class * super )

define nested class

Parameters
vmpointer to vm.
outerouter class
nameclass name.
supersuper class.
Returns
pointer to defined class.

Definition at line 207 of file class.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mrbc_define_method()

void mrbc_define_method ( struct VM * vm,
mrbc_class * cls,
const char * name,
mrbc_func_t cfunc )

define method.

Parameters
vmpointer to vm.
clspointer to class.
namemethod name.
cfuncpointer to function.

Definition at line 249 of file class.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mrbc_define_module()

mrbc_class * mrbc_define_module ( struct VM * vm,
const char * name )

define module

Parameters
vmpointer to vm.
namemodule name.
Returns
pointer to defined module.

Definition at line 221 of file class.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mrbc_define_module_under()

mrbc_class * mrbc_define_module_under ( struct VM * vm,
const mrbc_class * outer,
const char * name )

define nested module

Parameters
vmpointer to vm.
outerouter module
namemodule name.
Returns
pointer to defined module.

Definition at line 235 of file class.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mrbc_find_method()

mrbc_class * mrbc_find_method ( mrbc_method * r_method,
mrbc_class * cls,
mrbc_sym sym_id )

find method

Parameters
r_methodpointer to mrbc_method to return values.
clssearch class or module.
sym_idsearch symbol id.
Returns
pointer to class if found, otherwise NULL.

Definition at line 417 of file class.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mrbc_get_class_by_name()

mrbc_class * mrbc_get_class_by_name ( const char * name)

get class by name

Parameters
nameclass name.
Returns
pointer to class object.

Definition at line 491 of file class.c.

Here is the call graph for this function:

◆ mrbc_init_class()

void mrbc_init_class ( void )

initialize all classes.

Definition at line 623 of file class.c.

Here is the call graph for this function:

◆ mrbc_init_class_c()

void mrbc_init_class_c ( void )

Initialize built-in classes (scheduler-related classes excluded).

Definition at line 633 of file class.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mrbc_init_class_mrblib()

void mrbc_init_class_mrblib ( void )

Initialize Ruby-implemented classes

Definition at line 657 of file class.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mrbc_instance_delete()

void mrbc_instance_delete ( mrbc_value * v)

instance destructor

Parameters
vpointer to target value

Definition at line 300 of file class.c.

Here is the call graph for this function:

◆ mrbc_instance_getiv()

mrbc_value mrbc_instance_getiv ( mrbc_value * target,
mrbc_sym sym_id )

instance variable getter

Parameters
targettarget object or class.
sym_idkey symbol ID.
Returns
value.

Definition at line 350 of file class.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mrbc_instance_new()

mrbc_value mrbc_instance_new ( struct VM * vm,
mrbc_class * cls,
int size )

instance constructor

Parameters
vmPointer to VM.
clsPointer to Class (mrbc_class).
sizesize of additional data.
Returns
mrbc_instance object.

Definition at line 281 of file class.c.

Here is the caller graph for this function:

◆ mrbc_instance_setiv()

int mrbc_instance_setiv ( mrbc_value * target,
mrbc_sym sym_id,
mrbc_value * v )

instance variable setter

Parameters
targettarget object or class.
sym_idkey symbol ID.
vpointer to value.
Returns
error code.

Definition at line 322 of file class.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mrbc_obj_is_kind_of()

int mrbc_obj_is_kind_of ( const mrbc_value * obj,
const mrbc_class * tcls )

Check the class is the class of object.

Parameters
objtarget object
tclstarget class
Returns
result

Definition at line 393 of file class.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mrbc_run_mrblib()

int mrbc_run_mrblib ( const void * bytecode)

Run mrblib, which is mruby bytecode

Parameters
bytecodebytecode (.mrb file)
Returns
dummy yet.

Definition at line 593 of file class.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mrbc_send()

mrbc_value mrbc_send ( struct VM * vm,
mrbc_value * v,
int argc,
mrbc_value * recv,
const char * method_name,
int n_params,
... )

(BETA) Call any method of the object, but written by C.

Parameters
vmpointer to vm.
vsee below example.
argcsee below example.
recvpointer to receiver.
method_namemethod name.
n_paramsnum of params.

Examples

// (Integer).to_s(16)
static void c_integer_to_s(struct VM *vm, mrbc_value v[], int argc)
{
mrbc_value *recv = &v[1]; // expect Integer.
mrbc_value ret = mrbc_send( vm, v, argc, recv, "to_s", 1, &arg1 );
SET_RETURN(ret);
}
struct RObject mrbc_value
Value object. Default version.
#define mrbc_integer_value(n)
Definition boxing_no.h:66
mrbc_value mrbc_send(struct VM *vm, mrbc_value *v, int argc, mrbc_value *recv, const char *method_name, int n_params,...)
Definition class.c:526
Virtual Machine.
Definition vm.h:150
#define SET_RETURN(n)
Definition value.h:221

Definition at line 526 of file class.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mrbc_traverse_class_tree()

mrbc_class * mrbc_traverse_class_tree ( mrbc_class * cls,
mrbc_class * nest_buf[],
int * nest_idx )

(internal use) traverse class tree.

Parameters
clstarget class
nest_bufnest buffer
nest_idxnest buffer index
Returns
mrbc_class * next target class or NULL

Definition at line 80 of file class.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mrbc_traverse_class_tree_skip()

mrbc_class * mrbc_traverse_class_tree_skip ( mrbc_class * nest_buf[],
int * nest_idx )

(internal use) traverse class tree. skip that class.

Parameters
nest_bufnest buffer
nest_idxnest buffer index
Returns
mrbc_class * previous target class or NULL

Definition at line 111 of file class.c.

◆ sub_define_class_or_module()

mrbc_class * sub_define_class_or_module ( struct VM * vm,
const mrbc_class * outer,
const char * name,
mrbc_class * super,
mrbc_vtype vtype )
static

Definition at line 121 of file class.c.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ mrbc_class_tbl

mrbc_class* const mrbc_class_tbl[MRBC_TT_MAXVAL+1]
Initial value:
= {
0,
MRBC_CLASS(NilClass),
MRBC_CLASS(FalseClass),
MRBC_CLASS(TrueClass),
MRBC_CLASS(Integer),
MRBC_CLASS(Float),
MRBC_CLASS(Symbol),
0,
0,
0,
MRBC_CLASS(Proc),
MRBC_CLASS(Array),
MRBC_CLASS(String),
MRBC_CLASS(Range),
MRBC_CLASS(Hash),
0,
}
#define MRBC_CLASS(cls)
Definition class.h:55

Builtin class table.

Note
must be same order as mrbc_vtype.
See also
mrbc_vtype in value.h

Definition at line 42 of file class.c.