Add a nptr T type

This commit is contained in:
Nigel Tao committed 2018-07-15 17:10:03 +10:00
1 parent 15f2f42b77
commit 29eb64a0a4
11 files changed
+39 -27

No files matched your search

+1 -1
View File
@@ -35,7 +35,7 @@ func (g *gen) writeBuiltinCall(b *buffer, n *a.Expr, rp replacementPolicy, depth
switch recvTyp.Decorator() {
case 0:
// No-op.
case t.IDPtr:
case t.IDNptr, t.IDPtr:
// TODO: don't hard-code initialize.
if method.Ident() != g.tm.ByName("initialize") {
return errNoSuchBuiltin
+4 -5
View File
@@ -95,7 +95,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, depth u
method := n.LHS().AsExpr()
recv := method.LHS().AsExpr()
recvTyp, addr := recv.MType(), "&"
if recvTyp.Decorator() == t.IDPtr {
if p := recvTyp.Decorator(); p == t.IDNptr || p == t.IDPtr {
recvTyp, addr = recvTyp.Inner(), ""
}
if recvTyp.Decorator() != 0 {
@@ -199,7 +199,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, depth u
if err := g.writeExpr(b, lhs, rp, depth); err != nil {
return err
}
if key := lhs.MType().Decorator(); key == t.IDPtr || key == t.IDNptr {
if p := lhs.MType().Decorator(); p == t.IDNptr || p == t.IDPtr {
b.writes("->")
} else {
b.writes(".")
@@ -313,7 +313,7 @@ func (g *gen) writeExprUserDefinedCall(b *buffer, n *a.Expr, rp replacementPolic
method := n.LHS().AsExpr()
recv := method.LHS().AsExpr()
recvTyp, addr := recv.MType(), "&"
if recvTyp.Decorator() == t.IDPtr {
if p := recvTyp.Decorator(); p == t.IDNptr || p == t.IDPtr {
recvTyp, addr = recvTyp.Inner(), ""
}
if recvTyp.Decorator() != 0 {
@@ -368,8 +368,7 @@ func (g *gen) writeCTypeName(b *buffer, n *a.TypeExpr, varNamePrefix string, var
numPointers, innermost := 0, x
for ; innermost != nil && innermost.Inner() != nil; innermost = innermost.Inner() {
// TODO: "nptr T", not just "ptr T".
if p := innermost.Decorator(); p == t.IDPtr {
if p := innermost.Decorator(); p == t.IDNptr || p == t.IDPtr {
if numPointers == maxNumPointers {
return fmt.Errorf("cannot convert Wuffs type %q to C: too many ptr's", n.Str(g.tm))
}
+1 -1
View File
@@ -6,7 +6,7 @@
- Renamed Puffs to Wuffs.
- Ship as a "single file C library"
- Added a `skipgendeps` flag.
- Added a `nullptr` literal.
- Added a `nullptr` literal and `nptr T` type.
- Added an `io_bind` keyword.
- Added a `use` keyword.
- Added a `yield` keyword.
+4 -4
View File
@@ -636,14 +636,14 @@ const MaxTypeExprDepth = 63
// TypeExpr is a type expression, such as "base.u32", "base.u32[..8]", "foo",
// "pkg.bar", "ptr T", "array[8] T", "slice T" or "table T":
// - ID0: <0|IDArray|IDFunc|IDPtr|IDSlice|IDTable>
// - ID0: <0|IDArray|IDFunc|IDNptr|IDPtr|IDSlice|IDTable>
// - ID1: <0|pkg>
// - ID2: <0|type name>
// - LHS: <nil|Expr>
// - MHS: <nil|Expr>
// - RHS: <nil|TypeExpr>
//
// An IDPtr ID0 means "ptr RHS". RHS is the inner type.
// An IDNptr or IDPtr ID0 means "nptr RHS" or "ptr RHS". RHS is the inner type.
//
// An IDArray ID0 means "array[LHS] RHS". RHS is the inner type.
//
@@ -684,7 +684,7 @@ func (n *TypeExpr) Innermost() *TypeExpr {
}
func (n *TypeExpr) Pointee() *TypeExpr {
for ; n != nil && n.id0 == t.IDPtr; n = n.Inner() {
for ; n != nil && (n.id0 == t.IDNptr || n.id0 == t.IDPtr); n = n.Inner() {
}
return n
}
@@ -748,7 +748,7 @@ func (n *TypeExpr) HasPointers() bool {
return true
}
}
case t.IDPtr, t.IDNptr, t.IDSlice, t.IDTable:
case t.IDNptr, t.IDPtr, t.IDSlice, t.IDTable:
return true
}
}
+3
View File
@@ -223,6 +223,9 @@ func (n *TypeExpr) appendStr(buf []byte, tm *t.Map, depth uint32) []byte {
switch n.Decorator() {
case 0:
buf = append(buf, n.QID().Str(tm)...)
case t.IDNptr:
buf = append(buf, "nptr "...)
return n.Inner().appendStr(buf, tm, depth)
case t.IDPtr:
buf = append(buf, "ptr "...)
return n.Inner().appendStr(buf, tm, depth)
+18 -3
View File
@@ -888,8 +888,6 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (a.Bounds, error) {
func (q *checker) bcheckExprCall(n *a.Expr, depth uint32) error {
// TODO: handle func pre/post conditions.
//
// TODO: bcheck the receiver, e.g. ptr vs nptr.
lhs := n.LHS().AsExpr()
f, err := q.c.resolveFunc(lhs.MType())
if err != nil {
@@ -905,7 +903,24 @@ func (q *checker) bcheckExprCall(n *a.Expr, depth uint32) error {
return err
}
}
return nil
recv := lhs.LHS().AsExpr()
if recv.MType().Decorator() != t.IDNptr {
return nil
}
// Check that q.facts contain "recv != nullptr".
for _, x := range q.facts {
if x.Operator() != t.IDXBinaryNotEq {
continue
}
xLHS := x.LHS().AsExpr()
xRHS := x.RHS().AsExpr()
if (xLHS.Eq(exprNullptr) && xRHS.Eq(recv)) ||
(xRHS.Eq(exprNullptr) && xLHS.Eq(recv)) {
return nil
}
}
return fmt.Errorf("check: cannot prove %q", recv.Str(q.tm)+" != nullptr")
}
var errNotASpecialCase = errors.New("not a special case")
+4 -4
View File
@@ -27,12 +27,12 @@ import (
)
var (
exprIn = a.NewExpr(0, 0, 0, t.IDIn, nil, nil, nil, nil)
exprOut = a.NewExpr(0, 0, 0, t.IDOut, nil, nil, nil, nil)
exprThis = a.NewExpr(0, 0, 0, t.IDThis, nil, nil, nil, nil)
exprIn = a.NewExpr(0, 0, 0, t.IDIn, nil, nil, nil, nil)
exprOut = a.NewExpr(0, 0, 0, t.IDOut, nil, nil, nil, nil)
exprThis = a.NewExpr(0, 0, 0, t.IDThis, nil, nil, nil, nil)
exprNullptr = a.NewExpr(0, 0, 0, t.IDNullptr, nil, nil, nil, nil)
)
// typeExprFoo is an *ast.Node MType (implicit type).
var (
typeExprGeneric1 = a.NewTypeExpr(0, t.IDBase, t.IDDagger1, nil, nil, nil)
typeExprGeneric2 = a.NewTypeExpr(0, t.IDBase, t.IDDagger2, nil, nil, nil)
+1 -2
View File
@@ -1009,8 +1009,7 @@ swtch:
}
fallthrough
// TODO: also check t.IDNptr? Where else should we look for nptr?
case t.IDPtr, t.IDSlice, t.IDTable:
case t.IDNptr, t.IDPtr, t.IDSlice, t.IDTable:
if err := q.tcheckTypeExpr(typ.Inner(), depth); err != nil {
return err
}
+2 -2
View File
@@ -377,13 +377,13 @@ func (p *parser) parseFieldNode() (*a.Node, error) {
}
func (p *parser) parseTypeExpr() (*a.TypeExpr, error) {
if p.peek1() == t.IDPtr {
if x := p.peek1(); x == t.IDNptr || x == t.IDPtr {
p.src = p.src[1:]
rhs, err := p.parseTypeExpr()
if err != nil {
return nil, err
}
return a.NewTypeExpr(t.IDPtr, 0, 0, nil, nil, rhs), nil
return a.NewTypeExpr(x, 0, 0, nil, nil, rhs), nil
}
decorator, arrayLength := t.ID(0), (*a.Expr)(nil)
-4
View File
@@ -6523,10 +6523,6 @@ wuffs_gif__decoder__decode_config(wuffs_gif__decoder* self,
if (self->private_impl.status < 0) {
return self->private_impl.status;
}
if (!a_dst) {
self->private_impl.status = WUFFS_BASE__ERROR_BAD_ARGUMENT;
return WUFFS_BASE__ERROR_BAD_ARGUMENT;
}
wuffs_base__status status = WUFFS_BASE__STATUS_OK;
uint32_t v_num_loops;
+1 -1
View File
@@ -104,7 +104,7 @@ pub struct decoder?(
)
// TODO: should dst be an nptr instead of a ptr?
pub func decoder.decode_config?(dst ptr base.image_config, src base.io_reader)() {
pub func decoder.decode_config?(dst nptr base.image_config, src base.io_reader)() {
if this.call_sequence >= 1 {
return error "invalid call sequence"
}