Add an io_bind keyword

This commit is contained in:
Nigel Tao committed 2018-04-28 11:45:33 +10:00
1 parent 00f660af60
commit 395890c287
11 files changed
+127 -18

No files matched your search

+8
View File
@@ -303,6 +303,14 @@ func (q *checker) bcheckStatement(n *a.Node) error {
case a.KVar:
return q.bcheckVar(n.Var())
case a.KIOBind:
n := n.IOBind()
if err := q.bcheckBlock(n.Body()); err != nil {
return err
}
// TODO: invalidate any facts regarding the io_bind expressions.
return nil
case a.KIterate:
n := n.Iterate()
for _, o := range n.Variables() {
+30
View File
@@ -39,6 +39,11 @@ func (q *checker) tcheckVars(block []*a.Node) error {
}
}
case a.KIOBind:
if err := q.tcheckVars(o.IOBind().Body()); err != nil {
return err
}
case a.KIterate:
if err := q.tcheckVars(o.Iterate().Variables()); err != nil {
return err
@@ -110,6 +115,31 @@ func (q *checker) tcheckStatement(n *a.Node) error {
}
return nil
case a.KIOBind:
n := n.IOBind()
for _, o := range n.InFields() {
if err := q.tcheckExpr(o.Expr(), 0); err != nil {
return err
}
isIOType := false
if typ := o.Expr().MType(); typ.Decorator() == 0 {
if qid := typ.QID(); qid[0] == t.IDBase && (qid[1] == t.IDIOReader || qid[1] == t.IDIOWriter) {
isIOType = true
}
}
if !isIOType {
return fmt.Errorf("check: io_bind expression %q, of type %q, does not have an I/O type",
o.Expr().Str(q.tm), o.Expr().MType().Str(q.tm))
}
}
for _, o := range n.Body() {
// TODO: prohibit jumps (breaks, continues), rets (returns, yields)
// and retry-calling ? methods while inside an io_bind body.
if err := q.tcheckStatement(o); err != nil {
return err
}
}
case a.KIterate:
n := n.Iterate()
unroll := n.UnrollCount()