Rename IDDiamond to IDDagger1 and IDDagger2

This commit is contained in:
Nigel Tao committed 2018-05-18 13:15:39 +10:00
1 parent e4320c3c6d
commit 6e06d1f9f1
5 files changed
+70 -49

No files matched your search

+15 -13
View File
@@ -157,25 +157,27 @@ var Funcs = []string{
"status.is_suspension()(ret bool)", "status.is_suspension()(ret bool)",
} }
// The "T" types here are placeholders for generic "slice U" or "table U" // The "T1" and "T2" types here are placeholders for generic "slice T" or
// types. After tokenizing (but before parsing) these XxxFunc strings (e.g. in // "table T" types. After tokenizing (but before parsing) these XxxFunc strings
// the lang/check package), replace the "T" receiver type with the "◊" diamond, // (e.g. in the lang/check package), replace "T1" and "T2" with "†" or "‡"
// to avoid collision with a user-defined "T" type. // daggers, to avoid collision with a user-defined "T1" or "T2" type.
const ( const (
GenericOldName = t.IDCapitalT GenericOldName1 = t.IDT1
GenericNewName = t.IDDiamond GenericOldName2 = t.IDT2
GenericNewName1 = t.IDDagger1
GenericNewName2 = t.IDDagger2
) )
var SliceFuncs = []string{ var SliceFuncs = []string{
"T.copy_from_slice(s T)(ret u64)", "T1.copy_from_slice(s T1)(ret u64)",
"T.length()(ret u64)", "T1.length()(ret u64)",
"T.prefix(up_to u64)(ret T)", "T1.prefix(up_to u64)(ret T1)",
"T.suffix(up_to u64)(ret T)", "T1.suffix(up_to u64)(ret T1)",
} }
var TableFuncs = []string{ var TableFuncs = []string{
"T.height()(ret u64)", "T2.height()(ret u64)",
"T.stride()(ret u64)", "T2.stride()(ret u64)",
"T.width()(ret u64)", "T2.width()(ret u64)",
} }
+1 -1
View File
@@ -499,7 +499,7 @@ func (c *Checker) checkFuncSignature(node *a.Node) error {
if qqid[0] == t.IDBase { if qqid[0] == t.IDBase {
// No need to populate c.funcs and c.localVars for built-in funcs. In // No need to populate c.funcs and c.localVars for built-in funcs. In
// any case, the remaining type checking code in this function doesn't // any case, the remaining type checking code in this function doesn't
// handle the base.◊ diamond type. // handle the base.† dagger type.
return nil return nil
} }
if other, ok := c.funcs[qqid]; ok { if other, ok := c.funcs[qqid]; ok {
+8 -5
View File
@@ -34,7 +34,8 @@ var (
// typeExprFoo is an *ast.Node MType (implicit type). // typeExprFoo is an *ast.Node MType (implicit type).
var ( var (
typeExprGeneric = a.NewTypeExpr(0, t.IDBase, t.IDDiamond, nil, nil, nil) typeExprGeneric1 = a.NewTypeExpr(0, t.IDBase, t.IDDagger1, nil, nil, nil)
typeExprGeneric2 = a.NewTypeExpr(0, t.IDBase, t.IDDagger2, nil, nil, nil)
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)
typeExprPlaceholder = a.NewTypeExpr(0, t.IDBase, t.IDPilcrow, nil, nil, nil) typeExprPlaceholder = a.NewTypeExpr(0, t.IDBase, t.IDPilcrow, nil, nil, nil)
@@ -128,8 +129,10 @@ func (c *Checker) parseBuiltInFuncs(ss []string, generic bool) (map[t.QQID]*a.Fu
} }
if generic { if generic {
for i := range tokens { for i := range tokens {
if tokens[i].ID == builtin.GenericOldName { if tokens[i].ID == builtin.GenericOldName1 {
tokens[i].ID = builtin.GenericNewName tokens[i].ID = builtin.GenericNewName1
} else if tokens[i].ID == builtin.GenericOldName2 {
tokens[i].ID = builtin.GenericNewName2
} }
} }
} }
@@ -161,7 +164,7 @@ func (c *Checker) resolveFunc(typ *a.TypeExpr) (*a.Func, error) {
qqid := t.QQID{lQID[0], lQID[1], typ.FuncName()} qqid := t.QQID{lQID[0], lQID[1], typ.FuncName()}
if lTyp.IsSliceType() { if lTyp.IsSliceType() {
qqid[0] = t.IDBase qqid[0] = t.IDBase
qqid[1] = t.IDDiamond qqid[1] = t.IDDagger1
if f, err := c.builtInSliceFunc(qqid); err != nil { if f, err := c.builtInSliceFunc(qqid); err != nil {
return nil, err return nil, err
} else if f != nil { } else if f != nil {
@@ -170,7 +173,7 @@ func (c *Checker) resolveFunc(typ *a.TypeExpr) (*a.Func, error) {
} else if lTyp.IsTableType() { } else if lTyp.IsTableType() {
qqid[0] = t.IDBase qqid[0] = t.IDBase
qqid[1] = t.IDDiamond qqid[1] = t.IDDagger2
if f, err := c.builtInTableFunc(qqid); err != nil { if f, err := c.builtInTableFunc(qqid); err != nil {
return nil, err return nil, err
} else if f != nil { } else if f != nil {
+21 -12
View File
@@ -321,7 +321,7 @@ func (q *checker) tcheckAssign(n *a.Assign) error {
) )
} }
func (q *checker) tcheckArg(n *a.Arg, inField *a.Field, genericType *a.TypeExpr, depth uint32) error { func (q *checker) tcheckArg(n *a.Arg, inField *a.Field, genericType1 *a.TypeExpr, genericType2 *a.TypeExpr, depth uint32) error {
if err := q.tcheckExpr(n.Value(), depth); err != nil { if err := q.tcheckExpr(n.Value(), depth); err != nil {
return err return err
} }
@@ -336,8 +336,10 @@ func (q *checker) tcheckArg(n *a.Arg, inField *a.Field, genericType *a.TypeExpr,
return fmt.Errorf("check: argument name: got %q, want %q", n.Name().Str(q.tm), inField.Name().Str(q.tm)) return fmt.Errorf("check: argument name: got %q, want %q", n.Name().Str(q.tm), inField.Name().Str(q.tm))
} }
inFieldTyp := inField.XType() inFieldTyp := inField.XType()
if genericType != nil && inFieldTyp.Eq(typeExprGeneric) { if genericType1 != nil && inFieldTyp.Eq(typeExprGeneric1) {
inFieldTyp = genericType inFieldTyp = genericType1
} else if genericType2 != nil && inFieldTyp.Eq(typeExprGeneric2) {
inFieldTyp = genericType2
} }
if err := q.tcheckEq(inField.Name(), nil, inFieldTyp, n.Value(), n.Value().MType()); err != nil { if err := q.tcheckEq(inField.Name(), nil, inFieldTyp, n.Value(), n.Value().MType()); err != nil {
return err return err
@@ -551,9 +553,14 @@ func (q *checker) tcheckExprCall(n *a.Expr, depth uint32) error {
n.Str(q.tm), ne, f.QQID().Str(q.tm), fe) n.Str(q.tm), ne, f.QQID().Str(q.tm), fe)
} }
genericType := (*a.TypeExpr)(nil) genericType1 := (*a.TypeExpr)(nil)
if f.Receiver() == (t.QID{t.IDBase, t.IDDiamond}) { genericType2 := (*a.TypeExpr)(nil)
genericType = lhs.MType().Receiver() switch f.Receiver() {
case t.QID{t.IDBase, t.IDDagger1}:
genericType1 = lhs.MType().Receiver()
case t.QID{t.IDBase, t.IDDagger2}:
genericType1 = lhs.MType().Receiver() // TODO: convert table T to slice T.
genericType2 = lhs.MType().Receiver()
} }
// Check that the func's in type matches the arguments. // Check that the func's in type matches the arguments.
@@ -565,7 +572,7 @@ func (q *checker) tcheckExprCall(n *a.Expr, depth uint32) error {
for i, o := range n.Args() { for i, o := range n.Args() {
// TODO: inline tcheckArg here, after removing the special-cased hacks // TODO: inline tcheckArg here, after removing the special-cased hacks
// in tcheckExprOther. // in tcheckExprOther.
if err := q.tcheckArg(o.Arg(), inFields[i].Field(), genericType, depth); err != nil { if err := q.tcheckArg(o.Arg(), inFields[i].Field(), genericType1, genericType2, depth); err != nil {
return err return err
} }
} }
@@ -587,8 +594,10 @@ func (q *checker) tcheckExprCall(n *a.Expr, depth uint32) error {
n.SetMType(typeExprEmptyStruct) n.SetMType(typeExprEmptyStruct)
case 1: case 1:
oTyp := outFields[0].Field().XType() oTyp := outFields[0].Field().XType()
if genericType != nil && oTyp.Eq(typeExprGeneric) { if genericType1 != nil && oTyp.Eq(typeExprGeneric1) {
n.SetMType(genericType) n.SetMType(genericType1)
} else if genericType2 != nil && oTyp.Eq(typeExprGeneric2) {
n.SetMType(genericType2)
} else { } else {
n.SetMType(oTyp) n.SetMType(oTyp)
} }
@@ -608,7 +617,7 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
if lTyp.IsSliceType() { if lTyp.IsSliceType() {
qqid[0] = t.IDBase qqid[0] = t.IDBase
qqid[1] = t.IDDiamond qqid[1] = t.IDDagger1
if f, err := q.c.builtInSliceFunc(qqid); err != nil { if f, err := q.c.builtInSliceFunc(qqid); err != nil {
return err return err
} else if f == nil { } else if f == nil {
@@ -619,7 +628,7 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
} else if lTyp.IsTableType() { } else if lTyp.IsTableType() {
qqid[0] = t.IDBase qqid[0] = t.IDBase
qqid[1] = t.IDDiamond qqid[1] = t.IDDagger2
if f, err := q.c.builtInTableFunc(qqid); err != nil { if f, err := q.c.builtInTableFunc(qqid); err != nil {
return err return err
} else if f == nil { } else if f == nil {
@@ -976,7 +985,7 @@ swtch:
// TODO: reject. You can only refine numeric types. // TODO: reject. You can only refine numeric types.
} }
if qid[0] == t.IDBase { if qid[0] == t.IDBase {
if _, ok := builtInTypeMap[qid[1]]; ok || qid[1] == t.IDDiamond { if _, ok := builtInTypeMap[qid[1]]; ok || qid[1] == t.IDDagger1 || qid[1] == t.IDDagger2 {
break swtch break swtch
} }
} }
+25 -18
View File
@@ -397,15 +397,19 @@ const (
IDEmptyStruct = ID(0x100) IDEmptyStruct = ID(0x100)
IDBool = ID(0x101) IDBool = ID(0x101)
IDStatus = ID(0x102)
IDIOReader = ID(0x103)
IDIOWriter = ID(0x104)
IDCapitalT = ID(0x105)
IDImageBuffer = ID(0x106)
IDImageConfig = ID(0x107)
IDPilcrow = ID(0x10D) IDImageBuffer = ID(0x102)
IDDiamond = ID(0x10E) IDImageConfig = ID(0x103)
IDIOReader = ID(0x104)
IDIOWriter = ID(0x105)
IDStatus = ID(0x106)
IDT1 = ID(0x10A)
IDT2 = ID(0x10B)
IDDagger1 = ID(0x10C)
IDDagger2 = ID(0x10D)
IDPilcrow = ID(0x10E)
// It is important that IDDoubleZ is right next to the IDI8..IDU64 block. // It is important that IDDoubleZ is right next to the IDI8..IDU64 block.
// See the ID.IsNumTypeOrIdeal method. // See the ID.IsNumTypeOrIdeal method.
@@ -588,28 +592,31 @@ var builtInsByID = [nBuiltInIDs]string{
IDEmptyStruct: "empty_struct", IDEmptyStruct: "empty_struct",
IDBool: "bool", IDBool: "bool",
IDStatus: "status",
IDIOReader: "io_reader",
IDIOWriter: "io_writer",
IDCapitalT: "T",
IDImageBuffer: "image_buffer", IDImageBuffer: "image_buffer",
IDImageConfig: "image_config", IDImageConfig: "image_config",
IDIOReader: "io_reader",
IDIOWriter: "io_writer",
IDStatus: "status",
// The next few IDs are never returned by the tokenizer, as it rejects // Some of the next few IDs are never returned by the tokenizer, as it
// non-ASCII input. The string representations "¶", "◊" and "ℤ" are // rejects non-ASCII input. The string representations "¶", "ℤ" etc. are
// specifically non-ASCII so that no user-defined (non built-in) identifier // specifically non-ASCII so that no user-defined (non built-in) identifier
// will conflict with them. // will conflict with them.
// IDDaggerN is used by the type checker as a dummy-valued built-in ID to
// represent a generic type.
IDT1: "T1",
IDT2: "T2",
IDDagger1: "†", // U+2020 DAGGER
IDDagger2: "‡", // U+2021 DOUBLE DAGGER
// IDPilcrow is used by the type checker to build a placeholder MType for // IDPilcrow is used by the type checker to build a placeholder MType for
// AST nodes that aren't expression nodes, such as struct definition nodes // AST nodes that aren't expression nodes, such as struct definition nodes
// and statement nodes. Its presence means that the non-expression node is // and statement nodes. Its presence means that the non-expression node is
// type checked. // type checked.
IDPilcrow: "¶", // U+00B6 PILCROW SIGN IDPilcrow: "¶", // U+00B6 PILCROW SIGN
// IDDiamond is used by the type checker as a dummy-valued built-in ID to
// represent a generic type.
IDDiamond: "◊", // U+25C7 WHITE DIAMOND
// IDDoubleZ is used by the type checker as a dummy-valued built-in ID to // IDDoubleZ is used by the type checker as a dummy-valued built-in ID to
// represent an ideal integer type (in mathematical terms, the integer ring // represent an ideal integer type (in mathematical terms, the integer ring
// ℤ), as opposed to a realized integer type whose range is restricted. For // ℤ), as opposed to a realized integer type whose range is restricted. For