This is a port of the mruby/c tutorial Chapter 03 to the mbed environment.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

vm.c File Reference

vm.c File Reference

mruby bytecode executor. More...

Go to the source code of this file.

Functions

static char * find_irep_symbol (uint8_t *p, int n)
 find sym[n] from symbol table in irep
static int op_nop (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute NOP.
static int op_move (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute MOVE.
static int op_loadl (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute LOADL.
static int op_loadi (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute LOADI.
static int op_loadsym (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute LOADSYM.
static int op_loadnil (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute LOADNIL.
static int op_loadself (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute LOADSELF.
static int op_loadt (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute LOADT.
static int op_loadf (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute LOADF.
static int op_getglobal (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute GETGLOBAL.
static int op_setglobal (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute SETGLOBAL.
static int op_getconst (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute GETCONST.
static int op_setconst (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute SETCONST.
static int op_jmp (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute JMP.
static int op_jmpif (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute JMPIF.
static int op_jmpnot (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute JMPNOT.
static int op_send (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute SEND.
static int op_enter (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute ENTER.
static int op_return (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute RETURN.
static int op_add (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute ADD.
static int op_addi (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute ADDI.
static int op_sub (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute ADD.
static int op_subi (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute.
static int op_mul (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute.
static int op_div (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute.
static int op_eq (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute EQ.
static int op_lt (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute LT.
static int op_le (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute LE.
static int op_gt (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute GE.
static int op_ge (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute GE.
static int op_array (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Make Array.
static int op_string (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Create string object.
static int op_hash (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Create HASH object.
static int op_lambda (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute LAMBDA.
static int op_range (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute RANGE.
static int op_class (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute CLASS.
static int op_method (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute METHOD.
static int op_tclass (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute TCLASS.
static int op_stop (mrb_vm *vm, uint32_t code, mrb_value *regs)
 Execute STOP.
mrb_irep * new_irep (mrb_vm *vm)
 Allocate new IREP.
struct VM * vm_open (void)
 VM initializer.
void vm_close (struct VM *vm)
 VM finalizer.
void vm_boot (struct VM *vm)
 Boot the VM.
int vm_run (mrb_vm *vm)
 Fetch a bytecode and execute.
void debug_irep (mrb_vm *vm, mrb_irep *irep)

Detailed Description

mruby bytecode executor.

  Copyright (C) 2015 Kyushu Institute of Technology.
  Copyright (C) 2015 Shimane IT Open-Innovation Center.
  This file is distributed under BSD 3-Clause License.
  Fetch mruby VM bytecodes, decode and execute.
  

Definition in file vm.c.


Function Documentation

void debug_irep ( mrb_vm *  vm,
mrb_irep *  irep 
)
Parameters:
vmPointer of VM.
irep
Returns:

Definition at line 1351 of file vm.c.

static char* find_irep_symbol ( uint8_t *  p,
int  n 
) [static]

find sym[n] from symbol table in irep

Parameters:
p
n
Returns:
symbol string

Definition at line 39 of file vm.c.

mrb_irep* new_irep ( mrb_vm *  vm )

Allocate new IREP.

Parameters:
vmPointer of VM.
Returns:
Pointer of new IREP.

Definition at line 1192 of file vm.c.

static int op_add ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute ADD.

R(A) := R(A)+R(A+1) (Syms[B]=:+,C=1)

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 492 of file vm.c.

static int op_addi ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute ADDI.

R(A) := R(A)+C (Syms[B]=:+)

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 533 of file vm.c.

static int op_array ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Make Array.

R(A) := ary_new(R(B),R(B+1)..R(B+C))

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 922 of file vm.c.

static int op_class ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute CLASS.

R(A) := newclass(R(A),Syms(B),R(A+1)) Syms(B): class name R(A+1): super class

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 1109 of file vm.c.

static int op_div ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute.

R(A) := R(A)/R(A+1) (Syms[B]=:/)

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 657 of file vm.c.

static int op_enter ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute ENTER.

arg setup according to flags (23=5:5:1:5:5:1:1)

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 442 of file vm.c.

static int op_eq ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute EQ.

R(A) := R(A)==R(A+1) (Syms[B]=:==,C=1)

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 693 of file vm.c.

static int op_ge ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute GE.

R(A) := R(A)>=R(A+1) (Syms[B]=:>=,C=1)

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 879 of file vm.c.

static int op_getconst ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute GETCONST.

R(A) := constget(Syms(Bx))

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 295 of file vm.c.

static int op_getglobal ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute GETGLOBAL.

R(A) := getglobal(Syms(Bx))

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 251 of file vm.c.

static int op_gt ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute GE.

R(A) := R(A)>=R(A+1) (Syms[B]=:>=,C=1)

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 836 of file vm.c.

static int op_hash ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Create HASH object.

R(A) := hash_new(R(B),R(B+1)..R(B+C))

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 1001 of file vm.c.

static int op_jmp ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute JMP.

pc += sBx

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 339 of file vm.c.

static int op_jmpif ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute JMPIF.

if R(A) pc += sBx

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 357 of file vm.c.

static int op_jmpnot ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute JMPNOT.

if not R(A) pc += sBx

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 377 of file vm.c.

static int op_lambda ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute LAMBDA.

R(A) := lambda(SEQ[Bz],Cz)

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 1054 of file vm.c.

static int op_le ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute LE.

R(A) := R(A)<=R(A+1) (Syms[B]=:<=,C=1)

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 793 of file vm.c.

static int op_loadf ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute LOADF.

R(A) := false

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 233 of file vm.c.

static int op_loadi ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute LOADI.

R(A) := sBx

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 133 of file vm.c.

static int op_loadl ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute LOADL.

R(A) := Pool(Bx)

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 109 of file vm.c.

static int op_loadnil ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute LOADNIL.

R(A) := nil

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 179 of file vm.c.

static int op_loadself ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute LOADSELF.

R(A) := self

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 197 of file vm.c.

static int op_loadsym ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute LOADSYM.

R(A) := Syms(Bx)

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 153 of file vm.c.

static int op_loadt ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute LOADT.

R(A) := true

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 215 of file vm.c.

static int op_lt ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute LT.

R(A) := R(A)<R(A+1) (Syms[B]=:<,C=1)

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 749 of file vm.c.

static int op_method ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute METHOD.

R(A).newmethod(Syms(B),R(A+1))

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 1128 of file vm.c.

static int op_move ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute MOVE.

R(A) := R(B)

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 91 of file vm.c.

static int op_mul ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute.

R(A) := R(A)*R(A+1) (Syms[B]=:*)

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 621 of file vm.c.

static int op_nop ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute NOP.

No operation

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 74 of file vm.c.

static int op_range ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute RANGE.

R(A) := R(A) := range_new(R(B),R(B+1),C)

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 1086 of file vm.c.

static int op_return ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute RETURN.

return R(A) (B=normal,in-block return/break)

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 466 of file vm.c.

static int op_send ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute SEND.

R(A) := call(R(A),Syms(B),R(A+1),...,R(A+C))

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 397 of file vm.c.

static int op_setconst ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute SETCONST.

constset(Syms(Bx),R(A))

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 318 of file vm.c.

static int op_setglobal ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute SETGLOBAL.

setglobal(Syms(Bx), R(A))

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 273 of file vm.c.

static int op_stop ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute STOP.

stop VM

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 1178 of file vm.c.

static int op_string ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Create string object.

R(A) := str_dup(Lit(Bx))

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 971 of file vm.c.

static int op_sub ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute ADD.

R(A) := R(A)-R(A+1) (Syms[B]=:-,C=1)

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 559 of file vm.c.

static int op_subi ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute.

R(A) := R(A)-C (Syms[B]=:-)

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 595 of file vm.c.

static int op_tclass ( mrb_vm *  vm,
uint32_t  code,
mrb_value *  regs 
) [static]

Execute TCLASS.

R(A) := target_class

Parameters:
vmA pointer of VM.
codebytecode
regsvm->regs + vm->reg_top
Return values:
0No error.

Definition at line 1158 of file vm.c.

void vm_boot ( struct VM *  vm )

Boot the VM.

Parameters:
vmPointer of VM

Definition at line 1254 of file vm.c.

void vm_close ( struct VM *  vm )

VM finalizer.

Parameters:
vmPointer of VM

Definition at line 1239 of file vm.c.

struct VM* vm_open ( void   ) [read]

VM initializer.

Get a VM from static heap.

Returns:
Pointer of struct VM in static area.
  init_static();
  struct VM *vm = vm_open();

Definition at line 1212 of file vm.c.

int vm_run ( mrb_vm *  vm )

Fetch a bytecode and execute.

Parameters:
vmA pointer of VM.
Return values:
0No error.

Definition at line 1278 of file vm.c.