aboutsummaryrefslogtreecommitdiff
path: root/pkg/pointer/pointer.go
diff options
context:
space:
mode:
authorJulien Dessaux2021-09-23 16:14:37 +0200
committerJulien Dessaux2021-09-23 17:49:44 +0200
commit198efceb1f14c9822bf87ede6961d0f94a4760db (patch)
tree5391e03e81979b99380cf2794f8e338234a34b04 /pkg/pointer/pointer.go
parentMoved the character execution's to the pointer in order to handle the k command (diff)
downloadgofunge98-198efceb1f14c9822bf87ede6961d0f94a4760db.tar.gz
gofunge98-198efceb1f14c9822bf87ede6961d0f94a4760db.tar.bz2
gofunge98-198efceb1f14c9822bf87ede6961d0f94a4760db.zip
Implemented commands until helloworld works \o/
Diffstat (limited to '')
-rw-r--r--pkg/pointer/pointer.go28
1 files changed, 23 insertions, 5 deletions
diff --git a/pkg/pointer/pointer.go b/pkg/pointer/pointer.go
index 902fe69..2eea79d 100644
--- a/pkg/pointer/pointer.go
+++ b/pkg/pointer/pointer.go
@@ -6,6 +6,9 @@ import (
"git.adyxax.org/adyxax/gofunge/pkg/field"
)
+type InputFunction func() int
+type OutputFunction func(v int)
+
type Pointer struct {
// the position
x int
@@ -16,18 +19,33 @@ type Pointer struct {
// The Storage offset
sox int
soy int
+ // The stringmode flag
+ stringMode bool
+ lastCharWasSpace bool
// The stack
- Ss *StackStack
+ ss *StackStack
// The next element for the multi-"threaded" b98 interpreter
Next *Pointer
+ // The input/output functions
+ CharacterInput InputFunction
+ DecimalInput InputFunction
+ CharacterOutput OutputFunction
+ DecimalOutput OutputFunction
}
func NewPointer() *Pointer {
- return &Pointer{dx: 1, Ss: NewStackStack()}
+ return &Pointer{
+ dx: 1,
+ ss: NewStackStack(),
+ CharacterInput: DefaultCharacterInput,
+ DecimalInput: DefaultDecimalInput,
+ CharacterOutput: DefaultCharacterOutput,
+ DecimalOutput: DefaultDecimalOutput,
+ }
}
func (p Pointer) Split() *Pointer {
- return &p // p is already a copy
+ return &p // p is already a copy TODO we need to duplicate the stack and handle the Next
}
func (p *Pointer) Step(f field.Field) {
@@ -76,8 +94,8 @@ func (p *Pointer) Redirect(c int) bool {
case 'r':
p.Reverse()
case 'x':
- dy := p.Ss.Pop()
- dx := p.Ss.Pop()
+ dy := p.ss.head.Pop()
+ dx := p.ss.head.Pop()
p.RedirectTo(dx, dy)
default:
return false