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

+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 {
loop:
for _, o := range block {
if err := q.bcheckStatement(o); err != nil {
return err
}
if k := o.Kind(); k == a.KJump || k == a.KReturn {
break
switch o.Kind() {
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
@@ -276,7 +286,7 @@ func (q *checker) bcheckStatement(n *a.Node) error {
q.facts = q.facts[:0]
return nil
case a.KReturn:
case a.KRet:
// TODO.
case a.KVar:
@@ -475,8 +485,6 @@ func terminates(body []*a.Node) bool {
if len(body) > 0 {
n := body[len(body)-1]
switch n.Kind() {
case a.KReturn, a.KJump:
return true
case a.KIf:
n := n.If()
for {
@@ -492,6 +500,10 @@ func terminates(body []*a.Node) bool {
return len(bif) > 0
}
}
case a.KJump:
return true
case a.KRet:
return n.Ret().Keyword().Key() == t.KeyReturn
}
return false
}
+2 -2
View File
@@ -156,8 +156,8 @@ func (q *checker) tcheckStatement(n *a.Node) error {
}
n.SetJumpTarget(jumpTarget)
case a.KReturn:
n := n.Return()
case a.KRet:
n := n.Ret()
if value := n.Value(); value != nil {
if err := q.tcheckExpr(value, 0); err != nil {
return err