- changed literal syntax to use the convert notation

- fixed issued with function declarations/function literals
- added more tests and fixed existing tests

SVN=118167
This commit is contained in:
Robert Griesemer 2008-05-08 17:12:15 -07:00
parent 7fbe486b1a
commit 9bc7b08abb
6 changed files with 69 additions and 9 deletions

View file

@ -7,7 +7,8 @@
package main package main
func main() { func main() {
[ ' ', []int(
' ',
'a', 'a',
'ä', 'ä',
'本', '本',
@ -30,5 +31,5 @@ func main() {
'\ubabe', '\ubabe',
'\U0123ABCD', '\U0123ABCD',
'\Ucafebabe' '\Ucafebabe'
] );
} }

View file

@ -7,7 +7,8 @@
package main package main
func main() { func main() {
[ 0., []float(
0.,
+10., +10.,
-210., -210.,
@ -66,5 +67,5 @@ func main() {
0.0E123, 0.0E123,
+10.01e234, +10.01e234,
-210.012e345 -210.012e345
] );
} }

View file

@ -7,7 +7,8 @@
package main package main
func main() { func main() {
[ 0, []int(
0,
123, 123,
0123, 0123,
0000, 0000,
@ -15,5 +16,5 @@ func main() {
0x123, 0x123,
0X0, 0X0,
0X123 0X123
]; );
} }

View file

@ -7,7 +7,8 @@
package main package main
func main() { func main() {
[ "", []string(
"",
" ", " ",
"'`", "'`",
"a", "a",
@ -25,5 +26,5 @@ func main() {
`\a\b\f\n\r\t\v\\\'\"`, `\a\b\f\n\r\t\v\\\'\"`,
`\000\123\x00\xca\xFE\u0123\ubabe\U0123ABCD\Ucafebabe`, `\000\123\x00\xca\xFE\u0123\ubabe\U0123ABCD\Ucafebabe`,
`\x\u\U\` `\x\u\U\`
] );
} }

View file

@ -67,7 +67,8 @@ func control_structs() {
var x float var x float
} }
foo: // a label foo: // a label
switch { var j int;
switch y := 0; true {
case i < y: case i < y:
fallthrough; fallthrough;
case i < j: case i < j:

55
test/turing.go Normal file
View file

@ -0,0 +1,55 @@
// $G $F.go && $L $F.$A && ./$A.out
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
// brainfuck
func main() {
var a [30000]byte;
prog := "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.";
p := 0;
pc := 0;
for {
switch prog[pc] {
case '>':
p++;
case '<':
p--;
case '+':
a[p]++;
case '-':
a[p]--;
case '.':
print string(a[p]);
case '[':
if a[p] == 0 {
for nest := 1; nest > 0; pc++ {
if prog[pc+1] == ']' {
nest--;
}
if prog[pc+1] == '[' {
nest++;
}
}
}
case ']':
if a[p] != 0 {
for nest := -1; nest < 0; pc-- {
if prog[pc-1] == ']' {
nest--;
}
if prog[pc-1] == '[' {
nest++;
}
}
}
default:
return;
}
pc++;
}
}