Skip to content

Commit

Permalink
Add findOrigin() method for find class origin
Browse files Browse the repository at this point in the history
  • Loading branch information
elct9620 committed Jul 11, 2024
1 parent 16a46f9 commit 807c0f4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
24 changes: 23 additions & 1 deletion class.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
)

var (
FlagClassIsInherited = uint32(1 << 17)
FlagUndefinedAllocate = uint32(1 << 6)
FlagClassIsInherited = uint32(1 << 17)
FlagClassIsOrigin = uint32(1 << 18)
FlagClassIsPrepended = uint32(1 << 19)
)

type methodTable map[Symbol]Method
Expand Down Expand Up @@ -252,6 +254,26 @@ func (mrb *State) checkInheritable(super RClass) {
}
}

func findOrigin(class RClass) RClass {
isNilClass := reflect.ValueOf(class).IsNil()
if isNilClass {
return nil
}

ret := class
if (ret.Flags() & FlagClassIsPrepended) != 0 {
ret = ret.Super()

for {
if (ret.Flags() & FlagClassIsOrigin) == 0 {
ret = ret.Super()
}
}
}

return ret
}

func allocObject(mrb *State, self Value) Value {
args := mrb.GetArgv()
argc := mrb.GetArgc()
Expand Down
6 changes: 6 additions & 0 deletions object.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ func (obj *Object) ivGet(sym Symbol) Value {
return obj.iv.Get(sym)
}

func (mrb *State) includeModuleAt(class, insPos, module RClass, superSearch int) int {
return 0
}

func (mrb *State) IncludeModule(class, module RClass) error {
mrb.includeModuleAt(class, findOrigin(class), module, 1)

return nil
}

Expand Down

0 comments on commit 807c0f4

Please sign in to comment.