mruby/c VM Source Code release 3.4
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)
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_methodmrbc_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- Shimane IT Open-Innovation Center.

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 626 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 591 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 118 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 163 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 304 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 210 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 255 of file class.c.

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

◆ mrbc_find_method()

mrbc_method * 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 or NULL.

Definition at line 442 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 501 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 633 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 355 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 388 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 331 of file class.c.

Here is the call graph for this function:
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 374 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 419 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 603 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);
}
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:538
Virtual Machine.
Definition vm.h:140
struct RObject mrbc_value
Definition value.h:174
#define SET_RETURN(n)
Definition value.h:261
#define mrbc_integer_value(n)
Definition value.h:208

Definition at line 538 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 67 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 102 of file class.c.

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:51

Builtin class table.

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

Definition at line 37 of file class.c.