Machine is now a generic type
This commit is contained in:
@@ -9,7 +9,7 @@ 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 { Program: []int {
|
||||
machine := cre.Machine[int] { Program: []int {
|
||||
cre.PUSH, 0,
|
||||
cre.CAL,
|
||||
|
||||
@@ -27,14 +27,14 @@ func main () {
|
||||
if err != nil { panic(err.Error()) }
|
||||
}
|
||||
|
||||
func read (machine *cre.Machine) (stop bool) {
|
||||
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) (stop bool) {
|
||||
func write (machine *cre.Machine[int]) (stop bool) {
|
||||
print(string(rune(machine.Pop())))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ func main () {
|
||||
responseStart := 71
|
||||
responseLoopStart := 50
|
||||
|
||||
machine := cre.Machine { Program: []int {
|
||||
machine := cre.Machine[int] { Program: []int {
|
||||
// reset x
|
||||
cre.PUSH, introStart,
|
||||
cre.PUSH, x,
|
||||
@@ -129,14 +129,14 @@ func main () {
|
||||
if err != nil { panic(err.Error()) }
|
||||
}
|
||||
|
||||
func read (machine *cre.Machine) (stop bool) {
|
||||
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) (stop bool) {
|
||||
func write (machine *cre.Machine[int]) (stop bool) {
|
||||
print(string(rune(machine.Pop())))
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user