mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-21 16:47:28 +01:00
Rename u32, io_reader, etc to base.u32, etc
This commit is contained in:
1 parent
fee97df698
commit
f95239f6e0
24 files changed
+394
-392
No files matched your search
+6
-11
@@ -274,16 +274,11 @@ func (n *Raw) SetPackage(tm *t.Map, pkg t.ID) error {
|
||||
if o.id0.Key() != 0 {
|
||||
return nil
|
||||
}
|
||||
// TODO: Add signed integer types, as per the builtin.Types var?
|
||||
//
|
||||
// Or, don't hard code these, and instead require built-in types to
|
||||
// have qualified names, such as "builtin.u8" or "base.io_reader"?
|
||||
switch o.id2.Key() {
|
||||
case t.KeyU8, t.KeyU16, t.KeyU32, t.KeyU64, t.KeyBool, t.KeyStatus, t.KeyIOReader, t.KeyIOWriter:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
if o.id1 == t.IDBase {
|
||||
return nil
|
||||
}
|
||||
if o.id1 != 0 {
|
||||
return fmt.Errorf(`invalid SetPackage(%q) call: old package: got %q, want ""`,
|
||||
pkg.Str(tm), o.id1.Str(tm))
|
||||
@@ -621,8 +616,8 @@ func NewJump(keyword t.ID, label t.ID) *Jump {
|
||||
// MaxTypeExprDepth is an advisory limit for a TypeExpr's recursion depth.
|
||||
const MaxTypeExprDepth = 63
|
||||
|
||||
// TypeExpr is a type expression, such as "u32", "u32[..8]", "pkg.foo", "ptr
|
||||
// T", "array[8] T" or "slice T":
|
||||
// TypeExpr is a type expression, such as "base.u32", "base.u32[..8]", "foo",
|
||||
// "pkg.bar", "ptr T", "array[8] T" or "slice T":
|
||||
// - ID0: <0|IDPtr|IDArray|IDSlice|IDOpenParen>
|
||||
// - ID1: <0|pkg>
|
||||
// - ID2: <0|type name>
|
||||
@@ -646,7 +641,7 @@ const MaxTypeExprDepth = 63
|
||||
// "foo". ID1 is the "pkg" or zero, ID2 is the "foo".
|
||||
//
|
||||
// Numeric types can be refined as "foo[LHS..MHS]". LHS and MHS are Expr's,
|
||||
// possibly nil. For example, the LHS for "u32[..4095]" is nil.
|
||||
// possibly nil. For example, the LHS for "base.u32[..4095]" is nil.
|
||||
//
|
||||
// TODO: struct types, list types, nptr vs ptr, table types.
|
||||
type TypeExpr Node
|
||||
|
||||
+1
-1
@@ -89,7 +89,7 @@ func (n *TypeExpr) Eq(o *TypeExpr) bool {
|
||||
}
|
||||
|
||||
// EqIgnoringRefinements returns whether n and o are equal, ignoring the
|
||||
// "[i:j]" in "u32[i:j]".
|
||||
// "[i:j]" in "base.u32[i:j]".
|
||||
func (n *TypeExpr) EqIgnoringRefinements(o *TypeExpr) bool {
|
||||
return n.eq(o, true)
|
||||
}
|
||||
|
||||
@@ -52,14 +52,14 @@ func TestString(tt *testing.T) {
|
||||
|
||||
"x + 42",
|
||||
"x and (y < z)",
|
||||
"x & (y as u8)",
|
||||
"x & (y as base.u8)",
|
||||
"x * ((a / b) - (i / j))",
|
||||
|
||||
"x + y + z",
|
||||
"x + (i * j.k[l] * (-m << 4) * (n & o(o0:p, o1:q[:r.s + 5]))) + z",
|
||||
|
||||
"x as bool",
|
||||
"x as u32",
|
||||
"x as base.bool",
|
||||
"x as base.u32",
|
||||
"x as T",
|
||||
"x as T",
|
||||
"x as T[i..]",
|
||||
|
||||
@@ -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
@@ -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{}
|
||||
|
||||
@@ -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
@@ -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
@@ -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 {
|
||||
|
||||
@@ -277,6 +277,7 @@ const (
|
||||
KeyIn = Key(IDIn >> KeyShift)
|
||||
KeyOut = Key(IDOut >> KeyShift)
|
||||
KeySLICE = Key(IDSLICE >> KeyShift)
|
||||
KeyBase = Key(IDBase >> KeyShift)
|
||||
|
||||
KeyI8 = Key(IDI8 >> KeyShift)
|
||||
KeyI16 = Key(IDI16 >> KeyShift)
|
||||
@@ -469,6 +470,7 @@ const (
|
||||
IDIn = ID(0x7A<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||
IDOut = ID(0x7B<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||
IDSLICE = ID(0x7C<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||
IDBase = ID(0x7D<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||
|
||||
IDI8 = ID(0x80<<KeyShift | FlagsIdent | FlagsImplicitSemicolon | FlagsNumType)
|
||||
IDI16 = ID(0x81<<KeyShift | FlagsIdent | FlagsImplicitSemicolon | FlagsNumType)
|
||||
@@ -681,6 +683,7 @@ var builtInsByKey = [nBuiltInKeys]struct {
|
||||
KeyIn: {"in", IDIn},
|
||||
KeyOut: {"out", IDOut},
|
||||
KeySLICE: {"SLICE", IDSLICE},
|
||||
KeyBase: {"base", IDBase},
|
||||
|
||||
// Change MaxIntBits if a future update adds an i128 or u128 type.
|
||||
|
||||
|
||||
Reference in new issue
Block a user