Ran gofmt
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
//go:build ignore
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
@@ -5,12 +6,12 @@ package main
|
||||
import "os"
|
||||
import cre "git.tebibyte.media/sashakoshka/creature"
|
||||
|
||||
func main () {
|
||||
func main() {
|
||||
// this is a simple echo program. it will take in input indefinetly and
|
||||
// repeat it. due to line buffering in the terminal however, it will
|
||||
// only print output once you have pressed enter.
|
||||
machine := cre.Machine[int] {}
|
||||
machine.LoadProgram([]int {
|
||||
machine := cre.Machine[int]{}
|
||||
machine.LoadProgram([]int{
|
||||
cre.PUSH, 0,
|
||||
cre.CAL,
|
||||
|
||||
@@ -22,20 +23,22 @@ func main () {
|
||||
cre.JMP,
|
||||
})
|
||||
|
||||
machine.Register (0, read)
|
||||
machine.Register (1, write)
|
||||
machine.Register(0, read)
|
||||
machine.Register(1, write)
|
||||
err := machine.Execute(0)
|
||||
if err != nil { panic(err.Error()) }
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func read (machine *cre.Machine[int]) (stop bool) {
|
||||
ch := []byte { 0 }
|
||||
func read(machine *cre.Machine[int]) (stop bool) {
|
||||
ch := []byte{0}
|
||||
os.Stdin.Read(ch)
|
||||
machine.Push(int(ch[0]))
|
||||
return
|
||||
}
|
||||
|
||||
func write (machine *cre.Machine[int]) (stop bool) {
|
||||
func write(machine *cre.Machine[int]) (stop bool) {
|
||||
print(string(rune(machine.Pop())))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//go:build ignore
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
@@ -5,7 +6,7 @@ package main
|
||||
import "os"
|
||||
import cre "git.tebibyte.media/sashakoshka/creature"
|
||||
|
||||
func main () {
|
||||
func main() {
|
||||
// this is an "ai psychiatrist" program. when it starts, it asks the
|
||||
// user "What brings you in today?", and no matter what the user types,
|
||||
// the program will respond with "And how does that make you feel?".
|
||||
@@ -13,15 +14,15 @@ func main () {
|
||||
// point.
|
||||
|
||||
// constant address values
|
||||
x := 0
|
||||
introStart := 1
|
||||
introLoopStart := 5
|
||||
readLoopStart := 36
|
||||
responseStart := 71
|
||||
x := 0
|
||||
introStart := 1
|
||||
introLoopStart := 5
|
||||
readLoopStart := 36
|
||||
responseStart := 71
|
||||
responseLoopStart := 50
|
||||
|
||||
machine := cre.Machine[int] {}
|
||||
machine.LoadProgram([]int {
|
||||
|
||||
machine := cre.Machine[int]{}
|
||||
machine.LoadProgram([]int{
|
||||
// reset x
|
||||
cre.PUSH, introStart,
|
||||
cre.PUSH, x,
|
||||
@@ -38,7 +39,7 @@ func main () {
|
||||
cre.EQ,
|
||||
cre.PUSH, readLoopStart,
|
||||
cre.JMP,
|
||||
|
||||
|
||||
// get char
|
||||
cre.PUSH, x,
|
||||
cre.PEEK,
|
||||
@@ -87,7 +88,7 @@ func main () {
|
||||
cre.EQ,
|
||||
cre.PUSH, readLoopStart,
|
||||
cre.JMP,
|
||||
|
||||
|
||||
// get char
|
||||
cre.PUSH, x,
|
||||
cre.PEEK,
|
||||
@@ -111,33 +112,35 @@ func main () {
|
||||
cre.JMP,
|
||||
})
|
||||
|
||||
stringData := []byte (
|
||||
stringData := []byte(
|
||||
"\x00" +
|
||||
"== Artificial Intelligence Psychiatrist ==\n" +
|
||||
"What brings you in today?\n\x00" +
|
||||
"And how does that make you feel?\n\x00")
|
||||
"== Artificial Intelligence Psychiatrist ==\n" +
|
||||
"What brings you in today?\n\x00" +
|
||||
"And how does that make you feel?\n\x00")
|
||||
block := make([]int, len(stringData))
|
||||
|
||||
|
||||
for index, char := range stringData {
|
||||
block[index] = int(char)
|
||||
}
|
||||
|
||||
|
||||
machine.LoadMemory(block)
|
||||
machine.Register (0, read)
|
||||
machine.Register (1, write)
|
||||
|
||||
machine.Register(0, read)
|
||||
machine.Register(1, write)
|
||||
|
||||
err := machine.Execute(0)
|
||||
if err != nil { panic(err.Error()) }
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func read (machine *cre.Machine[int]) (stop bool) {
|
||||
ch := []byte { 0 }
|
||||
func read(machine *cre.Machine[int]) (stop bool) {
|
||||
ch := []byte{0}
|
||||
os.Stdin.Read(ch)
|
||||
machine.Push(int(ch[0]))
|
||||
return
|
||||
}
|
||||
|
||||
func write (machine *cre.Machine[int]) (stop bool) {
|
||||
func write(machine *cre.Machine[int]) (stop bool) {
|
||||
print(string(rune(machine.Pop())))
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user