]> Cypherpunks.ru repositories - gostls13.git/commitdiff
- changed literal syntax to use the convert notation
authorRobert Griesemer <gri@golang.org>
Fri, 9 May 2008 00:12:15 +0000 (17:12 -0700)
committerRobert Griesemer <gri@golang.org>
Fri, 9 May 2008 00:12:15 +0000 (17:12 -0700)
- fixed issued with function declarations/function literals
- added more tests and fixed existing tests

SVN=118167

test/char_lit.go
test/float_lit.go
test/int_lit.go
test/string_lit.go
test/test0.go
test/turing.go [new file with mode: 0644]

index 6af96be9ca8e8c0cbe8e9a413874053804f21d5e..7943f164f184b7dfa0d0d9bddd73f6327409d96c 100644 (file)
@@ -7,7 +7,8 @@
 package main
 
 func main() {
-  [ ' ',
+  []int(
+    ' ',
     'a',
     'ä',
     '本',
@@ -30,5 +31,5 @@ func main() {
     '\ubabe',
     '\U0123ABCD',
     '\Ucafebabe'
-  ]
+  );
 }
index 11decaffb17fb27ca04e85834e503d478c64b99b..a5413d980555229d85acfb41bee480c31a625dfa 100644 (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
-  ]
+  );
 }
index ef74370ac4b5441282e1b4a83193b8ea2e7ad279..9ce5fa3177edbcb264c3dbb0d6debea09eb6a5c0 100644 (file)
@@ -7,7 +7,8 @@
 package main
 
 func main() {
-  [ 0,
+  []int(
+    0,
     123,
     0123,
     0000,
@@ -15,5 +16,5 @@ func main() {
     0x123,
     0X0,
     0X123
-  ];
+  );
 }
index 87f7dae3acce0362f1ee458483ede69f548d0a87..1e725354b2156f834ef963b5d7627a5737a35031 100644 (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\`
-  ]
+  );
 }
index 0d9585ed6bd55530532d4a089680e30b72b35d8c..318c5ff77ad8704861c2d882792f1941ee9d1820 100644 (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:
diff --git a/test/turing.go b/test/turing.go
new file mode 100644 (file)
index 0000000..a7a8ea7
--- /dev/null
@@ -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++;
+       }
+}