fspl/analyzer/builtin.go

52 lines
2.2 KiB
Go

package analyzer
import "git.tebibyte.media/fspl/fspl/entity"
var primitiveTypes = map[string] entity.Type {
"Int": &entity.TypeWord { Acc: entity.AccessPublic, Signed: true },
"UInt": &entity.TypeWord { Acc: entity.AccessPublic, },
"I8": &entity.TypeInt { Acc: entity.AccessPublic, Signed: true, Width: 8 },
"I16": &entity.TypeInt { Acc: entity.AccessPublic, Signed: true, Width: 16 },
"I32": &entity.TypeInt { Acc: entity.AccessPublic, Signed: true, Width: 32 },
"I64": &entity.TypeInt { Acc: entity.AccessPublic, Signed: true, Width: 64 },
"U8": &entity.TypeInt { Acc: entity.AccessPublic, Signed: false, Width: 8 },
"U16": &entity.TypeInt { Acc: entity.AccessPublic, Signed: false, Width: 16 },
"U32": &entity.TypeInt { Acc: entity.AccessPublic, Signed: false, Width: 32 },
"U64": &entity.TypeInt { Acc: entity.AccessPublic, Signed: false, Width: 64 },
"F32": &entity.TypeFloat { Acc: entity.AccessPublic, Width: 32 },
"F64": &entity.TypeFloat { Acc: entity.AccessPublic, Width: 64 },
}
var builtinTypes = map[string] entity.Type { }
func builtinType (name string) *entity.TypeNamed {
ty, ok := builtinTypes[name]
if !ok { panic("BUG: compiler tried to reference missing builtin " + name) }
return &entity.TypeNamed {
Name: name,
Type: ty,
Acc: entity.AccessPublic,
}
}
func primitiveType (name string) *entity.TypeNamed {
ty, ok := primitiveTypes[name]
if !ok { panic("BUG: compiler tried to reference missing primitive " + name) }
return &entity.TypeNamed {
Name: name,
Type: ty,
Acc: entity.AccessPublic,
}
}
func init () {
builtinTypes["Index"] = &entity.TypeWord { Acc: entity.AccessPublic }
builtinTypes["Byte"] = &entity.TypeInt { Acc: entity.AccessPublic, Signed: false, Width: 8 }
builtinTypes["Bool"] = &entity.TypeInt { Acc: entity.AccessPublic, Signed: false, Width: 1 }
builtinTypes["Rune"] = &entity.TypeInt { Acc: entity.AccessPublic, Signed: false, Width: 32 }
builtinTypes["String"] = &entity.TypeSlice {
Acc: entity.AccessPublic,
Element: &entity.TypeInt { Acc: entity.AccessPublic, Signed: false, Width: 8 },
}
}