lang: refactor anticipating io_forget_history

This commit is contained in:
Nigel Tao committed 2024-02-09 14:55:35 +11:00
1 parent c21cc95713
commit e8af2d0635
5 files changed
+60 -44

No files matched your search

+4 -2
View File
@@ -265,8 +265,10 @@ func (q *checker) bcheckStatement(n *a.Node) error {
if _, err := q.bcheckExpr(n.IO(), 0); err != nil {
return err
}
if _, err := q.bcheckExpr(n.Arg1(), 0); err != nil {
return err
if arg1 := n.Arg1(); arg1 != nil {
if _, err := q.bcheckExpr(arg1, 0); err != nil {
return err
}
}
if histPos := n.HistoryPosition(); histPos != nil {
if _, err := q.bcheckExpr(histPos, 0); err != nil {
+13 -8
View File
@@ -160,16 +160,21 @@ func (q *checker) tcheckStatement(n *a.Node) error {
n.Keyword().Str(q.tm), n.IO().Str(q.tm), typ.Str(q.tm))
}
arg1Typ := typeExprSliceU8
if n.Keyword() == t.IDIOLimit {
arg1Typ := (*a.TypeExpr)(nil)
switch n.Keyword() {
case t.IDIOBind:
arg1Typ = typeExprSliceU8
case t.IDIOLimit:
arg1Typ = typeExprU64
}
if err := q.tcheckExpr(n.Arg1(), 0); err != nil {
return err
}
if typ := n.Arg1().MType(); !typ.EqIgnoringRefinementsLHSReadOnly(arg1Typ) {
return fmt.Errorf("check: %s expression %q, of type %q, does not have type %q",
n.Keyword().Str(q.tm), n.Arg1().Str(q.tm), typ.Str(q.tm), arg1Typ.Str(q.tm))
if arg1Typ != nil {
if err := q.tcheckExpr(n.Arg1(), 0); err != nil {
return err
}
if typ := n.Arg1().MType(); !typ.EqIgnoringRefinementsLHSReadOnly(arg1Typ) {
return fmt.Errorf("check: %s expression %q, of type %q, does not have type %q",
n.Keyword().Str(q.tm), n.Arg1().Str(q.tm), typ.Str(q.tm), arg1Typ.Str(q.tm))
}
}
if n.Keyword() == t.IDIOBind {
+28 -24
View File
@@ -1080,13 +1080,14 @@ func (p *parser) parseIOManipNode() (*a.Node, error) {
}
arg1Name := t.ID(0)
if keyword == t.IDIOBind {
switch keyword {
case t.IDIOBind:
arg1Name = t.IDData
if io.Operator() != 0 {
return nil, fmt.Errorf(`parse: invalid %s argument %q at %s:%d`,
keyword.Str(p.tm), io.Str(p.tm), p.filename, p.line())
}
} else {
case t.IDIOLimit:
arg1Name = t.IDLimit
if (io.Operator() != 0) && (io.IsArgsDotFoo() == 0) {
return nil, fmt.Errorf(`parse: invalid %s argument %q at %s:%d`,
@@ -1094,31 +1095,34 @@ func (p *parser) parseIOManipNode() (*a.Node, error) {
}
}
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:]
arg1 := (*a.Expr)(nil)
if arg1Name != 0 {
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 != arg1Name {
got := p.tm.ByID(x)
return nil, fmt.Errorf(`parse: expected %q, got %q at %s:%d`, arg1Name.Str(p.tm), got, p.filename, p.line())
}
p.src = p.src[1:]
if x := p.peek1(); x != arg1Name {
got := p.tm.ByID(x)
return nil, fmt.Errorf(`parse: expected %q, got %q at %s:%d`, arg1Name.Str(p.tm), 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:]
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:]
arg1, err := p.parseExpr()
if err != nil {
return nil, err
}
if arg1.Effect() != 0 {
return nil, fmt.Errorf(`parse: argument %q is not effect-free at %s:%d`,
io.Str(p.tm), p.filename, p.line())
arg1, err = p.parseExpr()
if err != nil {
return nil, err
}
if arg1.Effect() != 0 {
return nil, fmt.Errorf(`parse: argument %q is not effect-free at %s:%d`,
io.Str(p.tm), p.filename, p.line())
}
}
histPos := (*a.Expr)(nil)