type.go 701 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package typsys
  2. import "kumachan/lang/source"
  3. type Type interface { impl(Type) }
  4. type CertainType struct { Type Type }
  5. func (InferringType) impl(Type) {}
  6. type InferringType struct {
  7. Id string
  8. }
  9. func (ParameterType) impl(Type) {}
  10. type ParameterType struct {
  11. Name string
  12. }
  13. func (RefType) impl(Type) {}
  14. type RefType struct {
  15. Def source.Ref
  16. Args [] Type
  17. }
  18. func DefType(def *TypeDef) Type {
  19. return DefType2(def.Ref, def.Parameters)
  20. }
  21. func DefType2(ref source.Ref, params ([] string)) Type {
  22. return RefType {
  23. Def: ref,
  24. Args: (func() ([] Type) {
  25. var args = make([] Type, len(params))
  26. for i, p := range params {
  27. args[i] = ParameterType { p }
  28. }
  29. return args
  30. })(),
  31. }
  32. }