program.go 682 B

12345678910111213141516171819202122232425262728293031323334
  1. package program
  2. import (
  3. "kumachan/lang/source"
  4. "kumachan/lang/typsys"
  5. "kumachan/interpreter/core"
  6. )
  7. type Program struct {
  8. Metadata Metadata
  9. TypeInfo TypeInfo
  10. Executable Executable
  11. }
  12. type Metadata struct {
  13. ProgramPath string
  14. }
  15. type Executable interface {
  16. LookupEntry(ns string) (**Function, bool)
  17. }
  18. type TypeInfo struct {
  19. TypeRegistry map[source.Ref] *typsys.TypeDef
  20. }
  21. func (rtti TypeInfo) LookupType(rt core.ReflectType) (*typsys.TypeDef, source.Ref, ([] typsys.Type), bool) {
  22. var t = rt.Type()
  23. if T, ok := t.(typsys.RefType); ok {
  24. if def, ok := rtti.TypeRegistry[T.Def]; ok {
  25. return def, T.Def, T.Args, true
  26. }}
  27. return nil, source.Ref{}, nil, false
  28. }