diff options
author | Julien Dessaux | 2021-09-21 15:41:52 +0200 |
---|---|---|
committer | Julien Dessaux | 2021-09-21 15:41:52 +0200 |
commit | 270a3845cdec1baf1bb548e2042d9bbfeeecf153 (patch) | |
tree | 8e38500d9618cf4fc3f22d3f61c445b9e2566d62 | |
parent | Began implementing the stack and the stack stack (diff) | |
download | gofunge98-270a3845cdec1baf1bb548e2042d9bbfeeecf153.tar.gz gofunge98-270a3845cdec1baf1bb548e2042d9bbfeeecf153.tar.bz2 gofunge98-270a3845cdec1baf1bb548e2042d9bbfeeecf153.zip |
Simplified instruction pointer delta handling
Diffstat (limited to '')
-rw-r--r-- | pkg/pointer/delta.go | 10 | ||||
-rw-r--r-- | pkg/pointer/pointer.go | 13 | ||||
-rw-r--r-- | pkg/pointer/pointer_test.go | 6 | ||||
-rw-r--r-- | pkg/pointer/storage-offset.go | 2 |
4 files changed, 12 insertions, 19 deletions
diff --git a/pkg/pointer/delta.go b/pkg/pointer/delta.go deleted file mode 100644 index 0c3e074..0000000 --- a/pkg/pointer/delta.go +++ /dev/null @@ -1,10 +0,0 @@ -package pointer - -type Delta struct { - x int - y int -} - -func NewDelta(x, y int) *Delta { - return &Delta{x: x, y: y} -} diff --git a/pkg/pointer/pointer.go b/pkg/pointer/pointer.go index 8f2a299..5847e70 100644 --- a/pkg/pointer/pointer.go +++ b/pkg/pointer/pointer.go @@ -3,16 +3,19 @@ package pointer import "git.adyxax.org/adyxax/gofunge/pkg/field" type Pointer struct { - x int - y int - delta *Delta + // the position + x int + y int + // The delta + dx int + dy int // The Storage offset sox int soy int } func NewPointer() *Pointer { - return &Pointer{delta: NewDelta(1, 0)} + return &Pointer{dx: 1} } func (p Pointer) Split() *Pointer { @@ -20,5 +23,5 @@ func (p Pointer) Split() *Pointer { } func (p *Pointer) Step(f field.Field) { - p.x, p.y = f.Step(p.x, p.y, p.delta.x, p.delta.y) + p.x, p.y = f.Step(p.x, p.y, p.dx, p.dy) } diff --git a/pkg/pointer/pointer_test.go b/pkg/pointer/pointer_test.go index b6a3898..4d3b6bf 100644 --- a/pkg/pointer/pointer_test.go +++ b/pkg/pointer/pointer_test.go @@ -9,7 +9,7 @@ import ( ) func TestNewPointer(t *testing.T) { - require.Equal(t, NewPointer(), &Pointer{delta: &Delta{1, 0}}) + require.Equal(t, NewPointer(), &Pointer{dx: 1}) } func TestSplit(t *testing.T) { @@ -23,8 +23,8 @@ func TestSplit(t *testing.T) { // We check that p2 is a real copy p.Step(*f) p2.Step(*f) - require.Equal(t, p, &Pointer{x: 1, y: 0, delta: &Delta{1, 0}}) - require.Equal(t, p2, &Pointer{x: 1, y: 0, delta: &Delta{1, 0}}) + require.Equal(t, p, &Pointer{x: 1, y: 0, dx: 1}) + require.Equal(t, p2, &Pointer{x: 1, y: 0, dx: 1}) } func TestStep(t *testing.T) { // Step is thoroughly tested in the field package diff --git a/pkg/pointer/storage-offset.go b/pkg/pointer/storage-offset.go index 0fcd9ed..dc63ee0 100644 --- a/pkg/pointer/storage-offset.go +++ b/pkg/pointer/storage-offset.go @@ -5,7 +5,7 @@ func (p Pointer) GetStorageOffset() (x, y int) { } func (p *Pointer) CalculateNewStorageOffset() { - p.sox, p.soy = p.x+p.delta.x, p.y+p.delta.y + p.sox, p.soy = p.x+p.dx, p.y+p.dy } func (p *Pointer) SetStorageOffset(x, y int) { |