Add a yield keyword

This commit is contained in:
Nigel Tao committed 2017-12-01 15:24:48 +11:00
1 parent 93665d50fe
commit 65dcf6a5b9
19 files changed
+122 -89

No files matched your search

+1 -1
View File
@@ -228,7 +228,7 @@ func (g *gen) genHeader(b *buffer) error {
for i, z := range builtin.StatusList { for i, z := range builtin.StatusList {
code := uint32(0) code := uint32(0)
if z.Keyword == t.IDError { if z.Keyword.Key() == t.KeyError {
code |= 1 << 31 code |= 1 << 31
} }
code |= uint32(i) code |= uint32(i)
+10 -5
View File
@@ -219,8 +219,8 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
b.printf("goto label_%d_%s;\n", jt, keyword) b.printf("goto label_%d_%s;\n", jt, keyword)
return nil return nil
case a.KReturn: case a.KRet:
n := n.Return() n := n.Ret()
retExpr := n.Value() retExpr := n.Value()
if g.currFunk.suspendible { if g.currFunk.suspendible {
@@ -238,15 +238,20 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
} }
b.writes(";") b.writes(";")
if n.Keyword().Key() == t.KeyYield {
return g.writeCoroSuspPoint(b, true)
}
switch retKeyword { switch retKeyword {
case t.KeyError: case t.KeyError:
b.writes("goto exit;") b.writes("goto exit;")
return nil
case t.KeyStatus: case t.KeyStatus:
b.writes("goto ok;") b.writes("goto ok;")
return nil default:
b.printf("if (status == 0) { goto ok; } else if (status > 0) { "+
"status = %sERROR_CANNOT_RETURN_A_SUSPENSION; } goto exit;", g.PKGPREFIX)
} }
return g.writeCoroSuspPoint(b, true) return nil
} }
b.writes("return ") b.writes("return ")
+3 -2
View File
@@ -3,14 +3,15 @@
## Work In Progress ## Work In Progress
- Renamed Puffs to Wuffs - Renamed Puffs to Wuffs.
- Added a `yield` keyword.
## 2017-11-16 ## 2017-11-16
- [Initial open source - [Initial open source
release](https://groups.google.com/d/topic/puffslang/2z61mNTAMns/discussion), release](https://groups.google.com/d/topic/puffslang/2z61mNTAMns/discussion),
under the "Puffs" name under the "Puffs" name.
--- ---
+2 -1
View File
@@ -27,7 +27,7 @@ be enclosed by curly `{}`s. There is no 'dangling else' ambiguity.
- `pri` - `pri`
- `pub` - `pub`
7 keywords deal with control flow within a function: 8 keywords deal with control flow within a function:
- `break` - `break`
- `continue` - `continue`
@@ -36,6 +36,7 @@ be enclosed by curly `{}`s. There is no 'dangling else' ambiguity.
- `iterate` - `iterate`
- `return` - `return`
- `while` - `while`
- `yield`
5 keywords deal with assertions: 5 keywords deal with assertions:
+21 -14
View File
@@ -125,16 +125,17 @@ typedef int32_t wuffs_flate__status;
#define wuffs_flate__packageid 967230 // 0x000ec23e #define wuffs_flate__packageid 967230 // 0x000ec23e
#define WUFFS_FLATE__STATUS_OK 0 // 0x00000000 #define WUFFS_FLATE__STATUS_OK 0 // 0x00000000
#define WUFFS_FLATE__ERROR_BAD_WUFFS_VERSION -2147483647 // 0x80000001 #define WUFFS_FLATE__ERROR_BAD_WUFFS_VERSION -2147483647 // 0x80000001
#define WUFFS_FLATE__ERROR_BAD_RECEIVER -2147483646 // 0x80000002 #define WUFFS_FLATE__ERROR_BAD_RECEIVER -2147483646 // 0x80000002
#define WUFFS_FLATE__ERROR_BAD_ARGUMENT -2147483645 // 0x80000003 #define WUFFS_FLATE__ERROR_BAD_ARGUMENT -2147483645 // 0x80000003
#define WUFFS_FLATE__ERROR_INITIALIZER_NOT_CALLED -2147483644 // 0x80000004 #define WUFFS_FLATE__ERROR_INITIALIZER_NOT_CALLED -2147483644 // 0x80000004
#define WUFFS_FLATE__ERROR_INVALID_I_O_OPERATION -2147483643 // 0x80000005 #define WUFFS_FLATE__ERROR_INVALID_I_O_OPERATION -2147483643 // 0x80000005
#define WUFFS_FLATE__ERROR_CLOSED_FOR_WRITES -2147483642 // 0x80000006 #define WUFFS_FLATE__ERROR_CLOSED_FOR_WRITES -2147483642 // 0x80000006
#define WUFFS_FLATE__ERROR_UNEXPECTED_EOF -2147483641 // 0x80000007 #define WUFFS_FLATE__ERROR_UNEXPECTED_EOF -2147483641 // 0x80000007
#define WUFFS_FLATE__SUSPENSION_SHORT_READ 8 // 0x00000008 #define WUFFS_FLATE__SUSPENSION_SHORT_READ 8 // 0x00000008
#define WUFFS_FLATE__SUSPENSION_SHORT_WRITE 9 // 0x00000009 #define WUFFS_FLATE__SUSPENSION_SHORT_WRITE 9 // 0x00000009
#define WUFFS_FLATE__ERROR_CANNOT_RETURN_A_SUSPENSION -2147483638 // 0x8000000a
#define WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_OVER_SUBSCRIBED \ #define WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_OVER_SUBSCRIBED \
-1157040128 // 0xbb08f800 -1157040128 // 0xbb08f800
@@ -690,7 +691,7 @@ bool wuffs_flate__status__is_error(wuffs_flate__status s) {
return s < 0; return s < 0;
} }
const char* wuffs_flate__status__strings0[10] = { const char* wuffs_flate__status__strings0[11] = {
"flate: ok", "flate: ok",
"flate: bad wuffs version", "flate: bad wuffs version",
"flate: bad receiver", "flate: bad receiver",
@@ -701,6 +702,7 @@ const char* wuffs_flate__status__strings0[10] = {
"flate: unexpected EOF", "flate: unexpected EOF",
"flate: short read", "flate: short read",
"flate: short write", "flate: short write",
"flate: cannot return a suspension",
}; };
const char* wuffs_flate__status__strings1[22] = { const char* wuffs_flate__status__strings1[22] = {
@@ -734,7 +736,7 @@ const char* wuffs_flate__status__string(wuffs_flate__status s) {
switch ((s >> 10) & 0x1fffff) { switch ((s >> 10) & 0x1fffff) {
case 0: case 0:
a = wuffs_flate__status__strings0; a = wuffs_flate__status__strings0;
n = 10; n = 11;
break; break;
case wuffs_flate__packageid: case wuffs_flate__packageid:
a = wuffs_flate__status__strings1; a = wuffs_flate__status__strings1;
@@ -962,7 +964,12 @@ wuffs_flate__status wuffs_flate__flate_decoder__decode(
} }
if (!(v_z > 0)) { if (!(v_z > 0)) {
status = v_z; status = v_z;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2); if (status == 0) {
goto ok;
} else if (status > 0) {
status = WUFFS_FLATE__ERROR_CANNOT_RETURN_A_SUSPENSION;
}
goto exit;
} }
v_written = ((wuffs_base__slice_u8){ v_written = ((wuffs_base__slice_u8){
.ptr = a_dst.private_impl.mark, .ptr = a_dst.private_impl.mark,
@@ -1003,7 +1010,7 @@ wuffs_flate__status wuffs_flate__flate_decoder__decode(
} }
} }
status = v_z; status = v_z;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3); WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
} }
goto ok; goto ok;
+14 -12
View File
@@ -125,16 +125,17 @@ typedef int32_t wuffs_gif__status;
#define wuffs_gif__packageid 1017222 // 0x000f8586 #define wuffs_gif__packageid 1017222 // 0x000f8586
#define WUFFS_GIF__STATUS_OK 0 // 0x00000000 #define WUFFS_GIF__STATUS_OK 0 // 0x00000000
#define WUFFS_GIF__ERROR_BAD_WUFFS_VERSION -2147483647 // 0x80000001 #define WUFFS_GIF__ERROR_BAD_WUFFS_VERSION -2147483647 // 0x80000001
#define WUFFS_GIF__ERROR_BAD_RECEIVER -2147483646 // 0x80000002 #define WUFFS_GIF__ERROR_BAD_RECEIVER -2147483646 // 0x80000002
#define WUFFS_GIF__ERROR_BAD_ARGUMENT -2147483645 // 0x80000003 #define WUFFS_GIF__ERROR_BAD_ARGUMENT -2147483645 // 0x80000003
#define WUFFS_GIF__ERROR_INITIALIZER_NOT_CALLED -2147483644 // 0x80000004 #define WUFFS_GIF__ERROR_INITIALIZER_NOT_CALLED -2147483644 // 0x80000004
#define WUFFS_GIF__ERROR_INVALID_I_O_OPERATION -2147483643 // 0x80000005 #define WUFFS_GIF__ERROR_INVALID_I_O_OPERATION -2147483643 // 0x80000005
#define WUFFS_GIF__ERROR_CLOSED_FOR_WRITES -2147483642 // 0x80000006 #define WUFFS_GIF__ERROR_CLOSED_FOR_WRITES -2147483642 // 0x80000006
#define WUFFS_GIF__ERROR_UNEXPECTED_EOF -2147483641 // 0x80000007 #define WUFFS_GIF__ERROR_UNEXPECTED_EOF -2147483641 // 0x80000007
#define WUFFS_GIF__SUSPENSION_SHORT_READ 8 // 0x00000008 #define WUFFS_GIF__SUSPENSION_SHORT_READ 8 // 0x00000008
#define WUFFS_GIF__SUSPENSION_SHORT_WRITE 9 // 0x00000009 #define WUFFS_GIF__SUSPENSION_SHORT_WRITE 9 // 0x00000009
#define WUFFS_GIF__ERROR_CANNOT_RETURN_A_SUSPENSION -2147483638 // 0x8000000a
#define WUFFS_GIF__ERROR_BAD_GIF_BLOCK -1105848320 // 0xbe161800 #define WUFFS_GIF__ERROR_BAD_GIF_BLOCK -1105848320 // 0xbe161800
#define WUFFS_GIF__ERROR_BAD_GIF_EXTENSION_LABEL -1105848319 // 0xbe161801 #define WUFFS_GIF__ERROR_BAD_GIF_EXTENSION_LABEL -1105848319 // 0xbe161801
@@ -632,7 +633,7 @@ bool wuffs_gif__status__is_error(wuffs_gif__status s) {
return s < 0; return s < 0;
} }
const char* wuffs_gif__status__strings0[10] = { const char* wuffs_gif__status__strings0[11] = {
"gif: ok", "gif: ok",
"gif: bad wuffs version", "gif: bad wuffs version",
"gif: bad receiver", "gif: bad receiver",
@@ -643,6 +644,7 @@ const char* wuffs_gif__status__strings0[10] = {
"gif: unexpected EOF", "gif: unexpected EOF",
"gif: short read", "gif: short read",
"gif: short write", "gif: short write",
"gif: cannot return a suspension",
}; };
const char* wuffs_gif__status__strings1[8] = { const char* wuffs_gif__status__strings1[8] = {
@@ -662,7 +664,7 @@ const char* wuffs_gif__status__string(wuffs_gif__status s) {
switch ((s >> 10) & 0x1fffff) { switch ((s >> 10) & 0x1fffff) {
case 0: case 0:
a = wuffs_gif__status__strings0; a = wuffs_gif__status__strings0;
n = 10; n = 11;
break; break;
case wuffs_gif__packageid: case wuffs_gif__packageid:
a = wuffs_gif__status__strings1; a = wuffs_gif__status__strings1;
+11 -10
View File
@@ -125,16 +125,17 @@ typedef int32_t wuffs_flate__status;
#define wuffs_flate__packageid 967230 // 0x000ec23e #define wuffs_flate__packageid 967230 // 0x000ec23e
#define WUFFS_FLATE__STATUS_OK 0 // 0x00000000 #define WUFFS_FLATE__STATUS_OK 0 // 0x00000000
#define WUFFS_FLATE__ERROR_BAD_WUFFS_VERSION -2147483647 // 0x80000001 #define WUFFS_FLATE__ERROR_BAD_WUFFS_VERSION -2147483647 // 0x80000001
#define WUFFS_FLATE__ERROR_BAD_RECEIVER -2147483646 // 0x80000002 #define WUFFS_FLATE__ERROR_BAD_RECEIVER -2147483646 // 0x80000002
#define WUFFS_FLATE__ERROR_BAD_ARGUMENT -2147483645 // 0x80000003 #define WUFFS_FLATE__ERROR_BAD_ARGUMENT -2147483645 // 0x80000003
#define WUFFS_FLATE__ERROR_INITIALIZER_NOT_CALLED -2147483644 // 0x80000004 #define WUFFS_FLATE__ERROR_INITIALIZER_NOT_CALLED -2147483644 // 0x80000004
#define WUFFS_FLATE__ERROR_INVALID_I_O_OPERATION -2147483643 // 0x80000005 #define WUFFS_FLATE__ERROR_INVALID_I_O_OPERATION -2147483643 // 0x80000005
#define WUFFS_FLATE__ERROR_CLOSED_FOR_WRITES -2147483642 // 0x80000006 #define WUFFS_FLATE__ERROR_CLOSED_FOR_WRITES -2147483642 // 0x80000006
#define WUFFS_FLATE__ERROR_UNEXPECTED_EOF -2147483641 // 0x80000007 #define WUFFS_FLATE__ERROR_UNEXPECTED_EOF -2147483641 // 0x80000007
#define WUFFS_FLATE__SUSPENSION_SHORT_READ 8 // 0x00000008 #define WUFFS_FLATE__SUSPENSION_SHORT_READ 8 // 0x00000008
#define WUFFS_FLATE__SUSPENSION_SHORT_WRITE 9 // 0x00000009 #define WUFFS_FLATE__SUSPENSION_SHORT_WRITE 9 // 0x00000009
#define WUFFS_FLATE__ERROR_CANNOT_RETURN_A_SUSPENSION -2147483638 // 0x8000000a
#define WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_OVER_SUBSCRIBED \ #define WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_OVER_SUBSCRIBED \
-1157040128 // 0xbb08f800 -1157040128 // 0xbb08f800
+11 -10
View File
@@ -125,16 +125,17 @@ typedef int32_t wuffs_gif__status;
#define wuffs_gif__packageid 1017222 // 0x000f8586 #define wuffs_gif__packageid 1017222 // 0x000f8586
#define WUFFS_GIF__STATUS_OK 0 // 0x00000000 #define WUFFS_GIF__STATUS_OK 0 // 0x00000000
#define WUFFS_GIF__ERROR_BAD_WUFFS_VERSION -2147483647 // 0x80000001 #define WUFFS_GIF__ERROR_BAD_WUFFS_VERSION -2147483647 // 0x80000001
#define WUFFS_GIF__ERROR_BAD_RECEIVER -2147483646 // 0x80000002 #define WUFFS_GIF__ERROR_BAD_RECEIVER -2147483646 // 0x80000002
#define WUFFS_GIF__ERROR_BAD_ARGUMENT -2147483645 // 0x80000003 #define WUFFS_GIF__ERROR_BAD_ARGUMENT -2147483645 // 0x80000003
#define WUFFS_GIF__ERROR_INITIALIZER_NOT_CALLED -2147483644 // 0x80000004 #define WUFFS_GIF__ERROR_INITIALIZER_NOT_CALLED -2147483644 // 0x80000004
#define WUFFS_GIF__ERROR_INVALID_I_O_OPERATION -2147483643 // 0x80000005 #define WUFFS_GIF__ERROR_INVALID_I_O_OPERATION -2147483643 // 0x80000005
#define WUFFS_GIF__ERROR_CLOSED_FOR_WRITES -2147483642 // 0x80000006 #define WUFFS_GIF__ERROR_CLOSED_FOR_WRITES -2147483642 // 0x80000006
#define WUFFS_GIF__ERROR_UNEXPECTED_EOF -2147483641 // 0x80000007 #define WUFFS_GIF__ERROR_UNEXPECTED_EOF -2147483641 // 0x80000007
#define WUFFS_GIF__SUSPENSION_SHORT_READ 8 // 0x00000008 #define WUFFS_GIF__SUSPENSION_SHORT_READ 8 // 0x00000008
#define WUFFS_GIF__SUSPENSION_SHORT_WRITE 9 // 0x00000009 #define WUFFS_GIF__SUSPENSION_SHORT_WRITE 9 // 0x00000009
#define WUFFS_GIF__ERROR_CANNOT_RETURN_A_SUSPENSION -2147483638 // 0x8000000a
#define WUFFS_GIF__ERROR_BAD_GIF_BLOCK -1105848320 // 0xbe161800 #define WUFFS_GIF__ERROR_BAD_GIF_BLOCK -1105848320 // 0xbe161800
#define WUFFS_GIF__ERROR_BAD_GIF_EXTENSION_LABEL -1105848319 // 0xbe161801 #define WUFFS_GIF__ERROR_BAD_GIF_EXTENSION_LABEL -1105848319 // 0xbe161801
+14 -11
View File
@@ -44,7 +44,7 @@ const (
KIterate KIterate
KJump KJump
KPackageID KPackageID
KReturn KRet
KStatus KStatus
KStruct KStruct
KTypeExpr KTypeExpr
@@ -75,7 +75,7 @@ var kindStrings = [...]string{
KIterate: "KIterate", KIterate: "KIterate",
KJump: "KJump", KJump: "KJump",
KPackageID: "KPackageID", KPackageID: "KPackageID",
KReturn: "KReturn", KRet: "KRet",
KStatus: "KStatus", KStatus: "KStatus",
KStruct: "KStruct", KStruct: "KStruct",
KTypeExpr: "KTypeExpr", KTypeExpr: "KTypeExpr",
@@ -160,7 +160,7 @@ func (n *Node) Iterate() *Iterate { return (*Iterate)(n) }
func (n *Node) Jump() *Jump { return (*Jump)(n) } func (n *Node) Jump() *Jump { return (*Jump)(n) }
func (n *Node) PackageID() *PackageID { return (*PackageID)(n) } func (n *Node) PackageID() *PackageID { return (*PackageID)(n) }
func (n *Node) Raw() *Raw { return (*Raw)(n) } func (n *Node) Raw() *Raw { return (*Raw)(n) }
func (n *Node) Return() *Return { return (*Return)(n) } func (n *Node) Ret() *Ret { return (*Ret)(n) }
func (n *Node) Status() *Status { return (*Status)(n) } func (n *Node) Status() *Status { return (*Status)(n) }
func (n *Node) Struct() *Struct { return (*Struct)(n) } func (n *Node) Struct() *Struct { return (*Struct)(n) }
func (n *Node) TypeExpr() *TypeExpr { return (*TypeExpr)(n) } func (n *Node) TypeExpr() *TypeExpr { return (*TypeExpr)(n) }
@@ -507,16 +507,19 @@ func NewIf(condition *Expr, elseIf *If, bodyIfTrue []*Node, bodyIfFalse []*Node)
} }
} }
// Return is "return LHS": // Ret is "return LHS" or "yield LHS":
// - ID0: <IDReturn|IDYield>
// - LHS: <nil|Expr> // - LHS: <nil|Expr>
type Return Node type Ret Node
func (n *Return) Node() *Node { return (*Node)(n) } func (n *Ret) Node() *Node { return (*Node)(n) }
func (n *Return) Value() *Expr { return n.lhs.Expr() } func (n *Ret) Keyword() t.ID { return n.id0 }
func (n *Ret) Value() *Expr { return n.lhs.Expr() }
func NewReturn(value *Expr) *Return { func NewRet(keyword t.ID, value *Expr) *Ret {
return &Return{ return &Ret{
kind: KReturn, kind: KRet,
id0: keyword,
lhs: value.Node(), lhs: value.Node(),
} }
} }
@@ -663,7 +666,7 @@ const MaxBodyDepth = 255
// - If // - If
// - Iterate // - Iterate
// - Jump // - Jump
// - Return // - Ret
// - Var // - Var
// - While // - While
type Func Node type Func Node
+2
View File
@@ -36,6 +36,7 @@ func (z Status) String() string {
} }
var StatusList = [...]Status{ var StatusList = [...]Status{
// TODO: sort these somehow, when the list has stabilized?
{0, "ok"}, {0, "ok"},
{t.IDError, "bad wuffs version"}, {t.IDError, "bad wuffs version"},
{t.IDError, "bad receiver"}, {t.IDError, "bad receiver"},
@@ -46,6 +47,7 @@ var StatusList = [...]Status{
{t.IDError, "unexpected EOF"}, // Used if reading when closed == true. {t.IDError, "unexpected EOF"}, // Used if reading when closed == true.
{t.IDSuspension, "short read"}, // Used if reading when closed == false. {t.IDSuspension, "short read"}, // Used if reading when closed == false.
{t.IDSuspension, "short write"}, {t.IDSuspension, "short write"},
{t.IDError, "cannot return a suspension"},
} }
var StatusMap = map[string]Status{} var StatusMap = map[string]Status{}
+17 -5
View File
@@ -218,12 +218,22 @@ func bcheckField(tm *t.Map, n *a.Field) error {
} }
func (q *checker) bcheckBlock(block []*a.Node) error { func (q *checker) bcheckBlock(block []*a.Node) error {
loop:
for _, o := range block { for _, o := range block {
if err := q.bcheckStatement(o); err != nil { if err := q.bcheckStatement(o); err != nil {
return err return err
} }
if k := o.Kind(); k == a.KJump || k == a.KReturn { switch o.Kind() {
break case a.KJump:
break loop
case a.KRet:
if o.Ret().Keyword().Key() == t.KeyReturn {
break loop
}
// o is a yield statement.
//
// TODO: invalidate this-, in- and out-related facts because the
// suspension can change the state of this and its fields.
} }
} }
return nil return nil
@@ -276,7 +286,7 @@ func (q *checker) bcheckStatement(n *a.Node) error {
q.facts = q.facts[:0] q.facts = q.facts[:0]
return nil return nil
case a.KReturn: case a.KRet:
// TODO. // TODO.
case a.KVar: case a.KVar:
@@ -475,8 +485,6 @@ func terminates(body []*a.Node) bool {
if len(body) > 0 { if len(body) > 0 {
n := body[len(body)-1] n := body[len(body)-1]
switch n.Kind() { switch n.Kind() {
case a.KReturn, a.KJump:
return true
case a.KIf: case a.KIf:
n := n.If() n := n.If()
for { for {
@@ -492,6 +500,10 @@ func terminates(body []*a.Node) bool {
return len(bif) > 0 return len(bif) > 0
} }
} }
case a.KJump:
return true
case a.KRet:
return n.Ret().Keyword().Key() == t.KeyReturn
} }
return false return false
} }
+2 -2
View File
@@ -156,8 +156,8 @@ func (q *checker) tcheckStatement(n *a.Node) error {
} }
n.SetJumpTarget(jumpTarget) n.SetJumpTarget(jumpTarget)
case a.KReturn: case a.KRet:
n := n.Return() n := n.Ret()
if value := n.Value(); value != nil { if value := n.Value(); value != nil {
if err := q.tcheckExpr(value, 0); err != nil { if err := q.tcheckExpr(value, 0); err != nil {
return err return err
+2 -2
View File
@@ -612,7 +612,7 @@ func (p *parser) parseStatement1() (*a.Node, error) {
} }
return a.NewIterate(label, unroll, vars, asserts, body).Node(), nil return a.NewIterate(label, unroll, vars, asserts, body).Node(), nil
case t.KeyReturn: case t.KeyReturn, t.KeyYield:
p.src = p.src[1:] p.src = p.src[1:]
value, err := (*a.Expr)(nil), error(nil) value, err := (*a.Expr)(nil), error(nil)
if p.peek1().Key() != t.KeySemicolon { if p.peek1().Key() != t.KeySemicolon {
@@ -621,7 +621,7 @@ func (p *parser) parseStatement1() (*a.Node, error) {
return nil, err return nil, err
} }
} }
return a.NewReturn(value).Node(), nil return a.NewRet(x, value).Node(), nil
case t.KeyVar: case t.KeyVar:
p.src = p.src[1:] p.src = p.src[1:]
+3
View File
@@ -243,6 +243,7 @@ const (
KeyConst = Key(IDConst >> KeyShift) KeyConst = Key(IDConst >> KeyShift)
KeyTry = Key(IDTry >> KeyShift) KeyTry = Key(IDTry >> KeyShift)
KeyIterate = Key(IDIterate >> KeyShift) KeyIterate = Key(IDIterate >> KeyShift)
KeyYield = Key(IDYield >> KeyShift)
KeyFalse = Key(IDFalse >> KeyShift) KeyFalse = Key(IDFalse >> KeyShift)
KeyTrue = Key(IDTrue >> KeyShift) KeyTrue = Key(IDTrue >> KeyShift)
@@ -431,6 +432,7 @@ const (
IDConst = ID(0x66<<KeyShift | FlagsOther) IDConst = ID(0x66<<KeyShift | FlagsOther)
IDTry = ID(0x67<<KeyShift | FlagsOther) IDTry = ID(0x67<<KeyShift | FlagsOther)
IDIterate = ID(0x68<<KeyShift | FlagsOther) IDIterate = ID(0x68<<KeyShift | FlagsOther)
IDYield = ID(0x69<<KeyShift | FlagsOther)
IDFalse = ID(0x70<<KeyShift | FlagsLiteral | FlagsImplicitSemicolon) IDFalse = ID(0x70<<KeyShift | FlagsLiteral | FlagsImplicitSemicolon)
IDTrue = ID(0x71<<KeyShift | FlagsLiteral | FlagsImplicitSemicolon) IDTrue = ID(0x71<<KeyShift | FlagsLiteral | FlagsImplicitSemicolon)
@@ -635,6 +637,7 @@ var builtInsByKey = [nBuiltInKeys]struct {
KeyConst: {"const", IDConst}, KeyConst: {"const", IDConst},
KeyTry: {"try", IDTry}, KeyTry: {"try", IDTry},
KeyIterate: {"iterate", IDIterate}, KeyIterate: {"iterate", IDIterate},
KeyYield: {"yield", IDYield},
KeyFalse: {"false", IDFalse}, KeyFalse: {"false", IDFalse},
KeyTrue: {"true", IDTrue}, KeyTrue: {"true", IDTrue},
+3 -4
View File
@@ -127,7 +127,6 @@ pub func flate_decoder.decode?(dst writer1, src reader1)() {
in.dst.mark() in.dst.mark()
var z status = try this.decode_blocks?(dst:in.dst, src:in.src) var z status = try this.decode_blocks?(dst:in.dst, src:in.src)
if not z.is_suspension() { if not z.is_suspension() {
// TODO: rename "return" to "raise"?
return z return z
} }
// TODO: should "since_mark" be "since_mark!", as the return value lets // TODO: should "since_mark" be "since_mark!", as the return value lets
@@ -171,7 +170,7 @@ pub func flate_decoder.decode?(dst writer1, src reader1)() {
this.history_index = (this.history_index & 0x7FFF) + ((n_copied & 0x7FFF) as u32) + already_full this.history_index = (this.history_index & 0x7FFF) + ((n_copied & 0x7FFF) as u32) + already_full
} }
} }
return z yield z
} }
} }
@@ -239,9 +238,9 @@ pri func flate_decoder.decode_uncompressed?(dst writer1, src reader1)() {
length -= n_copied length -= n_copied
if in.dst.available() == 0 { if in.dst.available() == 0 {
// TODO: "closed for writes" instead? // TODO: "closed for writes" instead?
return suspension "short write" yield suspension "short write"
} else { } else {
return suspension "short read" yield suspension "short read"
} }
} }
} }
+3 -7
View File
@@ -212,13 +212,9 @@ pri func flate_decoder.decode_huffman_slow?(dst writer1, src reader1)() {
} }
} }
// TODO: "closed for writes" instead? // TODO: "closed for writes" instead?
return suspension "short write" yield suspension "short write"
// TODO: this "assert false" should be a compiler error.
// This might mean differentiating "return" and "raise".
//
// TODO: invalidate this-related facts because the // TODO: invalidate this-related facts because the
// suspension can change the state of this and its fields. // suspension can change the state of this and its fields.
assert false
} }
// Copy from the start of this.history, if we wrapped around. // Copy from the start of this.history, if we wrapped around.
if hlen > 0 { if hlen > 0 {
@@ -231,7 +227,7 @@ pri func flate_decoder.decode_huffman_slow?(dst writer1, src reader1)() {
hlen -= n_copied hlen -= n_copied
hdist = (hdist + (n_copied & 0x7FFF)) & 0x7FFF hdist = (hdist + (n_copied & 0x7FFF)) & 0x7FFF
// TODO: "closed for writes" instead? // TODO: "closed for writes" instead?
return suspension "short write" yield suspension "short write"
} }
} }
@@ -249,7 +245,7 @@ pri func flate_decoder.decode_huffman_slow?(dst writer1, src reader1)() {
} }
length -= n_copied length -= n_copied
// TODO: "closed for writes" instead? // TODO: "closed for writes" instead?
return suspension "short write" yield suspension "short write"
} }
} }
+1 -1
View File
@@ -54,7 +54,7 @@ pub func zlib_decoder.decode?(dst writer1, src reader1)() {
if z.is_ok() { if z.is_ok() {
break break
} }
return z yield z
} }
if checksum != in.src.read_u32be?() { if checksum != in.src.read_u32be?() {
return error "checksum mismatch" return error "checksum mismatch"
+1 -1
View File
@@ -182,7 +182,7 @@ pri func decoder.decode_id?(dst writer1, src reader1)() {
if (block_size == 0) and (z == suspension "short read") { if (block_size == 0) and (z == suspension "short read") {
break break
} }
return z yield z
} }
} }
} }
+1 -1
View File
@@ -118,7 +118,7 @@ pub func lzw_decoder.decode?(dst writer1, src reader1)() {
} }
s = (s + ((n_copied & 4095) as u32)) & 4095 s = (s + ((n_copied & 4095) as u32)) & 4095
// TODO: "closed for writes" instead? // TODO: "closed for writes" instead?
return suspension "short write" yield suspension "short write"
} }
if save_code <= 4095 { if save_code <= 4095 {