mruby/c VM Source Code release 4.0.0
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 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 char *name, mrbc_class *super, mrbc_vtype vtype)
static mrbc_classsub_mrbc_define_class_module_under (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)
void mrbc_instance_setiv (mrbc_value *obj, mrbc_sym sym_id, mrbc_value *v)
mrbc_value mrbc_instance_getiv (mrbc_value *obj, 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)

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

◆ 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 215 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 231 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 274 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 245 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 259 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 method if found, otherwise NULL.

Definition at line 415 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 489 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 622 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 325 of file class.c.

Here is the call graph for this function:

◆ mrbc_instance_getiv()

mrbc_value mrbc_instance_getiv ( mrbc_value * obj,
mrbc_sym sym_id )

instance variable getter

Parameters
objtarget object.
sym_idkey symbol ID.
Returns
value.

Definition at line 360 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 306 of file class.c.

Here is the caller graph for this function:

◆ mrbc_instance_setiv()

void mrbc_instance_setiv ( mrbc_value * obj,
mrbc_sym sym_id,
mrbc_value * v )

instance variable setter

Parameters
objpointer to target.
sym_idkey symbol ID.
vpointer to value.

Definition at line 346 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 391 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:64
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 68 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 99 of file class.c.

◆ sub_define_class_or_module()

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

Definition at line 109 of file class.c.

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

◆ sub_mrbc_define_class_module_under()

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

Definition at line 157 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 38 of file class.c.