Rename u32, io_reader, etc to base.u32, etc

This commit is contained in:
Nigel Tao committed 2018-04-12 21:49:17 +10:00
1 parent fee97df698
commit f95239f6e0
24 files changed
+394 -392

No files matched your search

+6 -6
View File
@@ -170,7 +170,7 @@ func invert(tm *t.Map, n *a.Expr) (*a.Expr, error) {
func typeBounds(tm *t.Map, typ *a.TypeExpr) (*big.Int, *big.Int, error) {
b := [2]*big.Int{}
if typ.Decorator() == 0 {
if qid := typ.QID(); qid[0] == 0 && qid[1].Key() < t.Key(len(numTypeBounds)) {
if qid := typ.QID(); qid[0] == t.IDBase && qid[1].Key() < t.Key(len(numTypeBounds)) {
b = numTypeBounds[qid[1].Key()]
}
}
@@ -827,8 +827,8 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
}
if aMin.Sign() < 0 {
// TODO: error, but a better check than aMin < 0 is that
// a.MType() is u32. Checking this properly should fall out
// when a *a.TypeExpr can express function types.
// a.MType() is base.u32. Checking this properly should fall
// out when a *a.TypeExpr can express function types.
}
// TODO: sixtyFour should actually be 8 * sizeof(n.LHS().Expr()).
if aMax.Cmp(sixtyFour) > 0 {
@@ -1145,7 +1145,7 @@ func (q *checker) bcheckExprBinaryOp1(op t.Key, lhs *a.Expr, lMin *big.Int, lMax
if typ.IsIdeal() {
typ = rhs.MType()
}
if qid := typ.QID(); qid[0] == 0 {
if qid := typ.QID(); qid[0] == t.IDBase {
b := numTypeBounds[qid[1].Key()]
return b[0], b[1], nil
}
@@ -1194,7 +1194,7 @@ func (q *checker) bcheckTypeExpr(typ *a.TypeExpr) (*big.Int, *big.Int, error) {
// TODO: is the special cases for io_reader and io_writer superfluous with
// the general purpose code for built-ins below?
if qid := typ.QID(); qid[0] == 0 {
if qid := typ.QID(); qid[0] == t.IDBase {
switch qid[1].Key() {
case t.KeyIOReader, t.KeyIOWriter:
return nil, nil, nil
@@ -1202,7 +1202,7 @@ func (q *checker) bcheckTypeExpr(typ *a.TypeExpr) (*big.Int, *big.Int, error) {
}
b := [2]*big.Int{}
if qid := typ.QID(); qid[0] == 0 && qid[1].Key() < t.Key(len(numTypeBounds)) {
if qid := typ.QID(); qid[0] == t.IDBase && qid[1].Key() < t.Key(len(numTypeBounds)) {
b = numTypeBounds[qid[1].Key()]
}
// TODO: should || be && instead (see also func typeBounds)? Is this if
+40 -40
View File
@@ -62,15 +62,15 @@ func TestCheck(tt *testing.T) {
packageid "test"
pri struct foo(
i i32,
i base.i32,
)
pri func foo.bar()() {
var x u8
var y i32 = +2
var z u64[..123]
var a array[4] u8
var b bool
var x base.u8
var y base.i32 = +2
var z base.u64[..123]
var a array[4] base.u8
var b base.bool
x = 0
x = 1 + (x * 0)
@@ -78,10 +78,10 @@ func TestCheck(tt *testing.T) {
y = this.i
b = not true
y = x as i32
y = x as base.i32
var p i32
var q i32[0..8]
var p base.i32
var q base.i32[0..8]
assert true
@@ -147,16 +147,16 @@ func TestCheck(tt *testing.T) {
})
want := [][2]string{
{"a", "array[4] u8"},
{"b", "bool"},
{"a", "array[4] base.u8"},
{"b", "base.bool"},
{"in", "in"},
{"out", "out"},
{"p", "i32"},
{"q", "i32[0..8]"},
{"p", "base.i32"},
{"q", "base.i32[0..8]"},
{"this", "ptr foo"},
{"x", "u8"},
{"y", "i32"},
{"z", "u64[..123]"},
{"x", "base.u8"},
{"y", "base.i32"},
{"z", "base.u64[..123]"},
}
if !reflect.DeepEqual(got, want) {
tt.Fatalf("\ngot %v\nwant %v", got, want)
@@ -166,35 +166,35 @@ func TestCheck(tt *testing.T) {
func TestConstValues(tt *testing.T) {
const filename = "test.wuffs"
testCases := map[string]int64{
"var i i32 = 42": 42,
"var i base.i32 = 42": 42,
"var i i32 = +7": +7,
"var i i32 = -7": -7,
"var i base.i32 = +7": +7,
"var i base.i32 = -7": -7,
"var b bool = false": 0,
"var b bool = not false": 1,
"var b bool = not not false": 0,
"var b base.bool = false": 0,
"var b base.bool = not false": 1,
"var b base.bool = not not false": 0,
"var i i32 = 10 + 3": 13,
"var i i32 = 10 - 3": 7,
"var i i32 = 10 * 3": 30,
"var i i32 = 10 / 3": 3,
"var i i32 = 10 << 3": 80,
"var i i32 = 10 >> 3": 1,
"var i i32 = 10 & 3": 2,
"var i i32 = 10 &^ 3": 8,
"var i i32 = 10 | 3": 11,
"var i i32 = 10 ^ 3": 9,
"var i base.i32 = 10 + 3": 13,
"var i base.i32 = 10 - 3": 7,
"var i base.i32 = 10 * 3": 30,
"var i base.i32 = 10 / 3": 3,
"var i base.i32 = 10 << 3": 80,
"var i base.i32 = 10 >> 3": 1,
"var i base.i32 = 10 & 3": 2,
"var i base.i32 = 10 &^ 3": 8,
"var i base.i32 = 10 | 3": 11,
"var i base.i32 = 10 ^ 3": 9,
"var b bool = 10 != 3": 1,
"var b bool = 10 < 3": 0,
"var b bool = 10 <= 3": 0,
"var b bool = 10 == 3": 0,
"var b bool = 10 >= 3": 1,
"var b bool = 10 > 3": 1,
"var b base.bool = 10 != 3": 1,
"var b base.bool = 10 < 3": 0,
"var b base.bool = 10 <= 3": 0,
"var b base.bool = 10 == 3": 0,
"var b base.bool = 10 >= 3": 1,
"var b base.bool = 10 > 3": 1,
"var b bool = false and true": 0,
"var b bool = false or true": 1,
"var b base.bool = false and true": 0,
"var b base.bool = false or true": 1,
}
tm := &t.Map{}
+2 -2
View File
@@ -132,7 +132,7 @@ check2:
continue
}
// Check that the LHS is "d as u64".
// Check that the LHS is "d as base.u64".
lhs := x.LHS().Expr()
if lhs.Operator().Key() != t.KeyXBinaryAs {
continue
@@ -168,7 +168,7 @@ check3:
continue
}
// Check that the LHS is "l as u64".
// Check that the LHS is "l as base.u64".
lhs := x.LHS().Expr()
if lhs.Operator().Key() != t.KeyXBinaryAs {
continue
+17 -16
View File
@@ -34,26 +34,26 @@ var (
// typeExprFoo is an *ast.Node MType (implicit type).
var (
typeExprGeneric = a.NewTypeExpr(0, 0, t.IDDiamond, nil, nil, nil)
typeExprIdeal = a.NewTypeExpr(0, 0, t.IDDoubleZ, nil, nil, nil)
typeExprList = a.NewTypeExpr(0, 0, t.IDDollar, nil, nil, nil)
typeExprGeneric = a.NewTypeExpr(0, t.IDBase, t.IDDiamond, 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)
typeExprU8 = a.NewTypeExpr(0, 0, t.IDU8, nil, nil, nil)
typeExprU16 = a.NewTypeExpr(0, 0, t.IDU16, nil, nil, nil)
typeExprU32 = a.NewTypeExpr(0, 0, t.IDU32, nil, nil, nil)
typeExprU64 = a.NewTypeExpr(0, 0, t.IDU64, nil, nil, nil)
typeExprBool = a.NewTypeExpr(0, 0, t.IDBool, nil, nil, nil)
typeExprStatus = a.NewTypeExpr(0, 0, t.IDStatus, nil, nil, nil)
typeExprIOReader = a.NewTypeExpr(0, 0, t.IDIOReader, nil, nil, nil)
typeExprIOWriter = a.NewTypeExpr(0, 0, t.IDIOWriter, nil, nil, nil)
typeExprImageConfig = a.NewTypeExpr(0, 0, t.IDImageConfig, 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)
typeExprU32 = a.NewTypeExpr(0, t.IDBase, t.IDU32, nil, nil, nil)
typeExprU64 = a.NewTypeExpr(0, t.IDBase, t.IDU64, 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)
typeExprIOReader = a.NewTypeExpr(0, t.IDBase, t.IDIOReader, nil, nil, nil)
typeExprIOWriter = a.NewTypeExpr(0, t.IDBase, t.IDIOWriter, nil, nil, nil)
typeExprImageConfig = a.NewTypeExpr(0, t.IDBase, t.IDImageConfig, nil, nil, nil)
typeExprSliceU8 = a.NewTypeExpr(t.IDSlice, 0, 0, nil, nil, typeExprU8)
// TODO: delete this.
typeExprPlaceholder = a.NewTypeExpr(0, 0, t.IDU8, nil, nil, nil)
typeExprPlaceholder16 = a.NewTypeExpr(0, 0, t.IDU16, nil, nil, nil)
typeExprPlaceholder32 = a.NewTypeExpr(0, 0, t.IDU32, nil, nil, nil)
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.
@@ -127,6 +127,7 @@ func parseBuiltInFuncs(tm *t.Map, ss []string, generic bool) (map[t.QQID]*a.Func
return nil, fmt.Errorf("check: parsing %q: got %d top level decls, want %d", s, len(tlds), 1)
}
f := tlds[0].Func()
f.Node().Raw().SetPackage(tm, t.IDBase)
m[f.QQID()] = f
}
return m, nil
@@ -140,7 +141,7 @@ func (c *Checker) resolveFunc(typ *a.TypeExpr) (*a.Func, error) {
lQID := lTyp.QID()
qqid := t.QQID{lQID[0], lQID[1], typ.FuncName()}
if lTyp.IsSliceType() {
qqid[0] = 0
qqid[0] = t.IDBase
qqid[1] = t.IDDiamond
if f, err := c.builtInSliceFunc(qqid); err != nil {
return nil, err
+13 -13
View File
@@ -570,7 +570,7 @@ func (q *checker) tcheckExprCall(n *a.Expr, depth uint32) error {
}
genericType := (*a.TypeExpr)(nil)
if f.Receiver() == (t.QID{0, t.IDDiamond}) {
if f.Receiver() == (t.QID{t.IDBase, t.IDDiamond}) {
genericType = lhs.MType().Receiver()
}
@@ -690,7 +690,7 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
qqid := t.QQID{lQID[0], lQID[1], n.Ident()}
if lTyp.IsSliceType() {
qqid[0] = 0
qqid[0] = t.IDBase
qqid[1] = t.IDDiamond
if f, err := q.c.builtInSliceFunc(qqid); err != nil {
return err
@@ -725,18 +725,16 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
}
if s == nil {
s = q.c.structs[lQID]
if s == nil && builtInTypeMap[lQID[1]] == nil {
if s == nil {
return fmt.Errorf("check: no struct type %q found for expression %q", lTyp.Str(q.tm), lhs.Str(q.tm))
}
}
if s != nil {
for _, field := range s.Fields() {
f := field.Field()
if f.Name() == n.Ident() {
n.SetMType(f.XType())
return nil
}
for _, field := range s.Fields() {
f := field.Field()
if f.Name() == n.Ident() {
n.SetMType(f.XType())
return nil
}
}
@@ -1028,7 +1026,7 @@ swtch:
// TODO: also check t.KeyOpenParen.
case 0:
qid := typ.QID()
if qid[1].IsNumType() {
if qid[0] == t.IDBase && qid[1].IsNumType() {
for _, b := range typ.Bounds() {
if b == nil {
continue
@@ -1045,8 +1043,10 @@ swtch:
if typ.Min() != nil || typ.Max() != nil {
// TODO: reject. You can only refine numeric types.
}
if _, ok := builtInTypeMap[qid[1]]; ok {
break swtch
if qid[0] == t.IDBase {
if _, ok := builtInTypeMap[qid[1]]; ok {
break swtch
}
}
for _, s := range q.c.structs {
if s.QID() == qid {