Skip to content

Commit

Permalink
Revert "Refactor to remove nested instance variable struct in object/…
Browse files Browse the repository at this point in the history
…class"

This reverts commit 92cbe74.
  • Loading branch information
elct9620 committed Aug 8, 2024
1 parent e23df0f commit e83fdbe
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
8 changes: 4 additions & 4 deletions class.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type class struct {
Object
super RClass
mt
iv ivTable
iv
}

type Class struct {
Expand Down Expand Up @@ -192,18 +192,18 @@ func (mrb *State) defineMethodRaw(class RClass, name Symbol, method Method) {

func (c *class) ivPut(sym Symbol, val Value) {
if c.iv == nil {
c.iv = make(ivTable)
c.iv = make(iv)
}

c.iv[sym] = val
c.iv.Put(sym, val)
}

func (c *class) ivGet(sym Symbol) Value {
if c.iv == nil {
return nil
}

return c.iv[sym]
return c.iv.Get(sym)
}

func (c *class) mtPut(sym Symbol, method Method) {
Expand Down
8 changes: 4 additions & 4 deletions object.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var _ RObject = &Object{}
type Object struct {
class RClass
flags uint32
iv ivTable
iv
}

func (obj *Object) Class() RClass {
Expand All @@ -32,18 +32,18 @@ func (obj *Object) Flags() uint32 {

func (obj *Object) ivPut(sym Symbol, val Value) {
if obj.iv == nil {
obj.iv = make(ivTable)
obj.iv = make(iv)
}

obj.iv[sym] = val
obj.iv.Put(sym, val)
}

func (obj *Object) ivGet(sym Symbol) Value {
if obj.iv == nil {
return nil
}

return obj.iv[sym]
return obj.iv.Get(sym)
}

func (mrb *State) includeModuleAt(class, insPos, module RClass, superSearch int) int {
Expand Down
9 changes: 9 additions & 0 deletions variable.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
package mruby

type ivTable map[Symbol]Value
type iv = ivTable

func (iv ivTable) Get(sym Symbol) Value {
return iv[sym]
}

func (iv ivTable) Put(sym Symbol, val Value) {
iv[sym] = val
}

func (mrb *State) ObjectInstanceVariableSetForce(obj RObject, name Symbol, val Value) {
obj.ivPut(name, val)
Expand Down

0 comments on commit e83fdbe

Please sign in to comment.