implement-modules #43
@ -53,33 +53,6 @@ func (this *Tree) assembleRawMaps () error {
|
||||
return nil
|
||||
}
|
||||
|
||||
var primitiveTypes = map[string] struct { } {
|
||||
"Int": struct { } { },
|
||||
"UInt": struct { } { },
|
||||
"I8": struct { } { },
|
||||
"I16": struct { } { },
|
||||
"I32": struct { } { },
|
||||
"I64": struct { } { },
|
||||
"U8": struct { } { },
|
||||
"U16": struct { } { },
|
||||
"U32": struct { } { },
|
||||
"U64": struct { } { },
|
||||
"F32": struct { } { },
|
||||
"F64": struct { } { },
|
||||
}
|
||||
|
||||
var builtinTypes = map[string] struct { } {
|
||||
"Byte": struct { } { },
|
||||
"Bool": struct { } { },
|
||||
"Rune": struct { } { },
|
||||
"String": struct { } { },
|
||||
}
|
||||
|
||||
var builtinConsts = map[string] struct { } {
|
||||
"true": struct { } { },
|
||||
"false": struct { } { },
|
||||
}
|
||||
|
||||
func (this *Tree) topLevelNameAvailable (currentPos lexer.Position, name string) error {
|
||||
if _, isPrimitive := primitiveTypes[name]; isPrimitive {
|
||||
return participle.Errorf (
|
||||
@ -136,13 +109,8 @@ func (this *Tree) ensure () {
|
||||
}
|
||||
|
||||
func (this *Tree) generateBuiltinTypes () {
|
||||
this.Types["Byte"] = &entity.TypeInt { Signed: false, Width: 8 }
|
||||
this.Types["Bool"] = &entity.TypeInt { Signed: false, Width: 8 }
|
||||
this.Types["Rune"] = &entity.TypeInt { Signed: false, Width: 32 }
|
||||
this.Types["String"] = &entity.TypeSlice {
|
||||
Element: &entity.TypeNamed {
|
||||
Name: "Byte",
|
||||
Type: this.Types["Byte"],
|
||||
},
|
||||
|
||||
for name, ty := range builtinTypes {
|
||||
this.Types[name] = ty
|
||||
}
|
||||
}
|
||||
|
@ -74,24 +74,13 @@ func (this *Tree) analyzeType (ty entity.Type) (entity.Type, error) {
|
||||
}
|
||||
|
||||
func (this *Tree) analyzeTypeNamed (ty *entity.TypeNamed) (entity.Type, error) {
|
||||
switch ty.Name {
|
||||
case "Int": return &entity.TypeWord { Signed: true }, nil
|
||||
case "UInt": return &entity.TypeWord { }, nil
|
||||
case "I8": return &entity.TypeInt { Signed: true, Width: 8 }, nil
|
||||
case "I16": return &entity.TypeInt { Signed: true, Width: 16 }, nil
|
||||
case "I32": return &entity.TypeInt { Signed: true, Width: 32 }, nil
|
||||
case "I64": return &entity.TypeInt { Signed: true, Width: 64 }, nil
|
||||
case "U8": return &entity.TypeInt { Signed: false, Width: 8 }, nil
|
||||
case "U16": return &entity.TypeInt { Signed: false, Width: 16 }, nil
|
||||
case "U32": return &entity.TypeInt { Signed: false, Width: 32 }, nil
|
||||
case "U64": return &entity.TypeInt { Signed: false, Width: 64 }, nil
|
||||
case "F32": return &entity.TypeFloat { Width: 32 }, nil
|
||||
case "F64": return &entity.TypeFloat { Width: 32 }, nil
|
||||
default:
|
||||
var err error
|
||||
ty.Type, err = this.analyzeTypedef(ty.Pos, ty.Name)
|
||||
return ty, err
|
||||
if primitive, isPrimitive := primitiveTypes[ty.Name]; isPrimitive {
|
||||
return primitive, nil
|
||||
}
|
||||
|
||||
var err error
|
||||
ty.Type, err = this.analyzeTypedef(ty.Pos, ty.Name)
|
||||
return ty, err
|
||||
}
|
||||
|
||||
func (this *Tree) assembleStructMap (ty *entity.TypeStruct) (*entity.TypeStruct, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user