Skip to content

Commit

Permalink
reworked some code
Browse files Browse the repository at this point in the history
  • Loading branch information
boarpig committed Dec 15, 2011
1 parent bce6851 commit 55e2743
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions brainfuck.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import (
"fmt"
"flag"
"os"
"ioutil"
)

func interpreter() {
tape := make([]byte, 30000)
func interpreter(code []byte) {
tape := make([]byte, 1000)
pointer := 15000
codeptr := 0
code := make([]byte, 0, 10000)
one_byte := make([]byte, 1, 1)
for code[codeptr] != 0 {
switch code[codeptr] {
Expand Down Expand Up @@ -72,21 +72,26 @@ func interpreter() {
}
}

func load_file(filename string) {

func is_bf_char(item byte) bool {
chars := [8]byte{'>', '<', '+', '-', '.', ',', '[', ']'}
var contained bool
for _, v := range chars{
if item == v {
contained = true
break
}
}
return contained
}

func main() {
filename := flag.String("file", "", "Specify the codefile to use.")
file, err := os.Open(*filename)
if err != nil {
return
}

n, err := file.Read(code)
fmt.Printf("Read %d bytes.", n)
if err != nil {
return
source := ioutil.ReadFile(filename)
code := make([]byte, 10)
for _, v := range code {
if is_bf_char(v) {
code = append(code, v)
}
}

interpreter(code)
}

0 comments on commit 55e2743

Please sign in to comment.