From 9bc7b08abbb53469ebc39fb6617b29da0756e858 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 8 May 2008 17:12:15 -0700 Subject: [PATCH] - changed literal syntax to use the convert notation - fixed issued with function declarations/function literals - added more tests and fixed existing tests SVN=118167 --- test/char_lit.go | 5 +++-- test/float_lit.go | 5 +++-- test/int_lit.go | 5 +++-- test/string_lit.go | 5 +++-- test/test0.go | 3 ++- test/turing.go | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 69 insertions(+), 9 deletions(-) create mode 100644 test/turing.go diff --git a/test/char_lit.go b/test/char_lit.go index 6af96be9ca..7943f164f1 100644 --- a/test/char_lit.go +++ b/test/char_lit.go @@ -7,7 +7,8 @@ package main func main() { - [ ' ', + []int( + ' ', 'a', 'ä', '本', @@ -30,5 +31,5 @@ func main() { '\ubabe', '\U0123ABCD', '\Ucafebabe' - ] + ); } diff --git a/test/float_lit.go b/test/float_lit.go index 11decaffb1..a5413d9805 100644 --- a/test/float_lit.go +++ b/test/float_lit.go @@ -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 - ] + ); } diff --git a/test/int_lit.go b/test/int_lit.go index ef74370ac4..9ce5fa3177 100644 --- a/test/int_lit.go +++ b/test/int_lit.go @@ -7,7 +7,8 @@ package main func main() { - [ 0, + []int( + 0, 123, 0123, 0000, @@ -15,5 +16,5 @@ func main() { 0x123, 0X0, 0X123 - ]; + ); } diff --git a/test/string_lit.go b/test/string_lit.go index 87f7dae3ac..1e725354b2 100644 --- a/test/string_lit.go +++ b/test/string_lit.go @@ -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\` - ] + ); } diff --git a/test/test0.go b/test/test0.go index 0d9585ed6b..318c5ff77a 100644 --- a/test/test0.go +++ b/test/test0.go @@ -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 index 0000000000..a7a8ea7863 --- /dev/null +++ b/test/turing.go @@ -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++; + } +} -- 2.48.1