From 0384c5e4a8a85f2950b547eefdf9d48de8b97fb2 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Fri, 13 Oct 2017 10:59:47 +1100 Subject: [PATCH] Rename the copy_from_xxx methods for consistency. --- cmd/puffs-c/internal/cgen/expr.go | 6 +- cmd/puffs-c/internal/cgen/statement.go | 6 +- lang/check/bounds.go | 8 +-- lang/check/type.go | 12 ++-- lang/token/list.go | 84 ++++++++++++-------------- std/flate/decode_flate.puffs | 10 +-- std/gif/decode_lzw.puffs | 4 +- 7 files changed, 62 insertions(+), 68 deletions(-) diff --git a/cmd/puffs-c/internal/cgen/expr.go b/cmd/puffs-c/internal/cgen/expr.go index 4b82cacc..72e3296d 100644 --- a/cmd/puffs-c/internal/cgen/expr.go +++ b/cmd/puffs-c/internal/cgen/expr.go @@ -159,7 +159,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare b.writes(")") return nil } - if isInDst(g.tm, n, t.KeyCopyFrom32, 2) { + if isInDst(g.tm, n, t.KeyCopyFromReader32, 2) { b.printf("puffs_base_writer1_copy_from32(&%swptr_dst, %swend_dst", bPrefix, bPrefix) // TODO: don't assume that the first argument is "in.src". b.printf(", &%srptr_src, %srend_src,", bPrefix, bPrefix) @@ -170,7 +170,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare b.writeb(')') return nil } - if isInDst(g.tm, n, t.KeyCopyHistory32, 2) { + if isInDst(g.tm, n, t.KeyCopyFromHistory32, 2) { b.printf("puffs_base_writer1_copy_history32(&%swptr_dst, %swstart_dst, %swend_dst", bPrefix, bPrefix, bPrefix) for _, o := range n.Args() { @@ -187,7 +187,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare bPrefix, bPrefix, bPrefix) return nil } - if isThatMethod(g.tm, n, t.KeyCopyFrom, 1) { + if isThatMethod(g.tm, n, t.KeyCopyFromSlice, 1) { b.writes("puffs_base_slice_u8_copy_from(") receiver := n.LHS().Expr().LHS().Expr() if err := g.writeExpr(b, receiver, rp, parenthesesMandatory, depth); err != nil { diff --git a/cmd/puffs-c/internal/cgen/statement.go b/cmd/puffs-c/internal/cgen/statement.go index ed01d718..215efff2 100644 --- a/cmd/puffs-c/internal/cgen/statement.go +++ b/cmd/puffs-c/internal/cgen/statement.go @@ -368,7 +368,7 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error { g.currFunk.shortReads = append(g.currFunk.shortReads, "src") b.printf("%srptr_src += %s;\n", bPrefix, scratchName) - } else if isInDst(g.tm, n, t.KeyWrite, 1) { + } else if isInDst(g.tm, n, t.KeyCopyFromSlice, 1) { // TODO: don't assume that the argument is "this.stack[s:]". b.printf("if (%sdst.buf && %sdst.buf->closed) { status = %sERROR_CLOSED_FOR_WRITES;", aPrefix, aPrefix, g.PKGPREFIX) @@ -618,8 +618,8 @@ func isInSrc(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool { } func isInDst(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool { - callSuspendible := methodName != t.KeyCopyFrom32 && - methodName != t.KeyCopyHistory32 && + callSuspendible := methodName != t.KeyCopyFromReader32 && + methodName != t.KeyCopyFromHistory32 && methodName != t.KeySlice // TODO: check that n.Args() is "(x:bar)". if n.ID0().Key() != t.KeyOpenParen || n.CallSuspendible() != callSuspendible || len(n.Args()) != nArgs { diff --git a/lang/check/bounds.go b/lang/check/bounds.go index e93c9c85..04c1c245 100644 --- a/lang/check/bounds.go +++ b/lang/check/bounds.go @@ -663,8 +663,8 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int, isInSrc(q.tm, n, t.KeyReadU16BE, 0) || isInSrc(q.tm, n, t.KeyReadU32BE, 0) || isInSrc(q.tm, n, t.KeyReadU32BE, 0) || isInSrc(q.tm, n, t.KeyReadU32LE, 0) || isInSrc(q.tm, n, t.KeySkip32, 1) || - isInDst(q.tm, n, t.KeyWrite, 1) || isInDst(q.tm, n, t.KeyWriteU8, 1) || - isInDst(q.tm, n, t.KeyCopyFrom32, 2) || isInDst(q.tm, n, t.KeyCopyHistory32, 2) || + isInDst(q.tm, n, t.KeyCopyFromSlice, 1) || isInDst(q.tm, n, t.KeyWriteU8, 1) || + isInDst(q.tm, n, t.KeyCopyFromReader32, 2) || isInDst(q.tm, n, t.KeyCopyFromHistory32, 2) || isInDst(q.tm, n, t.KeySlice, 0) || isThisMethod(q.tm, n, "decode_header", 1) || isThisMethod(q.tm, n, "decode_lsd", 1) || isThisMethod(q.tm, n, "decode_extension", 1) || isThisMethod(q.tm, n, "decode_id", 2) || @@ -735,8 +735,8 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int, } return nil, nil, nil } - // TODO: delete this hack that only matches "foo.copy_from(etc)". - if isThatMethod(q.tm, n, t.KeyCopyFrom, 1) { + // TODO: delete this hack that only matches "foo.copy_from_slice(etc)". + if isThatMethod(q.tm, n, t.KeyCopyFromSlice, 1) { for _, o := range n.Args() { a := o.Arg().Value() aMin, aMax, err := q.bcheckExpr(a, depth) diff --git a/lang/check/type.go b/lang/check/type.go index 6a9e8047..aef6362f 100644 --- a/lang/check/type.go +++ b/lang/check/type.go @@ -373,8 +373,8 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error { isInSrc(q.tm, n, t.KeyReadU16BE, 0) || isInSrc(q.tm, n, t.KeyReadU32BE, 0) || isInSrc(q.tm, n, t.KeyReadU32BE, 0) || isInSrc(q.tm, n, t.KeyReadU32LE, 0) || isInSrc(q.tm, n, t.KeySkip32, 1) || - isInDst(q.tm, n, t.KeyWrite, 1) || isInDst(q.tm, n, t.KeyWriteU8, 1) || - isInDst(q.tm, n, t.KeyCopyFrom32, 2) || isInDst(q.tm, n, t.KeyCopyHistory32, 2) || + isInDst(q.tm, n, t.KeyCopyFromSlice, 1) || isInDst(q.tm, n, t.KeyWriteU8, 1) || + isInDst(q.tm, n, t.KeyCopyFromReader32, 2) || isInDst(q.tm, n, t.KeyCopyFromHistory32, 2) || isInDst(q.tm, n, t.KeySlice, 0) || isThisMethod(q.tm, n, "decode_header", 1) || isThisMethod(q.tm, n, "decode_lsd", 1) || isThisMethod(q.tm, n, "decode_extension", 1) || isThisMethod(q.tm, n, "decode_id", 2) || @@ -399,7 +399,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error { n.SetMType(typeExprPlaceholder16) // HACK. } else if isInDst(q.tm, n, t.KeySlice, 0) { n.SetMType(typeExprSliceU8) // HACK. - } else if isInDst(q.tm, n, t.KeyCopyFrom32, 2) || isInDst(q.tm, n, t.KeyCopyHistory32, 2) { + } else if isInDst(q.tm, n, t.KeyCopyFromReader32, 2) || isInDst(q.tm, n, t.KeyCopyFromHistory32, 2) { n.SetMType(typeExprU32) // HACK. } else { n.SetMType(typeExprPlaceholder) // HACK. @@ -473,7 +473,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error { return nil } // TODO: delete this hack that only matches "foo.length(etc)". - if isThatMethod(q.tm, n, t.KeyCopyFrom, 1) || isThatMethod(q.tm, n, t.KeyLength, 0) || + if isThatMethod(q.tm, n, t.KeyCopyFromSlice, 1) || isThatMethod(q.tm, n, t.KeyLength, 0) || isThatMethod(q.tm, n, t.KeyAvailable, 0) { foo := n.LHS().Expr().LHS().Expr() if err := q.tcheckExpr(foo, depth); err != nil { @@ -615,8 +615,8 @@ func isInSrc(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool { } func isInDst(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool { - callSuspendible := methodName != t.KeyCopyFrom32 && - methodName != t.KeyCopyHistory32 && + callSuspendible := methodName != t.KeyCopyFromReader32 && + methodName != t.KeyCopyFromHistory32 && methodName != t.KeySlice // TODO: check that n.Args() is "(x:bar)". if n.ID0().Key() != t.KeyOpenParen || n.CallSuspendible() != callSuspendible || len(n.Args()) != nArgs { diff --git a/lang/token/list.go b/lang/token/list.go index e0006292..34315e50 100644 --- a/lang/token/list.go +++ b/lang/token/list.go @@ -273,7 +273,6 @@ const ( KeyReadU32LE = Key(IDReadU32LE >> KeyShift) KeyReadU64BE = Key(IDReadU64BE >> KeyShift) KeyReadU64LE = Key(IDReadU64LE >> KeyShift) - KeyWrite = Key(IDWrite >> KeyShift) KeyWriteU8 = Key(IDWriteU8 >> KeyShift) KeyWriteU16BE = Key(IDWriteU16BE >> KeyShift) KeyWriteU16LE = Key(IDWriteU16LE >> KeyShift) @@ -282,20 +281,19 @@ const ( KeyWriteU64BE = Key(IDWriteU64BE >> KeyShift) KeyWriteU64LE = Key(IDWriteU64LE >> KeyShift) - KeyIsError = Key(IDIsError >> KeyShift) - KeyIsOK = Key(IDIsOK >> KeyShift) - KeyIsSuspension = Key(IDIsSuspension >> KeyShift) - KeyCopyFrom = Key(IDCopyFrom >> KeyShift) - KeyCopyFrom32 = Key(IDCopyFrom32 >> KeyShift) - KeyCopyFrom64 = Key(IDCopyFrom64 >> KeyShift) - KeySkip32 = Key(IDSkip32 >> KeyShift) - KeySkip64 = Key(IDSkip64 >> KeyShift) - KeyCopyHistory32 = Key(IDCopyHistory32 >> KeyShift) - KeySlice = Key(IDSlice >> KeyShift) - KeyLength = Key(IDLength >> KeyShift) - KeyAvailable = Key(IDAvailable >> KeyShift) - KeyPrefix = Key(IDPrefix >> KeyShift) - KeySuffix = Key(IDSuffix >> KeyShift) + KeyIsError = Key(IDIsError >> KeyShift) + KeyIsOK = Key(IDIsOK >> KeyShift) + KeyIsSuspension = Key(IDIsSuspension >> KeyShift) + KeyCopyFromHistory32 = Key(IDCopyFromHistory32 >> KeyShift) + KeyCopyFromReader32 = Key(IDCopyFromReader32 >> KeyShift) + KeyCopyFromSlice = Key(IDCopyFromSlice >> KeyShift) + KeySkip32 = Key(IDSkip32 >> KeyShift) + KeySkip64 = Key(IDSkip64 >> KeyShift) + KeySlice = Key(IDSlice >> KeyShift) + KeyLength = Key(IDLength >> KeyShift) + KeyAvailable = Key(IDAvailable >> KeyShift) + KeyPrefix = Key(IDPrefix >> KeyShift) + KeySuffix = Key(IDSuffix >> KeyShift) KeyXUnaryPlus = Key(IDXUnaryPlus >> KeyShift) KeyXUnaryMinus = Key(IDXUnaryMinus >> KeyShift) @@ -452,7 +450,6 @@ const ( IDReadU32LE = ID(0xB5<