interface.go 667 B

123456789101112131415161718192021222324252627282930313233
  1. package core
  2. type DispatchTable struct {
  3. Methods [] *Function
  4. Children [] *DispatchTable
  5. Parent *DispatchTable
  6. Interface string
  7. }
  8. func CallFirstMethod(I Interface, h RuntimeHandle) Object {
  9. var this = I.UnderlyingObject
  10. var f = *(I.DispatchTable.Methods[0])
  11. return f.Call([] Object { this }, nil, h)
  12. }
  13. func CraftSamInterface(o Object) Interface {
  14. var method = Function(NativeFunction(func(_ ([] Object), _ ([] Object), _ RuntimeHandle) Object {
  15. return o
  16. }))
  17. var table = &DispatchTable {
  18. Methods: [] *Function { &method },
  19. Children: nil,
  20. Parent: nil,
  21. }
  22. return Interface {
  23. UnderlyingObject: nil,
  24. DispatchTable: table,
  25. }
  26. }