mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-22 00:47:28 +01:00
Add io_bind history_position arg
This commit is contained in:
1 parent
b60a2cacd9
commit
28a54baa19
11 files changed
+87
-24
No files matched your search
+11
-8
@@ -583,26 +583,29 @@ func NewField(flags Flags, name t.ID, xType *TypeExpr) *Field {
|
||||
}
|
||||
}
|
||||
|
||||
// IOBind is "io_bind (io:LHS, data:MHS) { List2 }" or "io_limit (io:LHS,
|
||||
// limit:MHS) { List2 }":
|
||||
// IOBind is "io_bind (io:LHS, data:MHS, history_position:RHS) { List2 }" or
|
||||
// "io_limit (io:LHS, limit:MHS) { List2 }":
|
||||
// - ID0: <IDIOBind|IDIOLimit>
|
||||
// - LHS: <Expr>
|
||||
// - MHS: <Expr>
|
||||
// - RHS: <Expr>
|
||||
// - List2: <Statement> body
|
||||
type IOBind Node
|
||||
|
||||
func (n *IOBind) AsNode() *Node { return (*Node)(n) }
|
||||
func (n *IOBind) Keyword() t.ID { return n.id0 }
|
||||
func (n *IOBind) IO() *Expr { return n.lhs.AsExpr() }
|
||||
func (n *IOBind) Arg1() *Expr { return n.mhs.AsExpr() }
|
||||
func (n *IOBind) Body() []*Node { return n.list2 }
|
||||
func (n *IOBind) AsNode() *Node { return (*Node)(n) }
|
||||
func (n *IOBind) Keyword() t.ID { return n.id0 }
|
||||
func (n *IOBind) IO() *Expr { return n.lhs.AsExpr() }
|
||||
func (n *IOBind) Arg1() *Expr { return n.mhs.AsExpr() }
|
||||
func (n *IOBind) HistoryPosition() *Expr { return n.rhs.AsExpr() }
|
||||
func (n *IOBind) Body() []*Node { return n.list2 }
|
||||
|
||||
func NewIOBind(keyword t.ID, io *Expr, arg1 *Expr, body []*Node) *IOBind {
|
||||
func NewIOBind(keyword t.ID, io *Expr, arg1 *Expr, historyPosition *Expr, body []*Node) *IOBind {
|
||||
return &IOBind{
|
||||
kind: KIOBind,
|
||||
id0: keyword,
|
||||
lhs: io.AsNode(),
|
||||
mhs: arg1.AsNode(),
|
||||
rhs: historyPosition.AsNode(),
|
||||
list2: body,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,6 +258,11 @@ func (q *checker) bcheckStatement(n *a.Node) error {
|
||||
if _, err := q.bcheckExpr(n.Arg1(), 0); err != nil {
|
||||
return err
|
||||
}
|
||||
if histPos := n.HistoryPosition(); histPos != nil {
|
||||
if _, err := q.bcheckExpr(histPos, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := q.bcheckBlock(n.Body()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -171,6 +171,16 @@ func (q *checker) tcheckStatement(n *a.Node) error {
|
||||
n.Keyword().Str(q.tm), n.Arg1().Str(q.tm), typ.Str(q.tm), arg1Typ.Str(q.tm))
|
||||
}
|
||||
|
||||
if n.Keyword() == t.IDIOBind {
|
||||
if err := q.tcheckExpr(n.HistoryPosition(), 0); err != nil {
|
||||
return err
|
||||
}
|
||||
if typ := n.HistoryPosition().MType(); !typ.IsIdeal() && !typ.EqIgnoringRefinements(typeExprU64) {
|
||||
return fmt.Errorf("check: %s expression %q, of type %q, does not have type %q",
|
||||
n.Keyword().Str(q.tm), n.HistoryPosition().Str(q.tm), typ.Str(q.tm), typeExprU64.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.
|
||||
|
||||
+31
-1
@@ -1123,6 +1123,36 @@ func (p *parser) parseIOBindNode() (*a.Node, error) {
|
||||
io.Str(p.tm), p.filename, p.line())
|
||||
}
|
||||
|
||||
histPos := (*a.Expr)(nil)
|
||||
if keyword == t.IDIOBind {
|
||||
if x := p.peek1(); x != t.IDComma {
|
||||
got := p.tm.ByID(x)
|
||||
return nil, fmt.Errorf(`parse: expected ",", got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
|
||||
if x := p.peek1(); x != t.IDHistoryPosition {
|
||||
got := p.tm.ByID(x)
|
||||
return nil, fmt.Errorf(`parse: expected "history_position", got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
|
||||
if x := p.peek1(); x != t.IDColon {
|
||||
got := p.tm.ByID(x)
|
||||
return nil, fmt.Errorf(`parse: expected ":", got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
|
||||
histPos, err = p.parseExpr()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if histPos.Effect() != 0 {
|
||||
return nil, fmt.Errorf(`parse: argument %q is not effect-free at %s:%d`,
|
||||
io.Str(p.tm), p.filename, p.line())
|
||||
}
|
||||
}
|
||||
|
||||
if x := p.peek1(); x != t.IDCloseParen {
|
||||
got := p.tm.ByID(x)
|
||||
return nil, fmt.Errorf(`parse: expected ")", got %q at %s:%d`, got, p.filename, p.line())
|
||||
@@ -1134,7 +1164,7 @@ func (p *parser) parseIOBindNode() (*a.Node, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return a.NewIOBind(keyword, io, arg1, body).AsNode(), nil
|
||||
return a.NewIOBind(keyword, io, arg1, histPos, body).AsNode(), nil
|
||||
}
|
||||
|
||||
func (p *parser) parseIf() (*a.If, error) {
|
||||
|
||||
Reference in new issue
Block a user