mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 00:55: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++
|
depth++
|
||||||
|
|
||||||
if rp == replaceCallSuspendibles && n.Effect().RootCause() && n.Effect().Coroutine() {
|
if rp == replaceCallSuspendibles && n.Effect().Coroutine() {
|
||||||
if g.currFunk.tempR >= g.currFunk.tempW {
|
if g.currFunk.tempR >= g.currFunk.tempW {
|
||||||
return fmt.Errorf("internal error: temporary variable count out of sync")
|
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)
|
b.printf("%s%d", tPrefix, g.currFunk.tempR)
|
||||||
g.currFunk.tempR++
|
g.currFunk.tempR++
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -285,21 +285,16 @@ func (h *resumabilityHelper) doExpr1(r resumabilities, n *a.Expr, sef subExprFil
|
|||||||
|
|
||||||
processOnlySubExprs := false
|
processOnlySubExprs := false
|
||||||
if sef != subExprFilterNone {
|
if sef != subExprFilterNone {
|
||||||
const mask = a.EffectCoroutine | a.EffectRootCause
|
|
||||||
switch sef {
|
switch sef {
|
||||||
case subExprFilterBeforeCoroutine:
|
case subExprFilterBeforeCoroutine:
|
||||||
switch n.Effect() & mask {
|
if !n.Effect().Coroutine() {
|
||||||
case a.EffectCoroutine | a.EffectRootCause:
|
|
||||||
sef = subExprFilterNone
|
|
||||||
case a.EffectCoroutine:
|
|
||||||
// No-op.
|
|
||||||
default:
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
sef = subExprFilterNone
|
||||||
processOnlySubExprs = true
|
processOnlySubExprs = true
|
||||||
|
|
||||||
case subExprFilterDuringCoroutine:
|
case subExprFilterDuringCoroutine:
|
||||||
if n.Effect()&mask == mask {
|
if n.Effect().Coroutine() {
|
||||||
switch n.Operator() {
|
switch n.Operator() {
|
||||||
case t.IDOpenParen:
|
case t.IDOpenParen:
|
||||||
r.raiseNoneToWeak()
|
r.raiseNoneToWeak()
|
||||||
@@ -311,7 +306,7 @@ func (h *resumabilityHelper) doExpr1(r resumabilities, n *a.Expr, sef subExprFil
|
|||||||
processOnlySubExprs = true
|
processOnlySubExprs = true
|
||||||
|
|
||||||
case subExprFilterAfterCoroutine:
|
case subExprFilterAfterCoroutine:
|
||||||
if n.Effect()&mask == mask {
|
if n.Effect().Coroutine() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ func (g *gen) writeStatementExpr(b *buffer, n *a.Expr, depth uint32) error {
|
|||||||
// statements.
|
// statements.
|
||||||
//
|
//
|
||||||
// TODO: clean up how this and writeSuspendibles interact.
|
// 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 derived {
|
||||||
if err := g.writeSaveExprDerivedVars(b, n); err != nil {
|
if err := g.writeSaveExprDerivedVars(b, n); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -171,13 +171,11 @@ func (g *gen) writeStatementExpr(b *buffer, n *a.Expr, depth uint32) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
checkStatus := false
|
checkStatus := false
|
||||||
if n.Effect().RootCause() {
|
if effect := n.Effect(); effect.Coroutine() {
|
||||||
if n.Effect().Coroutine() {
|
return nil
|
||||||
return nil
|
} else if effect.Optional() {
|
||||||
} else if n.Effect().Optional() {
|
b.writes("status = ")
|
||||||
b.writes("status = ")
|
checkStatus = true
|
||||||
checkStatus = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if err := g.writeExpr(b, n, replaceCallSuspendibles, depth); err != nil {
|
if err := g.writeExpr(b, n, replaceCallSuspendibles, depth); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -531,26 +529,6 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32, eqQuesti
|
|||||||
}
|
}
|
||||||
depth++
|
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 {
|
if err := g.writeSaveExprDerivedVars(b, n); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-11
@@ -111,11 +111,7 @@ const (
|
|||||||
|
|
||||||
EffectSubExprHasEffect = Effect(0x08)
|
EffectSubExprHasEffect = Effect(0x08)
|
||||||
|
|
||||||
// TODO: will we need an EffectRootCause if every ?-call requires a "do" or
|
effectMask = Effect(0xFF)
|
||||||
// "try"?
|
|
||||||
effectMaskNonRootCause = Effect(0x7F)
|
|
||||||
|
|
||||||
EffectRootCause = Effect(0x80)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (e Effect) AsFlags() Flags { return Flags(e) }
|
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) Optional() bool { return e&EffectOptional != 0 }
|
||||||
func (e Effect) Coroutine() bool { return e&EffectCoroutine != 0 }
|
func (e Effect) Coroutine() bool { return e&EffectCoroutine != 0 }
|
||||||
func (e Effect) SubExprHasEffect() bool { return e&EffectSubExprHasEffect != 0 }
|
func (e Effect) SubExprHasEffect() bool { return e&EffectSubExprHasEffect != 0 }
|
||||||
func (e Effect) RootCause() bool { return e&EffectRootCause != 0 }
|
|
||||||
|
|
||||||
func (e Effect) String() string {
|
func (e Effect) String() string {
|
||||||
switch e & effectMaskNonRootCause {
|
switch e & effectMask {
|
||||||
case 0:
|
case 0:
|
||||||
return ""
|
return ""
|
||||||
case EffectImpure:
|
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 {
|
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)
|
subExprEffect := Flags(0)
|
||||||
if lhs != nil {
|
if lhs != nil {
|
||||||
subExprEffect |= lhs.flags & Flags(effectMaskNonRootCause)
|
subExprEffect |= lhs.flags & Flags(effectMask)
|
||||||
}
|
}
|
||||||
if mhs != nil {
|
if mhs != nil {
|
||||||
subExprEffect |= mhs.flags & Flags(effectMaskNonRootCause)
|
subExprEffect |= mhs.flags & Flags(effectMask)
|
||||||
}
|
}
|
||||||
if rhs != nil {
|
if rhs != nil {
|
||||||
subExprEffect |= rhs.flags & Flags(effectMaskNonRootCause)
|
subExprEffect |= rhs.flags & Flags(effectMask)
|
||||||
}
|
}
|
||||||
for _, o := range args {
|
for _, o := range args {
|
||||||
subExprEffect |= o.flags & Flags(effectMaskNonRootCause)
|
subExprEffect |= o.flags & Flags(effectMask)
|
||||||
}
|
}
|
||||||
if subExprEffect != 0 {
|
if subExprEffect != 0 {
|
||||||
flags |= subExprEffect | EffectSubExprHasEffect.AsFlags()
|
flags |= subExprEffect | EffectSubExprHasEffect.AsFlags()
|
||||||
|
|||||||
+1
-1
@@ -531,7 +531,7 @@ func (q *checker) tcheckExprCall(n *a.Expr, depth uint32) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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",
|
return fmt.Errorf("check: %q has effect %q but %q has effect %q",
|
||||||
n.Str(q.tm), ne, f.QQID().Str(q.tm), fe)
|
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
|
return lhs, nil
|
||||||
|
|
||||||
case t.IDExclam, t.IDQuestion:
|
case t.IDExclam, t.IDQuestion:
|
||||||
e := p.parseEffect()
|
flags |= p.parseEffect().AsFlags()
|
||||||
if e != 0 {
|
|
||||||
e |= a.EffectRootCause
|
|
||||||
}
|
|
||||||
flags |= e.AsFlags()
|
|
||||||
fallthrough
|
fallthrough
|
||||||
|
|
||||||
case t.IDOpenParen:
|
case t.IDOpenParen:
|
||||||
|
|||||||
Reference in new issue
Block a user