Untested rules for pulling types from other section kinds

This commit is contained in:
Sasha Koshka 2022-10-13 15:08:47 -04:00
parent d5687d7b0e
commit 5463435fae
4 changed files with 89 additions and 19 deletions

View File

@ -205,8 +205,8 @@ func (analyzer *analysisOperation) resolvePrimitive (
case "U32": section = &PrimitiveU32 case "U32": section = &PrimitiveU32
case "U64": section = &PrimitiveU64 case "U64": section = &PrimitiveU64
case "Obj": section = &PrimitiveObj case "Obj": section = &PrimitiveObj
case "Face": section = &PrimitiveFace // case "Face": section = &PrimitiveFace
case "Func": section = &PrimitiveFunc // case "Func": section = &PrimitiveFunc
case "String": section = &BuiltInString case "String": section = &BuiltInString
default: default:
exists = false exists = false

View File

@ -160,6 +160,8 @@ func (literal StringLiteral) canBePassedAs (what Type) (allowed bool) {
reduced, worked := what.reduce() reduced, worked := what.reduce()
if worked { if worked {
// if the type was reduced to a non-basic type, only pass to
// singular dynamic arrays.
if !what.isSingular() { return } if !what.isSingular() { return }
if reduced.kind != TypeKindVariableArray { return } if reduced.kind != TypeKindVariableArray { return }
what = reduced what = reduced

View File

@ -83,15 +83,20 @@ func (section TypeSection) Member (
} }
if !exists { if !exists {
actual := section.what.actual if section.what.actual == nil { return }
if actual == nil { return }
actual, isTypeSection := section.what.actual.(*TypeSection)
if !isTypeSection { return }
member, exists = actual.Member(name) member, exists = actual.Member(name)
} }
case TypeKindPointer: case TypeKindPointer:
points := section.what.points points := section.what.points
if points == nil { return } if points == nil { return }
member, exists = points.actual.Member(name)
actual, isTypeSection := points.actual.(*TypeSection)
if !isTypeSection { return }
member, exists = actual.Member(name)
} }
return return
@ -164,7 +169,7 @@ func (analyzer *analysisOperation) analyzeObjectMembers (
) ( ) (
err error, err error,
) { ) {
inheritedSection := into.what.actual inheritedSection := into.what.actual.(*TypeSection)
inheritsFromSameModule := analyzer.inCurrentModule(inheritedSection) inheritsFromSameModule := analyzer.inCurrentModule(inheritedSection)
for index := 0; index < from.MembersLength(); index ++ { for index := 0; index < from.MembersLength(); index ++ {

View File

@ -107,11 +107,35 @@ func (what Type) underlyingPrimitive () (underlying *TypeSection) {
return return
case nil: case nil:
panic("invalid state: Type.actual is nil") panic (
"invalid state: Type.actual is nil for " +
what.Describe() + " " +
what.locatable.location.Describe())
default: default:
// if none of the primitives matched, recurse. // if none of the primitives matched, recurse.
underlying = actual.what.underlyingPrimitive() switch actual.(type) {
case *TypeSection:
underlying =
actual.(*TypeSection).
what.underlyingPrimitive()
// TODO
// case *FaceSection:
// TODO: depending on if this is an object interface or
// a function interface, return either Face or Func.
// we can assume this because of inheritence rules.
// // case *EnumSection:
// underlying =
// actual.(*EnumSection).
// what.underlyingPrimitive()
default:
panic (
"invalid state: type " + what.Describe() +
"has illegal actual " +
what.locatable.location.Describe())
}
return return
} }
} }
@ -137,7 +161,23 @@ func (what Type) isSingular () (singular bool) {
if actual == nil { if actual == nil {
return return
} else { } else {
singular = actual.what.isSingular() switch actual.(type) {
case *TypeSection:
singular = actual.(*TypeSection).what.isSingular()
// TODO: uncomment this when these sections have been
// implemented
// case *FaceSection:
// singular = true
// case *EnumSection:
// singular = actual.(*EnumSection).what.isSingular()
default:
panic (
"invalid state: type " + what.Describe() +
"has illegal actual " +
what.locatable.location.Describe())
}
} }
return return
} }
@ -163,7 +203,25 @@ func (what Type) reduce () (reduced Type, reducible bool) {
} }
// otherwise, recurse // otherwise, recurse
reduced, reducible = what.actual.what.reduce() switch what.actual.(type) {
case *TypeSection:
reduced, reducible = what.actual.(*TypeSection).what.reduce()
// TODO: uncomment this when these sections have been
// implemented
// case *FaceSection:
// singular = true
// case *EnumSection:
// reduced, reducible = what.actual.(*EnumSection).what.reduce()
default:
panic (
"invalid state: type " + what.Describe() +
"has illegal actual " +
what.locatable.location.Describe())
}
return return
} }
@ -208,11 +266,16 @@ func (analyzer analysisOperation) analyzeType (
return return
} }
var worked bool actualIsValidSectionKind := false
outputType.actual, worked = actual.(*TypeSection) switch actual.(type) {
if !worked { // TODO: uncomment once these sections are implemented
case *TypeSection /* , *EnumSection, *FaceSection */:
actualIsValidSectionKind = true
}
if !actualIsValidSectionKind {
err = inputType.NewError ( err = inputType.NewError (
"this must refer to a type or an interface", "this must refer to a type, interface, or enum",
infoerr.ErrorKindError) infoerr.ErrorKindError)
return return
} }
@ -246,10 +309,6 @@ func (what Type) Describe () (description string) {
description += "F32" description += "F32"
case &PrimitiveF64: case &PrimitiveF64:
description += "F64" description += "F64"
case &PrimitiveFunc:
description += "Func"
case &PrimitiveFace:
description += "Face"
case &PrimitiveObj: case &PrimitiveObj:
description += "Obj" description += "Obj"
case &PrimitiveU64: case &PrimitiveU64:
@ -272,11 +331,15 @@ func (what Type) Describe () (description string) {
description += "UInt" description += "UInt"
case &PrimitiveInt: case &PrimitiveInt:
description += "Int" description += "Int"
// case &PrimitiveFunc:
// description += "Func"
// case &PrimitiveFace:
// description += "Face"
case &BuiltInString: case &BuiltInString:
description += "String" description += "String"
case nil: case nil:
panic("invalid state: Type.actual is nil") description += "NIL-TYPE-ACTUAL"
default: default:
description += actual.ModuleName() + "." + actual.Name() description += actual.ModuleName() + "." + actual.Name()