1
0
mirror of https://github.com/golang/go synced 2024-11-25 08:07:57 -07:00

- 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
func main() {
[ ' ',
[]int(
' ',
'a',
'ä',
'本',
@ -30,5 +31,5 @@ func main() {
'\ubabe',
'\U0123ABCD',
'\Ucafebabe'
]
);
}

View File

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

View File

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

View File

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

View File

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