fix: use branch operation in || and && operators, fix storage for ! (#476)
This commit is contained in:
committed by
Ludovic Fernandez
parent
f3f54a5302
commit
9a8a88dcb9
9
_test/or0.go
Normal file
9
_test/or0.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
c := false
|
||||
println(c || !c)
|
||||
}
|
||||
|
||||
// Output:
|
||||
// true
|
||||
9
_test/or1.go
Normal file
9
_test/or1.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
c := false
|
||||
println(!c || c)
|
||||
}
|
||||
|
||||
// Output:
|
||||
// true
|
||||
@@ -1023,6 +1023,9 @@ func (interp *Interpreter) cfg(root *node) ([]*node, error) {
|
||||
n.child[1].tnext = n
|
||||
n.typ = n.child[0].typ
|
||||
n.findex = sc.add(n.typ)
|
||||
if n.start.action == aNop {
|
||||
n.start.gen = branch
|
||||
}
|
||||
|
||||
case lorExpr:
|
||||
n.start = n.child[0].start
|
||||
@@ -1031,6 +1034,9 @@ func (interp *Interpreter) cfg(root *node) ([]*node, error) {
|
||||
n.child[1].tnext = n
|
||||
n.typ = n.child[0].typ
|
||||
n.findex = sc.add(n.typ)
|
||||
if n.start.action == aNop {
|
||||
n.start.gen = branch
|
||||
}
|
||||
|
||||
case parenExpr:
|
||||
wireChild(n)
|
||||
|
||||
@@ -38,7 +38,7 @@ func (n *node) astDot(out io.Writer, name string) {
|
||||
func (n *node) cfgDot(out io.Writer) {
|
||||
fmt.Fprintf(out, "digraph cfg {\n")
|
||||
n.Walk(nil, func(n *node) {
|
||||
if n.kind == basicLit || n.kind == identExpr || n.tnext == nil {
|
||||
if n.kind == basicLit || n.tnext == nil {
|
||||
return
|
||||
}
|
||||
var label string
|
||||
|
||||
@@ -345,13 +345,16 @@ func not(n *node) {
|
||||
dest := genValue(n)
|
||||
value := genValue(n.child[0])
|
||||
tnext := getExec(n.tnext)
|
||||
i := n.findex
|
||||
|
||||
if n.fnext != nil {
|
||||
fnext := getExec(n.fnext)
|
||||
n.exec = func(f *frame) bltn {
|
||||
if !value(f).Bool() {
|
||||
f.data[i].SetBool(true)
|
||||
return tnext
|
||||
}
|
||||
f.data[i].SetBool(false)
|
||||
return fnext
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user