summaryrefslogtreecommitdiff
path: root/gcc/testsuite/go.test/test/turing.go
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/go.test/test/turing.go')
-rw-r--r--gcc/testsuite/go.test/test/turing.go53
1 files changed, 29 insertions, 24 deletions
diff --git a/gcc/testsuite/go.test/test/turing.go b/gcc/testsuite/go.test/test/turing.go
index 0af39de8b2..366982e67f 100644
--- a/gcc/testsuite/go.test/test/turing.go
+++ b/gcc/testsuite/go.test/test/turing.go
@@ -10,42 +10,47 @@ package main
var p, pc int
var a [30000]byte
+
const prog = "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.!"
func scan(dir int) {
for nest := dir; dir*nest > 0; pc += dir {
switch prog[pc+dir] {
- case ']':
- nest--
- case '[':
- nest++
+ case ']':
+ nest--
+ case '[':
+ nest++
}
}
}
func main() {
+ r := ""
for {
switch prog[pc] {
- case '>':
- p++
- case '<':
- p--
- case '+':
- a[p]++
- case '-':
- a[p]--
- case '.':
- print(string(a[p]))
- case '[':
- if a[p] == 0 {
- scan(1)
- }
- case ']':
- if a[p] != 0 {
- scan(-1)
- }
- default:
- return
+ case '>':
+ p++
+ case '<':
+ p--
+ case '+':
+ a[p]++
+ case '-':
+ a[p]--
+ case '.':
+ r += string(a[p])
+ case '[':
+ if a[p] == 0 {
+ scan(1)
+ }
+ case ']':
+ if a[p] != 0 {
+ scan(-1)
+ }
+ default:
+ if r != "Hello World!\n" {
+ panic(r)
+ }
+ return
}
pc++
}