Fix handling array boolean values
This commit is contained in:
13
_test/bool4.go
Normal file
13
_test/bool4.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
m := []bool{false, true}
|
||||
if m[0] {
|
||||
println(0)
|
||||
} else {
|
||||
println(1)
|
||||
}
|
||||
}
|
||||
|
||||
// Output:
|
||||
// 1
|
||||
@@ -633,6 +633,26 @@ func main() {
|
||||
// 1
|
||||
}
|
||||
|
||||
func Example_bool4() {
|
||||
src := `
|
||||
package main
|
||||
|
||||
func main() {
|
||||
m := []bool{false, true}
|
||||
if m[0] {
|
||||
println(0)
|
||||
} else {
|
||||
println(1)
|
||||
}
|
||||
}
|
||||
`
|
||||
i := NewInterpreter(Opt{Entry: "main"}, "bool4.go")
|
||||
i.Eval(src)
|
||||
|
||||
// Output:
|
||||
// 1
|
||||
}
|
||||
|
||||
func Example_chan0() {
|
||||
src := `
|
||||
package main
|
||||
|
||||
@@ -527,18 +527,6 @@ func callBin(n *Node) {
|
||||
}
|
||||
}
|
||||
|
||||
func getPtrIndex(n *Node) {
|
||||
i := n.findex
|
||||
next := getExec(n.tnext)
|
||||
fi := n.child[1].val.(int)
|
||||
value := genValue(n.child[0])
|
||||
|
||||
n.exec = func(f *Frame) Builtin {
|
||||
f.data[i] = value(f).Elem().Field(fi)
|
||||
return next
|
||||
}
|
||||
}
|
||||
|
||||
func getIndexBinMethod(n *Node) {
|
||||
i := n.findex
|
||||
m := n.val.(int)
|
||||
@@ -551,15 +539,26 @@ func getIndexBinMethod(n *Node) {
|
||||
}
|
||||
}
|
||||
|
||||
// getIndexArray returns array value from index
|
||||
func getIndexArray(n *Node) {
|
||||
i := n.findex
|
||||
next := getExec(n.tnext)
|
||||
tnext := getExec(n.tnext)
|
||||
value0 := genValue(n.child[0])
|
||||
value1 := genValue(n.child[1])
|
||||
|
||||
n.exec = func(f *Frame) Builtin {
|
||||
f.data[i] = value0(f).Index(int(value1(f).Int()))
|
||||
return next
|
||||
if n.fnext != nil {
|
||||
fnext := getExec(n.fnext)
|
||||
n.exec = func(f *Frame) Builtin {
|
||||
if value0(f).Index(int(value1(f).Int())).Bool() {
|
||||
return tnext
|
||||
}
|
||||
return fnext
|
||||
}
|
||||
} else {
|
||||
i := n.findex
|
||||
n.exec = func(f *Frame) Builtin {
|
||||
f.data[i] = value0(f).Index(int(value1(f).Int()))
|
||||
return tnext
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user