Add an io_limit keyword

This commit is contained in:
Nigel Tao committed 2018-12-09 09:03:21 +11:00
1 parent 3aff5e6f42
commit e992921dce
10 files changed
+159 -32

No files matched your search

+10 -2
View File
@@ -344,8 +344,16 @@ func (h *resumabilityHelper) doExpr1(r resumabilities, n *a.Expr, sef subExprFil
}
func (h *resumabilityHelper) doIOBind(r resumabilities, n *a.IOBind, depth uint32) error {
// Ignore the IOBind fields, as they should be I/O types and therefore not
// resumable.
if n.IO() != nil {
if err := h.doExpr(r, n.IO()); err != nil {
return err
}
}
if n.Limit() != nil {
if err := h.doExpr(r, n.Limit()); err != nil {
return err
}
}
return h.doBlock(r, n.Body(), depth)
}
+10
View File
@@ -226,6 +226,9 @@ func (g *gen) writeStatementAssign(b *buffer,
func (g *gen) writeStatementIOBind(b *buffer, n *a.IOBind, depth uint32) error {
inFields := n.InFields()
if n.Keyword() == t.IDIOLimit {
inFields = []*a.Node{n.IO().AsNode()}
}
if g.currFunk.ioBinds > maxIOBinds || len(inFields) > maxIOBindInFields {
return fmt.Errorf("too many temporary variables required")
@@ -251,6 +254,13 @@ func (g *gen) writeStatementIOBind(b *buffer, n *a.IOBind, depth uint32) error {
b.printf("wuffs_base__io_%s %s%d_%s%s = %s%s;\n",
cTyp, oPrefix, ioBindNum, prefix, name, prefix, name)
if n.Keyword() == t.IDIOLimit {
b.printf("wuffs_base__io_%s__set_limit(&%s%s, iop_%s%s,\n", cTyp, prefix, name, prefix, name)
if err := g.writeExpr(b, n.Limit(), 0); err != nil {
return err
}
b.printf(");\n")
}
// TODO: save / restore all iop vars, not just for local IO vars? How
// does this work if the io_bind body advances these pointers, either
// directly or by calling other funcs?