mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Introduce finer-grained effects
This commit is contained in:
1 parent
77e538aec8
commit
0a47966e72
12 files changed
+129
-115
No files matched your search
@@ -647,7 +647,7 @@ func (g *gen) writeStruct(b *buffer, n *a.Struct) error {
|
||||
b.writes("//\n")
|
||||
b.writes("// It is a struct, not a struct*, so that it can be stack allocated.\n")
|
||||
b.writes("struct {\n")
|
||||
if n.Suspendible() {
|
||||
if n.Optional() {
|
||||
b.printf("wuffs_base__status status;\n")
|
||||
b.writes("uint32_t magic;\n")
|
||||
b.writes("\n")
|
||||
@@ -661,7 +661,7 @@ func (g *gen) writeStruct(b *buffer, n *a.Struct) error {
|
||||
b.writes(";\n")
|
||||
}
|
||||
|
||||
if n.Suspendible() {
|
||||
if n.Optional() {
|
||||
b.writeb('\n')
|
||||
for _, file := range g.files {
|
||||
for _, tld := range file.TopLevelDecls() {
|
||||
@@ -669,7 +669,8 @@ func (g *gen) writeStruct(b *buffer, n *a.Struct) error {
|
||||
continue
|
||||
}
|
||||
o := tld.AsFunc()
|
||||
if o.Receiver() != n.QID() || !o.Suspendible() {
|
||||
// XXX: s/Optional/Coroutine/
|
||||
if o.Receiver() != n.QID() || !o.Effect().Optional() {
|
||||
continue
|
||||
}
|
||||
k := g.funks[o.QQID()]
|
||||
@@ -871,7 +872,7 @@ func (g *gen) writeInitializerSignature(b *buffer, n *a.Struct, public bool) err
|
||||
}
|
||||
|
||||
func (g *gen) writeInitializerPrototype(b *buffer, n *a.Struct) error {
|
||||
if !n.Suspendible() {
|
||||
if !n.Optional() {
|
||||
return nil
|
||||
}
|
||||
if err := g.writeInitializerSignature(b, n, n.Public()); err != nil {
|
||||
@@ -882,7 +883,7 @@ func (g *gen) writeInitializerPrototype(b *buffer, n *a.Struct) error {
|
||||
}
|
||||
|
||||
func (g *gen) writeInitializerImpl(b *buffer, n *a.Struct) error {
|
||||
if !n.Suspendible() {
|
||||
if !n.Optional() {
|
||||
return nil
|
||||
}
|
||||
if err := g.writeInitializerSignature(b, n, false); err != nil {
|
||||
|
||||
@@ -30,7 +30,8 @@ func (g *gen) writeExpr(b *buffer, n *a.Expr, rp replacementPolicy, depth uint32
|
||||
}
|
||||
depth++
|
||||
|
||||
if rp == replaceCallSuspendibles && n.CallSuspendible() {
|
||||
// XXX: s/Optional/Coroutine/
|
||||
if rp == replaceCallSuspendibles && n.Effect().RootCause() && n.Effect().Optional() {
|
||||
if g.currFunk.tempR >= g.currFunk.tempW {
|
||||
return fmt.Errorf("internal error: temporary variable count out of sync")
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ type funk struct {
|
||||
tempW uint32
|
||||
tempR uint32
|
||||
public bool
|
||||
suspendible bool
|
||||
suspendible bool // TODO: rename to coroutine.
|
||||
usesScratch bool
|
||||
hasGotoOK bool
|
||||
shortReads []string
|
||||
@@ -86,7 +86,8 @@ func (g *gen) writeFuncSignature(b *buffer, n *a.Func, cpp uint32) error {
|
||||
}
|
||||
|
||||
// TODO: write n's return values.
|
||||
if n.Suspendible() {
|
||||
// XXX: s/Optional/Coroutine/
|
||||
if n.Effect().Optional() {
|
||||
b.writes("wuffs_base__status ")
|
||||
} else if out := n.Out(); out == nil {
|
||||
// TODO: wuffs_base__empty_struct.
|
||||
@@ -174,7 +175,7 @@ func (g *gen) gatherFuncImpl(_ *buffer, n *a.Func) error {
|
||||
astFunc: n,
|
||||
cName: g.funcCName(n),
|
||||
public: n.Public(),
|
||||
suspendible: n.Suspendible(),
|
||||
suspendible: n.Effect().Optional(), // XXX: s/Optional/Coroutine/
|
||||
}
|
||||
|
||||
if err := g.writeFuncImplHeader(&g.currFunk.bHeader); err != nil {
|
||||
|
||||
@@ -43,10 +43,12 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
|
||||
switch n.Kind() {
|
||||
case a.KAssign:
|
||||
n := n.AsAssign()
|
||||
mightIntroduceTemporaries = n.LHS().Suspendible() || n.RHS().Suspendible()
|
||||
// XXX: s/Optional/Coroutine/
|
||||
mightIntroduceTemporaries = n.LHS().Effect().Optional() || n.RHS().Effect().Optional()
|
||||
case a.KVar:
|
||||
v := n.AsVar().Value()
|
||||
mightIntroduceTemporaries = v != nil && v.Suspendible()
|
||||
// XXX: s/Optional/Coroutine/
|
||||
mightIntroduceTemporaries = v != nil && v.Effect().Optional()
|
||||
}
|
||||
if mightIntroduceTemporaries {
|
||||
// Put n's code into its own block, to restrict the scope of the
|
||||
@@ -139,7 +141,8 @@ func (g *gen) writeStatementExpr(b *buffer, n *a.Expr, depth uint32) error {
|
||||
if err := g.writeSuspendibles(b, n, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
if n.CallSuspendible() {
|
||||
// XXX: s/Optional/Coroutine/
|
||||
if n.Effect().RootCause() && n.Effect().Optional() {
|
||||
return nil
|
||||
}
|
||||
if err := g.writeExpr(b, n, replaceCallSuspendibles, depth); err != nil {
|
||||
@@ -218,7 +221,9 @@ func (g *gen) writeStatementIf(b *buffer, n *a.If, depth uint32) error {
|
||||
// sub-expression evaluation correct.
|
||||
nCloseCurly := 1
|
||||
for first := true; ; first = false {
|
||||
if n.Condition().Suspendible() {
|
||||
// TODO: restrict the if condition to effect-free expressions?
|
||||
// XXX: s/Optional/Coroutine/
|
||||
if n.Condition().Effect().Optional() {
|
||||
if !first {
|
||||
b.writeb('{')
|
||||
const maxCloseCurly = 1000
|
||||
@@ -482,7 +487,8 @@ func (g *gen) writeCoroSuspPoint(b *buffer, maybeSuspend bool) error {
|
||||
}
|
||||
|
||||
func (g *gen) writeSuspendibles(b *buffer, n *a.Expr, depth uint32) error {
|
||||
if !n.Suspendible() {
|
||||
// XXX: s/Optional/Coroutine/
|
||||
if !n.Effect().Optional() {
|
||||
return nil
|
||||
}
|
||||
if n.Operator() != t.IDTry {
|
||||
@@ -501,7 +507,8 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error {
|
||||
|
||||
// The evaluation order for suspendible calls (which can have side effects)
|
||||
// is important here: LHS, MHS, RHS, Args and finally the node itself.
|
||||
if !n.CallSuspendible() {
|
||||
// XXX: s/Optional/Coroutine/
|
||||
if e := n.Effect(); !e.RootCause() || !e.Optional() {
|
||||
for _, o := range n.AsNode().AsRaw().SubNodes() {
|
||||
if o != nil && o.Kind() == a.KExpr {
|
||||
if err := g.writeCallSuspendibles(b, o.AsExpr(), depth); err != nil {
|
||||
|
||||
+2
-8
@@ -285,17 +285,11 @@ func (h *genHelper) genWuffs(dirname string, qualifiedFilenames []string) error
|
||||
if !n.Public() {
|
||||
continue
|
||||
}
|
||||
effect := ""
|
||||
if n.Suspendible() {
|
||||
effect = "?"
|
||||
} else if n.Impure() {
|
||||
effect = "!"
|
||||
}
|
||||
if n.Receiver().IsZero() {
|
||||
return fmt.Errorf("TODO: genWuffs for a free-standing function")
|
||||
}
|
||||
// TODO: look at n.Asserts().
|
||||
fmt.Fprintf(out, "pub func %s.%s%s(", n.Receiver().Str(&h.tm), n.FuncName().Str(&h.tm), effect)
|
||||
fmt.Fprintf(out, "pub func %s.%s%v(", n.Receiver().Str(&h.tm), n.FuncName().Str(&h.tm), n.Effect())
|
||||
for i, field := range n.In().Fields() {
|
||||
field := field.AsField()
|
||||
if i > 0 {
|
||||
@@ -325,7 +319,7 @@ func (h *genHelper) genWuffs(dirname string, qualifiedFilenames []string) error
|
||||
continue
|
||||
}
|
||||
effect := ""
|
||||
if n.Suspendible() {
|
||||
if n.Optional() {
|
||||
effect = "?"
|
||||
}
|
||||
fmt.Fprintf(out, "pub struct %s%s()\n", n.QID().Str(&h.tm), effect)
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
- Renamed `buf1`, `reader1`, etc to `io_buffer`, `io_reader`, etc.
|
||||
- Renamed `u32`, `io_reader`, etc to `base.u32`, `base.io_reader`, etc.
|
||||
- Renamed `unread_u8?` to `undo_byte!`; added `can_undo_byte`.
|
||||
- Redesigned `!` vs `?` effects.
|
||||
- Redesigned iterate blocks.
|
||||
- Added `{frame,image,pixel}_config` and `pixel_buffer` types.
|
||||
- Added a `reset` method.
|
||||
|
||||
+71
-70
@@ -92,37 +92,53 @@ var kindStrings = [...]string{
|
||||
type Flags uint32
|
||||
|
||||
const (
|
||||
FlagsImpure = Flags(0x00000001)
|
||||
FlagsSuspendible = Flags(0x00000002)
|
||||
FlagsCallImpure = Flags(0x00000004)
|
||||
FlagsCallSuspendible = Flags(0x00000008)
|
||||
FlagsPublic = Flags(0x00000010)
|
||||
flagsUnused = Flags(0x00000020)
|
||||
FlagsHasBreak = Flags(0x00000040)
|
||||
FlagsHasContinue = Flags(0x00000080)
|
||||
FlagsGlobalIdent = Flags(0x00000100)
|
||||
// The low 8 bits are reserved. Effect values (Effect is a uint8) share the
|
||||
// same values as Flags.
|
||||
|
||||
FlagsPublic = Flags(0x00000100)
|
||||
FlagsHasBreak = Flags(0x00000200)
|
||||
FlagsHasContinue = Flags(0x00000400)
|
||||
FlagsGlobalIdent = Flags(0x00000800)
|
||||
)
|
||||
|
||||
func (f Flags) AsEffect() Effect { return Effect(f) }
|
||||
|
||||
type Effect uint8
|
||||
|
||||
const (
|
||||
flagEffect = FlagsImpure | FlagsSuspendible
|
||||
EffectImpure = Effect(0x01)
|
||||
EffectOptional = Effect(0x02)
|
||||
EffectCoroutine = Effect(0x04)
|
||||
|
||||
// flagsThatMatterForEq is the bitwise or of all flags that matter for the
|
||||
// Expr.Eq method.
|
||||
flagsThatMatterForEq = Flags(0x0000FFFF)
|
||||
// TODO: will we need an EffectRootCause if every ?-call requires a "do" or
|
||||
// "try"?
|
||||
effectMaskNonRootCause = Effect(0x07)
|
||||
EffectRootCause = Effect(0x08)
|
||||
)
|
||||
|
||||
type Effect uint32
|
||||
func (e Effect) AsFlags() Flags { return Flags(e) }
|
||||
|
||||
// TODO: replace Pure calls with the stronger "e == 0"?
|
||||
func (e Effect) Pure() bool { return e&EffectImpure == 0 }
|
||||
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) RootCause() bool { return e&EffectRootCause != 0 }
|
||||
|
||||
func (e Effect) String() string {
|
||||
switch e {
|
||||
case Effect(0):
|
||||
switch e & effectMaskNonRootCause {
|
||||
case 0:
|
||||
return ""
|
||||
case Effect(FlagsImpure):
|
||||
case EffectImpure:
|
||||
return "!"
|
||||
case Effect(FlagsImpure | FlagsSuspendible):
|
||||
case EffectOptional:
|
||||
return "?"
|
||||
case EffectImpure | EffectOptional:
|
||||
return "!?"
|
||||
case EffectImpure | EffectOptional | EffectCoroutine:
|
||||
return "!??"
|
||||
}
|
||||
return "INVALID_EFFECT"
|
||||
return "‽INVALID_EFFECT‽"
|
||||
}
|
||||
|
||||
type Bounds [2]*big.Int
|
||||
@@ -289,10 +305,6 @@ func (n *Raw) SetPackage(tm *t.Map, pkg t.ID) error {
|
||||
const MaxExprDepth = 255
|
||||
|
||||
// Expr is an expression, such as "i", "+j" or "k + l[m(n, o)].p":
|
||||
// - FlagsImpure is if it or a sub-expr is FlagsCallImpure
|
||||
// - FlagsSuspendible is if it or a sub-expr is FlagsCallSuspendible
|
||||
// - FlagsCallImpure is "f(x)" vs "f!(x)"
|
||||
// - FlagsCallSuspendible is "f(x)" vs "f?(x)", it implies FlagsCallImpure
|
||||
// - ID0: <0|operator|IDOpenParen|IDOpenBracket|IDColon|IDDot>
|
||||
// - ID1: <0|pkg> (for statuses)
|
||||
// - ID2: <0|literal|ident>
|
||||
@@ -328,24 +340,19 @@ const MaxExprDepth = 255
|
||||
// keyword, ID1 is the package and ID2 is the message.
|
||||
type Expr Node
|
||||
|
||||
func (n *Expr) AsNode() *Node { return (*Node)(n) }
|
||||
func (n *Expr) Effect() Effect { return Effect(n.flags & flagEffect) }
|
||||
func (n *Expr) Pure() bool { return n.flags&FlagsImpure == 0 }
|
||||
func (n *Expr) Impure() bool { return n.flags&FlagsImpure != 0 }
|
||||
func (n *Expr) Suspendible() bool { return n.flags&FlagsSuspendible != 0 }
|
||||
func (n *Expr) CallImpure() bool { return n.flags&FlagsCallImpure != 0 }
|
||||
func (n *Expr) CallSuspendible() bool { return n.flags&FlagsCallSuspendible != 0 }
|
||||
func (n *Expr) GlobalIdent() bool { return n.flags&FlagsGlobalIdent != 0 }
|
||||
func (n *Expr) ConstValue() *big.Int { return n.constValue }
|
||||
func (n *Expr) MBounds() Bounds { return n.mBounds }
|
||||
func (n *Expr) MType() *TypeExpr { return n.mType }
|
||||
func (n *Expr) Operator() t.ID { return n.id0 }
|
||||
func (n *Expr) StatusQID() t.QID { return t.QID{n.id1, n.id2} }
|
||||
func (n *Expr) Ident() t.ID { return n.id2 }
|
||||
func (n *Expr) LHS() *Node { return n.lhs }
|
||||
func (n *Expr) MHS() *Node { return n.mhs }
|
||||
func (n *Expr) RHS() *Node { return n.rhs }
|
||||
func (n *Expr) Args() []*Node { return n.list0 }
|
||||
func (n *Expr) AsNode() *Node { return (*Node)(n) }
|
||||
func (n *Expr) Effect() Effect { return Effect(n.flags) }
|
||||
func (n *Expr) GlobalIdent() bool { return n.flags&FlagsGlobalIdent != 0 }
|
||||
func (n *Expr) ConstValue() *big.Int { return n.constValue }
|
||||
func (n *Expr) MBounds() Bounds { return n.mBounds }
|
||||
func (n *Expr) MType() *TypeExpr { return n.mType }
|
||||
func (n *Expr) Operator() t.ID { return n.id0 }
|
||||
func (n *Expr) StatusQID() t.QID { return t.QID{n.id1, n.id2} }
|
||||
func (n *Expr) Ident() t.ID { return n.id2 }
|
||||
func (n *Expr) LHS() *Node { return n.lhs }
|
||||
func (n *Expr) MHS() *Node { return n.mhs }
|
||||
func (n *Expr) RHS() *Node { return n.rhs }
|
||||
func (n *Expr) Args() []*Node { return n.list0 }
|
||||
|
||||
func (n *Expr) SetConstValue(x *big.Int) { n.constValue = x }
|
||||
func (n *Expr) SetGlobalIdent() { n.flags |= FlagsGlobalIdent }
|
||||
@@ -354,16 +361,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 {
|
||||
if lhs != nil {
|
||||
flags |= lhs.flags & (FlagsImpure | FlagsSuspendible)
|
||||
flags |= lhs.flags & Flags(effectMaskNonRootCause)
|
||||
}
|
||||
if mhs != nil {
|
||||
flags |= mhs.flags & (FlagsImpure | FlagsSuspendible)
|
||||
flags |= mhs.flags & Flags(effectMaskNonRootCause)
|
||||
}
|
||||
if rhs != nil {
|
||||
flags |= rhs.flags & (FlagsImpure | FlagsSuspendible)
|
||||
flags |= rhs.flags & Flags(effectMaskNonRootCause)
|
||||
}
|
||||
for _, o := range args {
|
||||
flags |= o.flags & (FlagsImpure | FlagsSuspendible)
|
||||
flags |= o.flags & Flags(effectMaskNonRootCause)
|
||||
}
|
||||
|
||||
return &Expr{
|
||||
@@ -782,8 +789,6 @@ func NewTypeExpr(decorator t.ID, pkg t.ID, name t.ID, alenRecvMin *Node, max *Ex
|
||||
const MaxBodyDepth = 255
|
||||
|
||||
// Func is "func ID2.ID0(LHS)(RHS) { List2 }":
|
||||
// - FlagsImpure is "ID1" vs "ID1!"
|
||||
// - FlagsSuspendible is "ID1" vs "ID1?", it implies FlagsImpure
|
||||
// - FlagsPublic is "pub" vs "pri"
|
||||
// - ID0: funcName
|
||||
// - ID1: <0|receiverPkg> (set by calling SetPackage)
|
||||
@@ -806,21 +811,18 @@ const MaxBodyDepth = 255
|
||||
// - While
|
||||
type Func Node
|
||||
|
||||
func (n *Func) AsNode() *Node { return (*Node)(n) }
|
||||
func (n *Func) Effect() Effect { return Effect(n.flags & flagEffect) }
|
||||
func (n *Func) Pure() bool { return n.flags&FlagsImpure == 0 }
|
||||
func (n *Func) Impure() bool { return n.flags&FlagsImpure != 0 }
|
||||
func (n *Func) Suspendible() bool { return n.flags&FlagsSuspendible != 0 }
|
||||
func (n *Func) Public() bool { return n.flags&FlagsPublic != 0 }
|
||||
func (n *Func) Filename() string { return n.filename }
|
||||
func (n *Func) Line() uint32 { return n.line }
|
||||
func (n *Func) QQID() t.QQID { return t.QQID{n.id1, n.id2, n.id0} }
|
||||
func (n *Func) Receiver() t.QID { return t.QID{n.id1, n.id2} }
|
||||
func (n *Func) FuncName() t.ID { return n.id0 }
|
||||
func (n *Func) In() *Struct { return n.lhs.AsStruct() }
|
||||
func (n *Func) Out() *TypeExpr { return n.rhs.AsTypeExpr() }
|
||||
func (n *Func) Asserts() []*Node { return n.list1 }
|
||||
func (n *Func) Body() []*Node { return n.list2 }
|
||||
func (n *Func) AsNode() *Node { return (*Node)(n) }
|
||||
func (n *Func) Effect() Effect { return Effect(n.flags) }
|
||||
func (n *Func) Public() bool { return n.flags&FlagsPublic != 0 }
|
||||
func (n *Func) Filename() string { return n.filename }
|
||||
func (n *Func) Line() uint32 { return n.line }
|
||||
func (n *Func) QQID() t.QQID { return t.QQID{n.id1, n.id2, n.id0} }
|
||||
func (n *Func) Receiver() t.QID { return t.QID{n.id1, n.id2} }
|
||||
func (n *Func) FuncName() t.ID { return n.id0 }
|
||||
func (n *Func) In() *Struct { return n.lhs.AsStruct() }
|
||||
func (n *Func) Out() *TypeExpr { return n.rhs.AsTypeExpr() }
|
||||
func (n *Func) Asserts() []*Node { return n.list1 }
|
||||
func (n *Func) Body() []*Node { return n.list2 }
|
||||
|
||||
func NewFunc(flags Flags, filename string, line uint32, receiverName t.ID, funcName t.ID, in *Struct, out *TypeExpr, asserts []*Node, body []*Node) *Func {
|
||||
return &Func{
|
||||
@@ -893,20 +895,19 @@ func NewConst(flags Flags, filename string, line uint32, name t.ID, xType *TypeE
|
||||
}
|
||||
|
||||
// Struct is "struct ID2(List0)":
|
||||
// - FlagsSuspendible is "ID1" vs "ID1?"
|
||||
// - FlagsPublic is "pub" vs "pri"
|
||||
// - ID1: <0|pkg> (set by calling SetPackage)
|
||||
// - ID2: name
|
||||
// - List0: <Field> fields
|
||||
type Struct Node
|
||||
|
||||
func (n *Struct) AsNode() *Node { return (*Node)(n) }
|
||||
func (n *Struct) Suspendible() bool { return n.flags&FlagsSuspendible != 0 }
|
||||
func (n *Struct) Public() bool { return n.flags&FlagsPublic != 0 }
|
||||
func (n *Struct) Filename() string { return n.filename }
|
||||
func (n *Struct) Line() uint32 { return n.line }
|
||||
func (n *Struct) QID() t.QID { return t.QID{n.id1, n.id2} }
|
||||
func (n *Struct) Fields() []*Node { return n.list0 }
|
||||
func (n *Struct) AsNode() *Node { return (*Node)(n) }
|
||||
func (n *Struct) Optional() bool { return n.flags&Flags(EffectOptional) != 0 }
|
||||
func (n *Struct) Public() bool { return n.flags&FlagsPublic != 0 }
|
||||
func (n *Struct) Filename() string { return n.filename }
|
||||
func (n *Struct) Line() uint32 { return n.line }
|
||||
func (n *Struct) QID() t.QID { return t.QID{n.id1, n.id2} }
|
||||
func (n *Struct) Fields() []*Node { return n.list0 }
|
||||
|
||||
func NewStruct(flags Flags, filename string, line uint32, name t.ID, fields []*Node) *Struct {
|
||||
return &Struct{
|
||||
|
||||
+1
-2
@@ -35,8 +35,7 @@ func (n *Expr) Eq(o *Expr) bool {
|
||||
return n.constValue.Cmp(o.constValue) == 0
|
||||
}
|
||||
|
||||
if (n.flags&flagsThatMatterForEq) != (o.flags&flagsThatMatterForEq) ||
|
||||
n.id0 != o.id0 || n.id1 != o.id1 || n.id2 != o.id2 {
|
||||
if n.flags != o.flags || n.id0 != o.id0 || n.id1 != o.id1 || n.id2 != o.id2 {
|
||||
return false
|
||||
}
|
||||
if !n.lhs.AsExpr().Eq(o.lhs.AsExpr()) {
|
||||
|
||||
+1
-5
@@ -102,11 +102,7 @@ func (n *Expr) appendStr(buf []byte, tm *t.Map, parenthesize bool, depth uint32)
|
||||
|
||||
case t.IDOpenParen:
|
||||
buf = n.lhs.AsExpr().appendStr(buf, tm, true, depth)
|
||||
if n.flags&FlagsSuspendible != 0 {
|
||||
buf = append(buf, '?')
|
||||
} else if n.flags&FlagsImpure != 0 {
|
||||
buf = append(buf, '!')
|
||||
}
|
||||
buf = append(buf, n.flags.AsEffect().String()...)
|
||||
buf = append(buf, '(')
|
||||
for i, o := range n.list0 {
|
||||
if i != 0 {
|
||||
|
||||
@@ -382,7 +382,7 @@ func (q *checker) bcheckAssignment(lhs *a.Expr, op t.ID, rhs *a.Expr) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if lhs.Pure() && rhs.Pure() && lhs.MType().IsNumType() {
|
||||
if lhs.Effect().Pure() && rhs.Effect().Pure() && lhs.MType().IsNumType() {
|
||||
o := a.NewExpr(0, t.IDXBinaryEqEq, 0, 0, lhs.AsNode(), nil, rhs.AsNode(), nil)
|
||||
o.SetMType(lhs.MType())
|
||||
q.facts.appendFact(o)
|
||||
|
||||
+1
-1
@@ -527,7 +527,7 @@ func (q *checker) tcheckExprCall(n *a.Expr, depth uint32) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if ne, fe := n.Effect(), f.Effect(); ne != fe {
|
||||
if ne, fe := n.Effect(), f.Effect(); ne|a.EffectRootCause != fe|a.EffectRootCause {
|
||||
return fmt.Errorf("check: %q has effect %q but %q has effect %q",
|
||||
n.Str(q.tm), ne, f.QQID().Str(q.tm), fe)
|
||||
}
|
||||
|
||||
+26
-13
@@ -186,14 +186,7 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) {
|
||||
p.tm.ByID(id1), p.filename, p.line())
|
||||
}
|
||||
|
||||
switch p.peek1() {
|
||||
case t.IDExclam:
|
||||
flags |= a.FlagsImpure
|
||||
p.src = p.src[1:]
|
||||
case t.IDQuestion:
|
||||
flags |= a.FlagsImpure | a.FlagsSuspendible
|
||||
p.src = p.src[1:]
|
||||
}
|
||||
flags |= p.parseEffect().AsFlags()
|
||||
argFields, err := p.parseList(t.IDCloseParen, (*parser).parseFieldNode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -276,7 +269,7 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) {
|
||||
}
|
||||
|
||||
if p.peek1() == t.IDQuestion {
|
||||
flags |= a.FlagsSuspendible
|
||||
flags |= a.EffectOptional.AsFlags()
|
||||
p.src = p.src[1:]
|
||||
}
|
||||
fields, err := p.parseList(t.IDCloseParen, (*parser).parseFieldNode)
|
||||
@@ -1072,11 +1065,11 @@ func (p *parser) parseOperand() (*a.Expr, error) {
|
||||
return lhs, nil
|
||||
|
||||
case t.IDExclam, t.IDQuestion:
|
||||
flags |= a.FlagsImpure | a.FlagsCallImpure
|
||||
if p.src[0].ID == t.IDQuestion {
|
||||
flags |= a.FlagsSuspendible | a.FlagsCallSuspendible
|
||||
e := p.parseEffect()
|
||||
if e != 0 {
|
||||
e |= a.EffectRootCause
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
flags |= e.AsFlags()
|
||||
fallthrough
|
||||
|
||||
case t.IDOpenParen:
|
||||
@@ -1103,3 +1096,23 @@ func (p *parser) parseOperand() (*a.Expr, error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (p *parser) parseEffect() a.Effect {
|
||||
switch p.peek1() {
|
||||
case t.IDQuestion:
|
||||
p.src = p.src[1:]
|
||||
return a.EffectOptional
|
||||
case t.IDExclam:
|
||||
p.src = p.src[1:]
|
||||
if p.peek1() != t.IDQuestion {
|
||||
return a.EffectImpure
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
if p.peek1() != t.IDQuestion {
|
||||
return a.EffectImpure | a.EffectOptional
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
return a.EffectImpure | a.EffectOptional | a.EffectCoroutine
|
||||
}
|
||||
return 0
|
||||
}
|
||||
Reference in new issue
Block a user