Add choose

wuffs_png_decode_filter_1_sub/clang9       905MB/s ± 0%  1339MB/s ± 0%  +48.05%  (p=0.008 n=5+5)
wuffs_png_decode_filter_1_sub/gcc10       1.12GB/s ± 0%  1.85GB/s ± 0%  +64.80%  (p=0.016 n=5+4)
This commit is contained in:
Nigel Tao committed 2021-01-06 23:16:16 +11:00
1 parent 364c396ae8
commit beaf3ef11f
11 files changed
+235 -22

No files matched your search

+28
View File
@@ -63,6 +63,11 @@ func (q *checker) tcheckStatement(n *a.Node) error {
return err
}
case a.KChoose:
if err := q.tcheckChoose(n.AsChoose()); err != nil {
return err
}
case a.KIf:
for n := n.AsIf(); n != nil; n = n.ElseIf() {
cond := n.Condition()
@@ -1061,6 +1066,29 @@ swtch:
return nil
}
func (q *checker) tcheckChoose(n *a.Choose) error {
qqid := q.astFunc.QQID()
fQQID := t.QQID{qqid[0], qqid[1], n.Name()}
f := q.c.funcs[fQQID]
if f == nil {
return fmt.Errorf("check: no function named %q", fQQID.Str(q.tm))
}
for _, o := range n.Args() {
o := o.AsExpr()
gQQID := t.QQID{qqid[0], qqid[1], o.Ident()}
g := q.c.funcs[gQQID]
if g == nil {
return fmt.Errorf("check: no function named %q", gQQID.Str(q.tm))
} else if err := f.CheckChooseCompatible(g); err != nil {
return fmt.Errorf("check: incompatible choose functions %q and %q: %v",
fQQID.Str(q.tm), gQQID.Str(q.tm), err)
}
o.SetMBounds(bounds{one, one})
o.SetMType(typeExprNonNullptr)
}
return nil
}
var comparisonOps = [...]bool{
t.IDXBinaryNotEq: true,
t.IDXBinaryLessThan: true,