Remove typeExprPlaceholder

This commit is contained in:
Nigel Tao committed 2018-04-20 17:16:23 +10:00
1 parent ba0db5b4d1
commit c479907bff
4 files changed
+23 -24

No files matched your search

+2
View File
@@ -69,6 +69,8 @@ var Types = []string{
"u16", "u16",
"u32", "u32",
"u64", "u64",
"empty_struct",
"bool", "bool",
"status", "status",
"io_reader", "io_reader",
+6 -9
View File
@@ -38,10 +38,12 @@ var (
typeExprIdeal = a.NewTypeExpr(0, t.IDBase, t.IDDoubleZ, nil, nil, nil) typeExprIdeal = a.NewTypeExpr(0, t.IDBase, t.IDDoubleZ, nil, nil, nil)
typeExprList = a.NewTypeExpr(0, t.IDBase, t.IDDollar, nil, nil, nil) typeExprList = a.NewTypeExpr(0, t.IDBase, t.IDDollar, nil, nil, nil)
typeExprU8 = a.NewTypeExpr(0, t.IDBase, t.IDU8, nil, nil, nil) typeExprU8 = a.NewTypeExpr(0, t.IDBase, t.IDU8, nil, nil, nil)
typeExprU16 = a.NewTypeExpr(0, t.IDBase, t.IDU16, nil, nil, nil) typeExprU16 = a.NewTypeExpr(0, t.IDBase, t.IDU16, nil, nil, nil)
typeExprU32 = a.NewTypeExpr(0, t.IDBase, t.IDU32, nil, nil, nil) typeExprU32 = a.NewTypeExpr(0, t.IDBase, t.IDU32, nil, nil, nil)
typeExprU64 = a.NewTypeExpr(0, t.IDBase, t.IDU64, nil, nil, nil) typeExprU64 = a.NewTypeExpr(0, t.IDBase, t.IDU64, nil, nil, nil)
typeExprEmptyStruct = a.NewTypeExpr(0, t.IDBase, t.IDEmptyStruct, nil, nil, nil)
typeExprBool = a.NewTypeExpr(0, t.IDBase, t.IDBool, nil, nil, nil) typeExprBool = a.NewTypeExpr(0, t.IDBase, t.IDBool, nil, nil, nil)
typeExprStatus = a.NewTypeExpr(0, t.IDBase, t.IDStatus, nil, nil, nil) typeExprStatus = a.NewTypeExpr(0, t.IDBase, t.IDStatus, nil, nil, nil)
typeExprIOReader = a.NewTypeExpr(0, t.IDBase, t.IDIOReader, nil, nil, nil) typeExprIOReader = a.NewTypeExpr(0, t.IDBase, t.IDIOReader, nil, nil, nil)
@@ -49,11 +51,6 @@ var (
typeExprImageConfig = a.NewTypeExpr(0, t.IDBase, t.IDImageConfig, nil, nil, nil) typeExprImageConfig = a.NewTypeExpr(0, t.IDBase, t.IDImageConfig, nil, nil, nil)
typeExprSliceU8 = a.NewTypeExpr(t.IDSlice, 0, 0, nil, nil, typeExprU8) typeExprSliceU8 = a.NewTypeExpr(t.IDSlice, 0, 0, nil, nil, typeExprU8)
// TODO: delete this.
typeExprPlaceholder = a.NewTypeExpr(0, t.IDBase, t.IDU8, nil, nil, nil)
typeExprPlaceholder16 = a.NewTypeExpr(0, t.IDBase, t.IDU16, nil, nil, nil)
typeExprPlaceholder32 = a.NewTypeExpr(0, t.IDBase, t.IDU32, nil, nil, nil)
) )
// typeMap maps from variable names (as token IDs) to types. // typeMap maps from variable names (as token IDs) to types.
+7 -9
View File
@@ -429,24 +429,23 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
// require a TypeExpr being able to express function and method types. // require a TypeExpr being able to express function and method types.
// TODO: delete this hack that only matches "foo.decode(etc)". // TODO: delete this hack that only matches "foo.decode(etc)".
if isThatMethod(q.tm, n, q.tm.ByName("decode"), 3) { if idDecode := q.tm.ByName("decode"); isThatMethod(q.tm, n, idDecode, 3) {
foo := n.LHS().Expr().LHS().Expr() foo := n.LHS().Expr().LHS().Expr()
if err := q.tcheckExpr(foo, depth); err != nil { if err := q.tcheckExpr(foo, depth); err != nil {
return err return err
} }
n.LHS().SetTypeChecked() n.LHS().SetTypeChecked()
n.LHS().Expr().SetMType(typeExprPlaceholder) // HACK. n.LHS().Expr().SetMType(a.NewTypeExpr(t.IDFunc, 0, idDecode, foo.MType().Node(), nil, nil))
for _, o := range n.Args() { for _, o := range n.Args() {
if err := q.tcheckArg(o.Arg(), nil, nil, depth); err != nil { if err := q.tcheckArg(o.Arg(), nil, nil, depth); err != nil {
return err return err
} }
} }
if n.Operator() == t.IDTry { if n.Operator() != t.IDTry {
// TODO: be more principled about inferring "try etc"'s type. return fmt.Errorf("TODO: foo.decode(etc) outside of a try statement")
n.SetMType(typeExprStatus)
} else {
n.SetMType(typeExprPlaceholder) // HACK.
} }
// TODO: be more principled about inferring "try etc"'s type.
n.SetMType(typeExprStatus)
return nil return nil
} }
@@ -600,8 +599,7 @@ func (q *checker) tcheckExprCall(n *a.Expr, depth uint32) error {
// *ast.Struct, to an *ast.TypeExpr we can pass to n.SetMType. // *ast.Struct, to an *ast.TypeExpr we can pass to n.SetMType.
return fmt.Errorf("TODO: translate an *ast.Struct to an *ast.TypeExpr") return fmt.Errorf("TODO: translate an *ast.Struct to an *ast.TypeExpr")
case 0: case 0:
// TODO: use a "unit", "void" or "empty struct" type. n.SetMType(typeExprEmptyStruct)
n.SetMType(typeExprPlaceholder)
case 1: case 1:
oTyp := outFields[0].Field().XType() oTyp := outFields[0].Field().XType()
if genericType != nil && oTyp.Eq(typeExprGeneric) { if genericType != nil && oTyp.Eq(typeExprGeneric) {
+8 -6
View File
@@ -366,11 +366,12 @@ const (
IDSLICE = ID(0xA6) IDSLICE = ID(0xA6)
IDBase = ID(0xA7) IDBase = ID(0xA7)
IDBool = ID(0xA8) IDEmptyStruct = ID(0xA8)
IDIOReader = ID(0xA9) IDBool = ID(0xA9)
IDIOWriter = ID(0xAA) IDStatus = ID(0xAA)
IDStatus = ID(0xAB) IDIOReader = ID(0xAB)
IDImageConfig = ID(0xAC) IDIOWriter = ID(0xAC)
IDImageConfig = ID(0xAD)
IDMark = ID(0xB0) IDMark = ID(0xB0)
IDReadU8 = ID(0xB1) IDReadU8 = ID(0xB1)
@@ -534,10 +535,11 @@ var builtInsByID = [nBuiltInIDs]string{
IDSLICE: "SLICE", IDSLICE: "SLICE",
IDBase: "base", IDBase: "base",
IDEmptyStruct: "empty_struct",
IDBool: "bool", IDBool: "bool",
IDStatus: "status",
IDIOReader: "io_reader", IDIOReader: "io_reader",
IDIOWriter: "io_writer", IDIOWriter: "io_writer",
IDStatus: "status",
IDImageConfig: "image_config", IDImageConfig: "image_config",
IDMark: "mark", IDMark: "mark",