mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 00:52:18 +01:00
Add a TypeExpr type expression
This commit is contained in:
1 parent
295cbbccae
commit
731ca8841b
5 files changed
+39
-29
No files matched your search
+1
-1
@@ -716,7 +716,7 @@ func (n *TypeExpr) IsBool() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (n *TypeExpr) IsIdeal() bool {
|
func (n *TypeExpr) IsIdeal() bool {
|
||||||
return n.id0 == 0 && n.id1 == t.IDBase && n.id2 == t.IDDoubleZ
|
return n.id0 == 0 && n.id1 == t.IDBase && n.id2 == t.IDQIdeal
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *TypeExpr) IsIOType() bool {
|
func (n *TypeExpr) IsIOType() bool {
|
||||||
|
|||||||
+12
-8
@@ -682,17 +682,21 @@ func allTypeChecked(tm *t.Map, n *a.Node) error {
|
|||||||
return fmt.Errorf("check: internal error: unchecked %s", nodeDebugString(tm, o))
|
return fmt.Errorf("check: internal error: unchecked %s", nodeDebugString(tm, o))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typOK := false
|
||||||
switch o.Kind() {
|
switch o.Kind() {
|
||||||
default:
|
|
||||||
if typ != typeExprPlaceholder {
|
|
||||||
return fmt.Errorf("check: internal error: %s does not have placeholder type", nodeDebugString(tm, o))
|
|
||||||
}
|
|
||||||
|
|
||||||
case a.KExpr:
|
case a.KExpr:
|
||||||
if typ == typeExprPlaceholder {
|
typOK = typ != typeExprPlaceholder && typ != typeExprTypeExpr
|
||||||
return fmt.Errorf("check: internal error: %s has placeholder type", nodeDebugString(tm, o))
|
case a.KTypeExpr:
|
||||||
}
|
typOK = typ == typeExprTypeExpr
|
||||||
|
default:
|
||||||
|
typOK = typ == typeExprPlaceholder
|
||||||
|
}
|
||||||
|
if !typOK {
|
||||||
|
return fmt.Errorf("check: internal error: %s has incorrect type, %s",
|
||||||
|
nodeDebugString(tm, o), typ.Str(tm))
|
||||||
|
}
|
||||||
|
|
||||||
|
if o.Kind() == a.KExpr {
|
||||||
o := o.AsExpr()
|
o := o.AsExpr()
|
||||||
if typ.IsIdeal() && o.ConstValue() == nil {
|
if typ.IsIdeal() && o.ConstValue() == nil {
|
||||||
return fmt.Errorf("check: internal error: expression %q has ideal number type "+
|
return fmt.Errorf("check: internal error: expression %q has ideal number type "+
|
||||||
|
|||||||
@@ -36,9 +36,10 @@ var (
|
|||||||
var (
|
var (
|
||||||
typeExprGeneric1 = a.NewTypeExpr(0, t.IDBase, t.IDDagger1, 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)
|
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.IDQIdeal, 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.IDQPlaceholder, nil, nil, nil)
|
||||||
|
typeExprTypeExpr = a.NewTypeExpr(0, t.IDBase, t.IDQTypeExpr, 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)
|
||||||
|
|||||||
+1
-1
@@ -1001,7 +1001,7 @@ swtch:
|
|||||||
default:
|
default:
|
||||||
return fmt.Errorf("check: %q is not a type", typ.Str(q.tm))
|
return fmt.Errorf("check: %q is not a type", typ.Str(q.tm))
|
||||||
}
|
}
|
||||||
setPlaceholderMBoundsMType(typ.AsNode())
|
typ.AsNode().SetMType(typeExprTypeExpr)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+22
-17
@@ -416,16 +416,17 @@ const (
|
|||||||
IDIOWriter = ID(0x113)
|
IDIOWriter = ID(0x113)
|
||||||
IDStatus = ID(0x114)
|
IDStatus = ID(0x114)
|
||||||
|
|
||||||
IDT1 = ID(0x11A)
|
IDT1 = ID(0x118)
|
||||||
IDT2 = ID(0x11B)
|
IDT2 = ID(0x119)
|
||||||
IDDagger1 = ID(0x11C)
|
IDDagger1 = ID(0x11A)
|
||||||
IDDagger2 = ID(0x11D)
|
IDDagger2 = ID(0x11B)
|
||||||
|
|
||||||
IDPilcrow = ID(0x11E)
|
IDQPlaceholder = ID(0x11D)
|
||||||
|
IDQTypeExpr = ID(0x11E)
|
||||||
|
|
||||||
// It is important that IDDoubleZ is right next to the IDI8..IDU64 block.
|
// It is important that IDQIdeal is right next to the IDI8..IDU64 block.
|
||||||
// See the ID.IsNumTypeOrIdeal method.
|
// See the ID.IsNumTypeOrIdeal method.
|
||||||
IDDoubleZ = ID(0x11F)
|
IDQIdeal = ID(0x11F)
|
||||||
|
|
||||||
IDI8 = ID(0x120)
|
IDI8 = ID(0x120)
|
||||||
IDI16 = ID(0x121)
|
IDI16 = ID(0x121)
|
||||||
@@ -675,17 +676,21 @@ var builtInsByID = [nBuiltInIDs]string{
|
|||||||
IDDagger1: "†", // U+2020 DAGGER
|
IDDagger1: "†", // U+2020 DAGGER
|
||||||
IDDagger2: "‡", // U+2021 DOUBLE DAGGER
|
IDDagger2: "‡", // U+2021 DOUBLE DAGGER
|
||||||
|
|
||||||
// IDPilcrow is used by the type checker to build a placeholder MType for
|
// IDQPlaceholder is used by the type checker to build an artificial MType
|
||||||
// AST nodes that aren't expression nodes, such as struct definition nodes
|
// for AST nodes that aren't expression nodes or type expression nodes,
|
||||||
// and statement nodes. Its presence means that the non-expression node is
|
// such as struct definition nodes and statement nodes. Its presence means
|
||||||
// type checked.
|
// that the node is type checked.
|
||||||
IDPilcrow: "¶", // U+00B6 PILCROW SIGN
|
IDQPlaceholder: "«Placeholder»",
|
||||||
|
|
||||||
// IDDoubleZ is used by the type checker as a dummy-valued built-in ID to
|
// IDQTypeExpr is used by the type checker to build an artificial MType for
|
||||||
// represent an ideal integer type (in mathematical terms, the integer ring
|
// type expression AST nodes.
|
||||||
// ℤ), as opposed to a realized integer type whose range is restricted. For
|
IDQTypeExpr: "«TypeExpr»",
|
||||||
// example, the base.u16 type is restricted to [0x0000, 0xFFFF].
|
|
||||||
IDDoubleZ: "ℤ", // U+2124 DOUBLE-STRUCK CAPITAL Z
|
// IDQIdeal is used by the type checker to build an artificial MType for
|
||||||
|
// ideal integers (in mathematical terms, the integer ring ℤ), as opposed
|
||||||
|
// to a realized integer type whose range is restricted. For example, the
|
||||||
|
// base.u16 type is restricted to [0x0000, 0xFFFF].
|
||||||
|
IDQIdeal: "«Ideal»",
|
||||||
|
|
||||||
// Change MaxIntBits if a future update adds an i128 or u128 type.
|
// Change MaxIntBits if a future update adds an i128 or u128 type.
|
||||||
IDI8: "i8",
|
IDI8: "i8",
|
||||||
|
|||||||
Reference in new issue
Block a user