mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 08:32:11 +01:00
Remove the obsolete Effect.RootCause concept
This commit is contained in:
1 parent
9741eada02
commit
5cae1f8c82
6 files changed
+19
-60
No files matched your search
@@ -27,15 +27,10 @@ func (g *gen) writeExpr(b *buffer, n *a.Expr, rp replacementPolicy, depth uint32
|
||||
}
|
||||
depth++
|
||||
|
||||
if rp == replaceCallSuspendibles && n.Effect().RootCause() && n.Effect().Coroutine() {
|
||||
if rp == replaceCallSuspendibles && n.Effect().Coroutine() {
|
||||
if g.currFunk.tempR >= g.currFunk.tempW {
|
||||
return fmt.Errorf("internal error: temporary variable count out of sync")
|
||||
}
|
||||
// TODO: check that this works with nested call-suspendibles:
|
||||
// "foo?().bar().qux?()(p?(), q?())".
|
||||
//
|
||||
// Also be aware of evaluation order in the presence of side effects:
|
||||
// in "foo(a?(), b!(), c?())", b should be called between a and c.
|
||||
b.printf("%s%d", tPrefix, g.currFunk.tempR)
|
||||
g.currFunk.tempR++
|
||||
return nil
|
||||
|
||||
@@ -285,21 +285,16 @@ func (h *resumabilityHelper) doExpr1(r resumabilities, n *a.Expr, sef subExprFil
|
||||
|
||||
processOnlySubExprs := false
|
||||
if sef != subExprFilterNone {
|
||||
const mask = a.EffectCoroutine | a.EffectRootCause
|
||||
switch sef {
|
||||
case subExprFilterBeforeCoroutine:
|
||||
switch n.Effect() & mask {
|
||||
case a.EffectCoroutine | a.EffectRootCause:
|
||||
sef = subExprFilterNone
|
||||
case a.EffectCoroutine:
|
||||
// No-op.
|
||||
default:
|
||||
if !n.Effect().Coroutine() {
|
||||
return nil
|
||||
}
|
||||
sef = subExprFilterNone
|
||||
processOnlySubExprs = true
|
||||
|
||||
case subExprFilterDuringCoroutine:
|
||||
if n.Effect()&mask == mask {
|
||||
if n.Effect().Coroutine() {
|
||||
switch n.Operator() {
|
||||
case t.IDOpenParen:
|
||||
r.raiseNoneToWeak()
|
||||
@@ -311,7 +306,7 @@ func (h *resumabilityHelper) doExpr1(r resumabilities, n *a.Expr, sef subExprFil
|
||||
processOnlySubExprs = true
|
||||
|
||||
case subExprFilterAfterCoroutine:
|
||||
if n.Effect()&mask == mask {
|
||||
if n.Effect().Coroutine() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ func (g *gen) writeStatementExpr(b *buffer, n *a.Expr, depth uint32) error {
|
||||
// statements.
|
||||
//
|
||||
// TODO: clean up how this and writeSuspendibles interact.
|
||||
derived := n.Effect().RootCause() && n.Effect().Optional() && !n.Effect().Coroutine()
|
||||
derived := n.Effect().Optional() && !n.Effect().Coroutine()
|
||||
if derived {
|
||||
if err := g.writeSaveExprDerivedVars(b, n); err != nil {
|
||||
return err
|
||||
@@ -171,13 +171,11 @@ func (g *gen) writeStatementExpr(b *buffer, n *a.Expr, depth uint32) error {
|
||||
}
|
||||
|
||||
checkStatus := false
|
||||
if n.Effect().RootCause() {
|
||||
if n.Effect().Coroutine() {
|
||||
return nil
|
||||
} else if n.Effect().Optional() {
|
||||
b.writes("status = ")
|
||||
checkStatus = true
|
||||
}
|
||||
if effect := n.Effect(); effect.Coroutine() {
|
||||
return nil
|
||||
} else if effect.Optional() {
|
||||
b.writes("status = ")
|
||||
checkStatus = true
|
||||
}
|
||||
if err := g.writeExpr(b, n, replaceCallSuspendibles, depth); err != nil {
|
||||
return err
|
||||
@@ -531,26 +529,6 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32, eqQuesti
|
||||
}
|
||||
depth++
|
||||
|
||||
// The evaluation order for suspendible calls (which can have side effects)
|
||||
// is important here: LHS, MHS, RHS, Args and finally the node itself.
|
||||
if e := n.Effect(); !e.RootCause() || !e.Coroutine() {
|
||||
for _, o := range n.AsNode().AsRaw().SubNodes() {
|
||||
if o != nil && o.Kind() == a.KExpr {
|
||||
if err := g.writeCallSuspendibles(b, o.AsExpr(), depth, false); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, o := range n.Args() {
|
||||
if o != nil && o.Kind() == a.KExpr {
|
||||
if err := g.writeCallSuspendibles(b, o.AsExpr(), depth, false); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := g.writeSaveExprDerivedVars(b, n); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
+6
-11
@@ -111,11 +111,7 @@ const (
|
||||
|
||||
EffectSubExprHasEffect = Effect(0x08)
|
||||
|
||||
// TODO: will we need an EffectRootCause if every ?-call requires a "do" or
|
||||
// "try"?
|
||||
effectMaskNonRootCause = Effect(0x7F)
|
||||
|
||||
EffectRootCause = Effect(0x80)
|
||||
effectMask = Effect(0xFF)
|
||||
)
|
||||
|
||||
func (e Effect) AsFlags() Flags { return Flags(e) }
|
||||
@@ -126,10 +122,9 @@ func (e Effect) Impure() bool { return e&EffectImpure != 0 }
|
||||
func (e Effect) Optional() bool { return e&EffectOptional != 0 }
|
||||
func (e Effect) Coroutine() bool { return e&EffectCoroutine != 0 }
|
||||
func (e Effect) SubExprHasEffect() bool { return e&EffectSubExprHasEffect != 0 }
|
||||
func (e Effect) RootCause() bool { return e&EffectRootCause != 0 }
|
||||
|
||||
func (e Effect) String() string {
|
||||
switch e & effectMaskNonRootCause {
|
||||
switch e & effectMask {
|
||||
case 0:
|
||||
return ""
|
||||
case EffectImpure:
|
||||
@@ -357,16 +352,16 @@ func (n *Expr) SetMType(x *TypeExpr) { n.mType = x }
|
||||
func NewExpr(flags Flags, operator t.ID, statusPkg t.ID, ident t.ID, lhs *Node, mhs *Node, rhs *Node, args []*Node) *Expr {
|
||||
subExprEffect := Flags(0)
|
||||
if lhs != nil {
|
||||
subExprEffect |= lhs.flags & Flags(effectMaskNonRootCause)
|
||||
subExprEffect |= lhs.flags & Flags(effectMask)
|
||||
}
|
||||
if mhs != nil {
|
||||
subExprEffect |= mhs.flags & Flags(effectMaskNonRootCause)
|
||||
subExprEffect |= mhs.flags & Flags(effectMask)
|
||||
}
|
||||
if rhs != nil {
|
||||
subExprEffect |= rhs.flags & Flags(effectMaskNonRootCause)
|
||||
subExprEffect |= rhs.flags & Flags(effectMask)
|
||||
}
|
||||
for _, o := range args {
|
||||
subExprEffect |= o.flags & Flags(effectMaskNonRootCause)
|
||||
subExprEffect |= o.flags & Flags(effectMask)
|
||||
}
|
||||
if subExprEffect != 0 {
|
||||
flags |= subExprEffect | EffectSubExprHasEffect.AsFlags()
|
||||
|
||||
+1
-1
@@ -531,7 +531,7 @@ func (q *checker) tcheckExprCall(n *a.Expr, depth uint32) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if ne, fe := n.Effect(), f.Effect(); ne|a.EffectRootCause != fe|a.EffectRootCause {
|
||||
if ne, fe := n.Effect(), f.Effect(); ne != fe {
|
||||
return fmt.Errorf("check: %q has effect %q but %q has effect %q",
|
||||
n.Str(q.tm), ne, f.QQID().Str(q.tm), fe)
|
||||
}
|
||||
|
||||
+1
-5
@@ -1022,11 +1022,7 @@ func (p *parser) parseOperand() (*a.Expr, error) {
|
||||
return lhs, nil
|
||||
|
||||
case t.IDExclam, t.IDQuestion:
|
||||
e := p.parseEffect()
|
||||
if e != 0 {
|
||||
e |= a.EffectRootCause
|
||||
}
|
||||
flags |= e.AsFlags()
|
||||
flags |= p.parseEffect().AsFlags()
|
||||
fallthrough
|
||||
|
||||
case t.IDOpenParen:
|
||||
|
||||
Reference in new issue
Block a user