Skip to content

Commit

Permalink
update samples
Browse files Browse the repository at this point in the history
  • Loading branch information
chai2010 committed Dec 25, 2024
1 parent 901d34b commit 3e89fd3
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 188 deletions.
28 changes: 18 additions & 10 deletions samples/Wa/brainfuck.wa
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
// 版权 @2019 凹语言 作者。保留所有权利。
// BrainFuck VM
// https://github.com/chai2010/brainfuck-wa

func main {
// print hi
const code = "++++++++++[>++++++++++<-]>++++.+."
vm := NewBrainFuck(code)
vm.Run()
println(string(vm.Run()))
}

type BrainFuck struct {
mem :[30000]byte
code :string
pos :int
pc :int
func Run(code: string) => string {
vm := NewBrainFuck(code)
return string(vm.Run())
}

// BF VM
type BrainFuck :struct {
mem: [30000]byte
code: string
pos: int
pc: int
}

func NewBrainFuck(code: string) => *BrainFuck {
return &BrainFuck{code: code}
}

func BrainFuck.Run {
func BrainFuck.Run => []byte {
output := make([]byte, 0, 64)
for ; this.pc != len(this.code); this.pc++ {
switch x := this.code[this.pc]; x {
case '>':
Expand All @@ -38,12 +46,12 @@ func BrainFuck.Run {
this.loop(-1)
}
case '.':
print(rune(this.mem[this.pos]))
output = append(output, this.mem[this.pos])
case ',':
// TODO: support read byte
}
}
return
return output
}

func BrainFuck.loop(inc: int) {
Expand Down
42 changes: 0 additions & 42 deletions samples/Wa/closure.wa

This file was deleted.

9 changes: 0 additions & 9 deletions samples/Wa/complex.wa

This file was deleted.

19 changes: 0 additions & 19 deletions samples/Wa/count.wa

This file was deleted.

15 changes: 0 additions & 15 deletions samples/Wa/defer.wa

This file was deleted.

16 changes: 0 additions & 16 deletions samples/Wa/heart.wa

This file was deleted.

17 changes: 0 additions & 17 deletions samples/Wa/hello-p5.wa

This file was deleted.

15 changes: 0 additions & 15 deletions samples/Wa/hello.wa

This file was deleted.

32 changes: 0 additions & 32 deletions samples/Wa/iface.wa

This file was deleted.

12 changes: 0 additions & 12 deletions samples/Wa/map.wa

This file was deleted.

1 change: 0 additions & 1 deletion vendor/CodeMirror
Submodule CodeMirror deleted from deee5c

0 comments on commit 3e89fd3

Please sign in to comment.