name (string) ‣ Every class names and method names are in symbol table ‣ So if some classes and methods are in ROM, symbol table is defined and in ROM id name 1 BasicObject 2 Object 3 Module 4 Class 5 __classname__ 6 Proc 7 initialize … …
making symbol table */ mrb_init_class(mrb); /* Class */ mrb_init_object(mrb); /* Object */ mrb_init_kernel(mrb); /* Kernel */ mrb_init_XXXX(mrb); /* class libraries in C */ mrb_init_mrblib(mrb); /* class libraries in Ruby */ mrb_init_mrbgems(mrb); /* gems for mruby */ }
scripts ‣ standard libraries and mrbgems written in Ruby are compiled into IREPs /* Program data array struct */ typedef struct mrb_irep { uint16_t nlocals; /* Number of local variables */ uint16_t nregs; /* Number of register variables */ uint8_t flags; mrb_code *iseq; mrb_value *pool; mrb_sym *syms; struct mrb_irep **reps; struct mrb_locals *lv; /* debug info */ mrb_bool own_filename; const char *filename; uint16_t *lines; struct mrb_irep_debug_info* debug_info; int ilen, plen, slen, rlen, refcnt; } mrb_irep;
methods in C are static functions, so we cannot refer in generated C files. ‣ We need to fix them. static mrb_value mrb_ary_plus(mrb_state *mrb, mrb_value self) { struct RArray *a1 = mrb_ary_ptr(self); /* ... */
more ‣ Ruby is dynamic, every class objects can be mutable ‣ Even if they are mutable, decompose and put parts of them on ROM ‣ You can use mruby on various boards!