diff --git a/class.go b/class.go index f629be3..8cd9be5 100644 --- a/class.go +++ b/class.go @@ -12,6 +12,14 @@ var methods = map[string]*Method{ }, } +type RClass struct { +} + +func (mrb *State) ClassOf(v Value) *RClass { + // NOTE: Null Pointer fallback to FalseClass + return mrb.falseClass +} + func (mrb *State) FindMethod(recv Value, mid string) *Method { if m, ok := methods[mid]; ok { return m diff --git a/irep.go b/irep.go index 1ed0aa3..204bf19 100644 --- a/irep.go +++ b/irep.go @@ -84,10 +84,14 @@ func (ir *iRep) Execute(state *State) (Value, error) { b := ir.iSeq.ReadB() c := ir.iSeq.ReadB() - ci := state.PushCallinfo(ir.syms[b], c) + regs[a] = regs[0] + opCode = opSend + + ci := state.PushCallinfo(ir.syms[b], c, nil) ci.stack = append(ci.stack, regs[int(a)+1:int(a)+ci.numArgs+1]...) recv := regs[0] + ci.targetClass = state.ClassOf(recv) method := state.FindMethod(recv, ci.methodId) if method == nil { diff --git a/mruby.go b/mruby.go index ebafd49..865d62c 100644 --- a/mruby.go +++ b/mruby.go @@ -12,9 +12,10 @@ type Method struct { } type callinfo struct { - numArgs int - methodId Symbol - stack []Value + numArgs int + methodId Symbol + stack []Value + targetClass *RClass } type context struct { @@ -28,6 +29,8 @@ func (ctx *context) GetCallinfo() *callinfo { type State struct { context *context + + falseClass *RClass } func New() *State { @@ -36,6 +39,7 @@ func New() *State { ciCursor: -1, callinfos: []*callinfo{}, }, + falseClass: &RClass{}, } } diff --git a/vm.go b/vm.go index 644b947..fc9f55f 100644 --- a/vm.go +++ b/vm.go @@ -1,12 +1,13 @@ package mruby -func (state *State) PushCallinfo(mid string, argc byte) *callinfo { +func (state *State) PushCallinfo(mid string, argc byte, targetClass *RClass) *callinfo { ctx := state.context callinfo := &callinfo{ - methodId: mid, - numArgs: int(argc & 0xf), - stack: []Value{nil}, + methodId: mid, + numArgs: int(argc & 0xf), + stack: []Value{nil}, + targetClass: targetClass, } ctx.ciCursor++