mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 00:55:11 +01:00
Add an "iterate" keyword.
This commit is contained in:
1 parent
7b18295688
commit
51bd52239b
12 files changed
+253
-53
No files matched your search
+32
-12
@@ -265,22 +265,24 @@ func (q *checker) bcheckStatement(n *a.Node) error {
|
||||
// TODO.
|
||||
|
||||
case a.KVar:
|
||||
n := n.Var()
|
||||
if innTyp := n.XType().Innermost(); innTyp.IsRefined() {
|
||||
if _, _, err := typeBounds(q.tm, innTyp); err != nil {
|
||||
return q.bcheckVar(n.Var())
|
||||
|
||||
case a.KIterate:
|
||||
n := n.Iterate()
|
||||
for _, o := range n.Variables() {
|
||||
if err := q.bcheckVar(o.Var()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
lhs := a.NewExpr(a.FlagsTypeChecked, 0, n.Name(), nil, nil, nil, nil)
|
||||
lhs.SetMType(n.XType())
|
||||
rhs := n.Value()
|
||||
if rhs == nil {
|
||||
// "var x T" has an implicit "= 0".
|
||||
//
|
||||
// TODO: check that T is an integer type.
|
||||
rhs = zeroExpr
|
||||
// TODO: this isn't right, as the body is a loop, not an
|
||||
// execute-exactly-once block. We should have pre / inv / post
|
||||
// conditions, a la bcheckWhile.
|
||||
for _, o := range n.Body() {
|
||||
if err := q.bcheckStatement(o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return q.bcheckAssignment(lhs, t.IDEq, rhs)
|
||||
return nil
|
||||
|
||||
case a.KWhile:
|
||||
return q.bcheckWhile(n.While())
|
||||
@@ -636,6 +638,24 @@ func (q *checker) bcheckWhile(n *a.While) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (q *checker) bcheckVar(n *a.Var) error {
|
||||
if innTyp := n.XType().Innermost(); innTyp.IsRefined() {
|
||||
if _, _, err := typeBounds(q.tm, innTyp); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
lhs := a.NewExpr(a.FlagsTypeChecked, 0, n.Name(), nil, nil, nil, nil)
|
||||
lhs.SetMType(n.XType())
|
||||
rhs := n.Value()
|
||||
if rhs == nil {
|
||||
// "var x T" has an implicit "= 0".
|
||||
//
|
||||
// TODO: check that T is an integer type.
|
||||
rhs = zeroExpr
|
||||
}
|
||||
return q.bcheckAssignment(lhs, t.IDEq, rhs)
|
||||
}
|
||||
|
||||
func (q *checker) bcheckExpr(n *a.Expr, depth uint32) (*big.Int, *big.Int, error) {
|
||||
if depth > a.MaxExprDepth {
|
||||
return nil, nil, fmt.Errorf("check: expression recursion depth too large")
|
||||
|
||||
Reference in new issue
Block a user