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

+5 -3
View File
@@ -331,11 +331,13 @@ func (h *livenessHelper) doIOManip(r livenesses, n *a.IOManip, depth uint32) err
if err := h.doExpr(r, n.IO()); err != nil {
return err
}
if err := h.doExpr(r, n.Arg1()); err != nil {
return err
if arg1 := n.Arg1(); arg1 != nil {
if err := h.doExpr(r, arg1); err != nil {
return err
}
}
if histPos := n.HistoryPosition(); histPos != nil {
if err := h.doExpr(r, n.HistoryPosition()); err != nil {
if err := h.doExpr(r, histPos); err != nil {
return err
}
}
+10 -7
View File
@@ -314,7 +314,7 @@ func (g *gen) writeStatementIOManip(b *buffer, n *a.IOManip, depth uint32) error
// switch can jump past this initialization??
b.writes("{\n")
{
if n.Keyword() == t.IDIOBind {
if keyword := n.Keyword(); keyword == t.IDIOBind {
b.printf("wuffs_base__io_buffer* %s%d_%s%s = %s%s;\n",
oPrefix, ioBindNum, prefix, name,
prefix, name)
@@ -382,7 +382,7 @@ func (g *gen) writeStatementIOManip(b *buffer, n *a.IOManip, depth uint32) error
}
{
if n.Keyword() == t.IDIOBind {
if keyword := n.Keyword(); keyword == t.IDIOBind {
b.printf("%s%s = %s%d_%s%s;\n",
prefix, name,
oPrefix, ioBindNum, prefix, name)
@@ -395,11 +395,14 @@ func (g *gen) writeStatementIOManip(b *buffer, n *a.IOManip, depth uint32) error
b.printf("%s%s%s = %s%d_%s%s%s;\n",
io1Prefix, prefix, name,
oPrefix, ioBindNum, io1Prefix, prefix, name)
}
b.printf("%s%s%s = %s%d_%s%s%s;\n",
io2Prefix, prefix, name,
oPrefix, ioBindNum, io2Prefix, prefix, name)
if n.Keyword() == t.IDIOLimit {
b.printf("%s%s%s = %s%d_%s%s%s;\n",
io2Prefix, prefix, name,
oPrefix, ioBindNum, io2Prefix, prefix, name)
} else {
b.printf("%s%s%s = %s%d_%s%s%s;\n",
io2Prefix, prefix, name,
oPrefix, ioBindNum, io2Prefix, prefix, name)
b.printf("if (%s%s) {\n", prefix, name)
b.printf("%s%s->meta.closed = %s%d_closed_%s%s;\n",
prefix, name, oPrefix, ioBindNum, prefix, name)
+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)