From 7a41ee4da1538e48170d90b70041698ec54c3a37 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Fri, 7 Jul 2017 16:54:19 +1000 Subject: [PATCH] Rename the "status" keyword to "suspension". --- cmd/puffs-gen-c/func.go | 8 +-- cmd/puffs-gen-c/main.go | 10 +-- doc/puffs-the-language.md | 13 ++-- gen/c/std/flate.c | 8 +-- gen/c/std/gif.c | 22 +++--- gen/h/std/flate.h | 4 +- gen/h/std/gif.h | 4 +- lang/ast/ast.go | 8 +-- lang/parse/parse.go | 4 +- lang/token/list.go | 138 +++++++++++++++++++------------------- test/c/std/gif.c | 8 +-- 11 files changed, 114 insertions(+), 113 deletions(-) diff --git a/cmd/puffs-gen-c/func.go b/cmd/puffs-gen-c/func.go index f8c85286..68d34737 100644 --- a/cmd/puffs-gen-c/func.go +++ b/cmd/puffs-gen-c/func.go @@ -822,7 +822,7 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error { g.printf("%s%d -= %srend_src - %srptr_src;\n", tPrefix, temp, bPrefix, bPrefix) g.printf("%ssrc.buf->ri = %ssrc.buf->wi;\n", aPrefix, aPrefix) - g.printf("status = %ssrc.buf->closed ? PUFFS_%s_ERROR_UNEXPECTED_EOF : PUFFS_%s_STATUS_SHORT_READ;", + g.printf("status = %ssrc.buf->closed ? PUFFS_%s_ERROR_UNEXPECTED_EOF : PUFFS_%s_SUSPENSION_SHORT_READ;", aPrefix, g.PKGNAME, g.PKGNAME) if g.perFunc.public && g.perFunc.suspendible { // TODO: drop the g.perFunc.public? g.writes("goto suspend;") @@ -844,7 +844,7 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error { g.writes("}\n") g.printf("if ((%swend_dst - %swptr_dst) < (sizeof(self->private_impl.f_stack) - v_s)) {", bPrefix, bPrefix) - g.printf("status = PUFFS_%s_STATUS_SHORT_WRITE;", g.PKGNAME) + g.printf("status = PUFFS_%s_SUSPENSION_SHORT_WRITE;", g.PKGNAME) if g.perFunc.public && g.perFunc.suspendible { g.writes("goto suspend;") } else { @@ -857,7 +857,7 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error { g.printf("b_wptr_dst += sizeof(self->private_impl.f_stack) - v_s;\n") } else if isInDst(g.tm, n, t.KeyWriteU8, 1) { - g.printf("if (%swptr_dst == %swend_dst) { status = PUFFS_%s_STATUS_SHORT_WRITE;", + g.printf("if (%swptr_dst == %swend_dst) { status = PUFFS_%s_SUSPENSION_SHORT_WRITE;", bPrefix, bPrefix, g.PKGNAME) if g.perFunc.public && g.perFunc.suspendible { g.writes("goto suspend;") @@ -968,7 +968,7 @@ func (g *gen) writeShortRead(name string) error { g.printf("\nshort_read_%s:\n", name) // TODO: ri == wi isn't the right condition. g.printf("status = ((%s%s.buf->closed) && (%s%s.buf->ri == %s%s.buf->wi)) ?"+ - "PUFFS_%s_ERROR_UNEXPECTED_EOF : PUFFS_%s_STATUS_SHORT_READ;", + "PUFFS_%s_ERROR_UNEXPECTED_EOF : PUFFS_%s_SUSPENSION_SHORT_READ;", aPrefix, name, aPrefix, name, aPrefix, name, g.PKGNAME, g.PKGNAME) if g.perFunc.public && g.perFunc.suspendible { // TODO: drop the g.perFunc.public? g.writes("goto suspend;") diff --git a/cmd/puffs-gen-c/main.go b/cmd/puffs-gen-c/main.go index b002ffe3..1028787b 100644 --- a/cmd/puffs-gen-c/main.go +++ b/cmd/puffs-gen-c/main.go @@ -87,9 +87,9 @@ var builtInStatuses = [...]string{ "error bad receiver", "error bad argument", "error constructor not called", - "error unexpected EOF", // Used if reading when closed == true. - "status short read", // Used if reading when closed == false. - "status short write", + "error unexpected EOF", // Used if reading when closed == true. + "suspension short read", // Used if reading when closed == false. + "suspension short write", "error closed for writes", } @@ -282,6 +282,8 @@ func (g *gen) genImpl() error { for _, s := range builtInStatuses { if strings.HasPrefix(s, "status ") { s = s[len("status "):] + } else if strings.HasPrefix(s, "suspension ") { + s = s[len("suspension "):] } else if strings.HasPrefix(s, "error ") { s = s[len("error "):] } @@ -406,7 +408,7 @@ func (g *gen) gatherStatuses(n *a.Status) error { if !ok { return fmt.Errorf("bad status message %q", raw) } - prefix := "status " + prefix := "suspension " isError := n.Keyword().Key() == t.KeyError if isError { prefix = "error " diff --git a/doc/puffs-the-language.md b/doc/puffs-the-language.md index f3b0b856..553a3095 100644 --- a/doc/puffs-the-language.md +++ b/doc/puffs-the-language.md @@ -18,8 +18,8 @@ top-level concepts: - `error` - `func` - `packageid` -- `status` - `struct` +- `suspension` - `use` 2 keywords distinguish between public and private API: @@ -123,12 +123,11 @@ The function name, such as `max`, may be followed by either an exclamation mark `!` or a question mark `?` but not both. An exclamation mark means that the function is impure, and may assign to things other than its local variables. A question mark means that the function is impure and furthermore a coroutine: it -can be suspended while returning a (recoverable) status, such as needing more -input data, or a (fatal) error, such as being invalid with respect to a file -format. If suspended with a status, calling that function again will resume at -the suspension point, not necessarily at the top of the function body. If -suspended with an error, calling that function again will return the same -error. +can return a (recoverable) suspension code, such as needing more input data, or +return a (fatal) error code, such as being invalid with respect to a file +format. If suspended, calling that function again will resume at the suspension +point, not necessarily at the top of the function body. If an error was +returned, calling that function again will return the same error. Some functions are methods, with syntax `func foo.bar(etc)(etc)`, where `foo` names a struct type and `bar` is the method name. Within the function body, an diff --git a/gen/c/std/flate.c b/gen/c/std/flate.c index 2b700a16..65e1800e 100644 --- a/gen/c/std/flate.c +++ b/gen/c/std/flate.c @@ -96,8 +96,8 @@ typedef int32_t puffs_flate_status; #define PUFFS_FLATE_ERROR_BAD_ARGUMENT -2147483645 // 0x80000003 #define PUFFS_FLATE_ERROR_CONSTRUCTOR_NOT_CALLED -2147483644 // 0x80000004 #define PUFFS_FLATE_ERROR_UNEXPECTED_EOF -2147483643 // 0x80000005 -#define PUFFS_FLATE_STATUS_SHORT_READ 6 // 0x00000006 -#define PUFFS_FLATE_STATUS_SHORT_WRITE 7 // 0x00000007 +#define PUFFS_FLATE_SUSPENSION_SHORT_READ 6 // 0x00000006 +#define PUFFS_FLATE_SUSPENSION_SHORT_WRITE 7 // 0x00000007 #define PUFFS_FLATE_ERROR_CLOSED_FOR_WRITES -2147483640 // 0x80000008 #define PUFFS_FLATE_ERROR_BAD_FLATE_BLOCK -1157040128 // 0xbb08f800 @@ -414,7 +414,7 @@ exit: short_read_src: status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi)) ? PUFFS_FLATE_ERROR_UNEXPECTED_EOF - : PUFFS_FLATE_STATUS_SHORT_READ; + : PUFFS_FLATE_SUSPENSION_SHORT_READ; goto suspend; } @@ -562,6 +562,6 @@ exit: short_read_src: status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi)) ? PUFFS_FLATE_ERROR_UNEXPECTED_EOF - : PUFFS_FLATE_STATUS_SHORT_READ; + : PUFFS_FLATE_SUSPENSION_SHORT_READ; goto suspend; } diff --git a/gen/c/std/gif.c b/gen/c/std/gif.c index ffcedc5d..11a2a1a6 100644 --- a/gen/c/std/gif.c +++ b/gen/c/std/gif.c @@ -96,8 +96,8 @@ typedef int32_t puffs_gif_status; #define PUFFS_GIF_ERROR_BAD_ARGUMENT -2147483645 // 0x80000003 #define PUFFS_GIF_ERROR_CONSTRUCTOR_NOT_CALLED -2147483644 // 0x80000004 #define PUFFS_GIF_ERROR_UNEXPECTED_EOF -2147483643 // 0x80000005 -#define PUFFS_GIF_STATUS_SHORT_READ 6 // 0x00000006 -#define PUFFS_GIF_STATUS_SHORT_WRITE 7 // 0x00000007 +#define PUFFS_GIF_SUSPENSION_SHORT_READ 6 // 0x00000006 +#define PUFFS_GIF_SUSPENSION_SHORT_WRITE 7 // 0x00000007 #define PUFFS_GIF_ERROR_CLOSED_FOR_WRITES -2147483640 // 0x80000008 #define PUFFS_GIF_ERROR_BAD_GIF_BLOCK -1105848320 // 0xbe161800 @@ -584,7 +584,7 @@ exit: short_read_src: status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi)) ? PUFFS_GIF_ERROR_UNEXPECTED_EOF - : PUFFS_GIF_STATUS_SHORT_READ; + : PUFFS_GIF_SUSPENSION_SHORT_READ; goto suspend; } @@ -664,7 +664,7 @@ exit: short_read_src: status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi)) ? PUFFS_GIF_ERROR_UNEXPECTED_EOF - : PUFFS_GIF_STATUS_SHORT_READ; + : PUFFS_GIF_SUSPENSION_SHORT_READ; return status; } @@ -773,7 +773,7 @@ exit: short_read_src: status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi)) ? PUFFS_GIF_ERROR_UNEXPECTED_EOF - : PUFFS_GIF_STATUS_SHORT_READ; + : PUFFS_GIF_SUSPENSION_SHORT_READ; return status; } @@ -835,7 +835,7 @@ puffs_gif_status puffs_gif_decoder_decode_extension(puffs_gif_decoder* self, t_2 -= b_rend_src - b_rptr_src; a_src.buf->ri = a_src.buf->wi; status = a_src.buf->closed ? PUFFS_GIF_ERROR_UNEXPECTED_EOF - : PUFFS_GIF_STATUS_SHORT_READ; + : PUFFS_GIF_SUSPENSION_SHORT_READ; return status; } b_rptr_src += t_2; @@ -868,7 +868,7 @@ exit: short_read_src: status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi)) ? PUFFS_GIF_ERROR_UNEXPECTED_EOF - : PUFFS_GIF_STATUS_SHORT_READ; + : PUFFS_GIF_SUSPENSION_SHORT_READ; return status; } @@ -1022,7 +1022,7 @@ exit: short_read_src: status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi)) ? PUFFS_GIF_ERROR_UNEXPECTED_EOF - : PUFFS_GIF_STATUS_SHORT_READ; + : PUFFS_GIF_SUSPENSION_SHORT_READ; return status; } @@ -1139,7 +1139,7 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self, if (v_code < v_clear_code) { PUFFS_COROUTINE_STATE(2); if (b_wptr_dst == b_wend_dst) { - status = PUFFS_GIF_STATUS_SHORT_WRITE; + status = PUFFS_GIF_SUSPENSION_SHORT_WRITE; goto suspend; } *b_wptr_dst++ = ((uint8_t)(v_code)); @@ -1183,7 +1183,7 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self, } if ((b_wend_dst - b_wptr_dst) < (sizeof(self->private_impl.f_stack) - v_s)) { - status = PUFFS_GIF_STATUS_SHORT_WRITE; + status = PUFFS_GIF_SUSPENSION_SHORT_WRITE; goto suspend; } memmove(b_wptr_dst, self->private_impl.f_stack + v_s, @@ -1252,6 +1252,6 @@ exit: short_read_src: status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi)) ? PUFFS_GIF_ERROR_UNEXPECTED_EOF - : PUFFS_GIF_STATUS_SHORT_READ; + : PUFFS_GIF_SUSPENSION_SHORT_READ; goto suspend; } diff --git a/gen/h/std/flate.h b/gen/h/std/flate.h index 6d66a52f..d30d1109 100644 --- a/gen/h/std/flate.h +++ b/gen/h/std/flate.h @@ -96,8 +96,8 @@ typedef int32_t puffs_flate_status; #define PUFFS_FLATE_ERROR_BAD_ARGUMENT -2147483645 // 0x80000003 #define PUFFS_FLATE_ERROR_CONSTRUCTOR_NOT_CALLED -2147483644 // 0x80000004 #define PUFFS_FLATE_ERROR_UNEXPECTED_EOF -2147483643 // 0x80000005 -#define PUFFS_FLATE_STATUS_SHORT_READ 6 // 0x00000006 -#define PUFFS_FLATE_STATUS_SHORT_WRITE 7 // 0x00000007 +#define PUFFS_FLATE_SUSPENSION_SHORT_READ 6 // 0x00000006 +#define PUFFS_FLATE_SUSPENSION_SHORT_WRITE 7 // 0x00000007 #define PUFFS_FLATE_ERROR_CLOSED_FOR_WRITES -2147483640 // 0x80000008 #define PUFFS_FLATE_ERROR_BAD_FLATE_BLOCK -1157040128 // 0xbb08f800 diff --git a/gen/h/std/gif.h b/gen/h/std/gif.h index b22b26c5..66043f06 100644 --- a/gen/h/std/gif.h +++ b/gen/h/std/gif.h @@ -96,8 +96,8 @@ typedef int32_t puffs_gif_status; #define PUFFS_GIF_ERROR_BAD_ARGUMENT -2147483645 // 0x80000003 #define PUFFS_GIF_ERROR_CONSTRUCTOR_NOT_CALLED -2147483644 // 0x80000004 #define PUFFS_GIF_ERROR_UNEXPECTED_EOF -2147483643 // 0x80000005 -#define PUFFS_GIF_STATUS_SHORT_READ 6 // 0x00000006 -#define PUFFS_GIF_STATUS_SHORT_WRITE 7 // 0x00000007 +#define PUFFS_GIF_SUSPENSION_SHORT_READ 6 // 0x00000006 +#define PUFFS_GIF_SUSPENSION_SHORT_WRITE 7 // 0x00000007 #define PUFFS_GIF_ERROR_CLOSED_FOR_WRITES -2147483640 // 0x80000008 #define PUFFS_GIF_ERROR_BAD_GIF_BLOCK -1105848320 // 0xbe161800 diff --git a/lang/ast/ast.go b/lang/ast/ast.go index 82b05b0e..9003fe4d 100644 --- a/lang/ast/ast.go +++ b/lang/ast/ast.go @@ -403,8 +403,8 @@ func NewIf(condition *Expr, elseIf *If, bodyIfTrue []*Node, bodyIfFalse []*Node) } } -// Return is "return LHS", "return error ID1" or "return status ID1": -// - ID0: <0|IDError|IDStatus> +// Return is "return LHS", "return error ID1" or "return suspension ID1": +// - ID0: <0|IDError|IDSuspension> // - ID1: message // - LHS: type Return Node @@ -577,9 +577,9 @@ func NewFunc(flags Flags, filename string, line uint32, receiver t.ID, name t.ID } } -// Status is "error ID1" or "status ID1": +// Status is "error ID1" or "suspension ID1": // - FlagsPublic is "pub" vs "pri" -// - ID0: +// - ID0: // - ID1: message type Status Node diff --git a/lang/parse/parse.go b/lang/parse/parse.go index 31ce9c4a..17a672e7 100644 --- a/lang/parse/parse.go +++ b/lang/parse/parse.go @@ -162,7 +162,7 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) { out := a.NewStruct(0, p.filename, line, t.IDOut, outFields) return a.NewFunc(flags, p.filename, line, id0, id1, in, out, asserts, body).Node(), nil - case t.KeyError, t.KeyStatus: + case t.KeyError, t.KeySuspension: keyword := p.src[0].ID p.src = p.src[1:] message := p.peek1() @@ -549,7 +549,7 @@ func (p *parser) parseStatement1() (*a.Node, error) { switch x := p.peek1(); x.Key() { case t.KeySemicolon: // No-op. - case t.KeyError, t.KeyStatus: + case t.KeyError, t.KeySuspension: keyword = x p.src = p.src[1:] message = p.peek1() diff --git a/lang/token/list.go b/lang/token/list.go index f15bdf42..51cac9a9 100644 --- a/lang/token/list.go +++ b/lang/token/list.go @@ -188,29 +188,29 @@ const ( KeyAs = Key(IDAs >> KeyShift) // TODO: sort these by name, when the list has stabilized. - KeyFunc = Key(IDFunc >> KeyShift) - KeyPtr = Key(IDPtr >> KeyShift) - KeyAssert = Key(IDAssert >> KeyShift) - KeyWhile = Key(IDWhile >> KeyShift) - KeyIf = Key(IDIf >> KeyShift) - KeyElse = Key(IDElse >> KeyShift) - KeyReturn = Key(IDReturn >> KeyShift) - KeyBreak = Key(IDBreak >> KeyShift) - KeyContinue = Key(IDContinue >> KeyShift) - KeyStruct = Key(IDStruct >> KeyShift) - KeyUse = Key(IDUse >> KeyShift) - KeyVar = Key(IDVar >> KeyShift) - KeyNptr = Key(IDNptr >> KeyShift) - KeyPre = Key(IDPre >> KeyShift) - KeyInv = Key(IDInv >> KeyShift) - KeyPost = Key(IDPost >> KeyShift) - KeyVia = Key(IDVia >> KeyShift) - KeyPub = Key(IDPub >> KeyShift) - KeyPri = Key(IDPri >> KeyShift) - KeyError = Key(IDError >> KeyShift) - KeyStatus = Key(IDStatus >> KeyShift) - KeyLimit = Key(IDLimit >> KeyShift) - KeyPackageID = Key(IDPackageID >> KeyShift) + KeyFunc = Key(IDFunc >> KeyShift) + KeyPtr = Key(IDPtr >> KeyShift) + KeyAssert = Key(IDAssert >> KeyShift) + KeyWhile = Key(IDWhile >> KeyShift) + KeyIf = Key(IDIf >> KeyShift) + KeyElse = Key(IDElse >> KeyShift) + KeyReturn = Key(IDReturn >> KeyShift) + KeyBreak = Key(IDBreak >> KeyShift) + KeyContinue = Key(IDContinue >> KeyShift) + KeyStruct = Key(IDStruct >> KeyShift) + KeyUse = Key(IDUse >> KeyShift) + KeyVar = Key(IDVar >> KeyShift) + KeyNptr = Key(IDNptr >> KeyShift) + KeyPre = Key(IDPre >> KeyShift) + KeyInv = Key(IDInv >> KeyShift) + KeyPost = Key(IDPost >> KeyShift) + KeyVia = Key(IDVia >> KeyShift) + KeyPub = Key(IDPub >> KeyShift) + KeyPri = Key(IDPri >> KeyShift) + KeyError = Key(IDError >> KeyShift) + KeySuspension = Key(IDSuspension >> KeyShift) + KeyLimit = Key(IDLimit >> KeyShift) + KeyPackageID = Key(IDPackageID >> KeyShift) KeyFalse = Key(IDFalse >> KeyShift) KeyTrue = Key(IDTrue >> KeyShift) @@ -349,29 +349,29 @@ const ( IDAs = ID(0x5B<