aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2018-02-11 16:48:54 +0100
committerDimitri Sokolyuk <demon@dim13.org>2018-02-11 16:48:54 +0100
commit8323a6a2053e0ec9d98ede95c7c5d5820f4509f1 (patch)
tree53c2dc61623d4ea72658843eae65658b842c84ac
parentf2b09c807835bafffcaa21196a57b2a5dddafc98 (diff)
rename
-rw-r--r--core.go4
-rw-r--r--core_test.go30
-rw-r--r--parse.go32
-rw-r--r--parse_test.go8
4 files changed, 37 insertions, 37 deletions
diff --git a/core.go b/core.go
index b06c029..ea906ed 100644
--- a/core.go
+++ b/core.go
@@ -111,7 +111,7 @@ func (c *Core) Decode() Instruction {
func (c *Core) Eval(ins Instruction) error {
c.pc++
switch v := ins.(type) {
- case Lit:
+ case Literal:
c.d.push(c.st0)
c.st0 = v.value()
case Jump:
@@ -119,7 +119,7 @@ func (c *Core) Eval(ins Instruction) error {
case Call:
c.r.push(c.pc << 1)
c.pc = v.value()
- case Cond:
+ case Conditional:
if c.st0 == 0 {
c.pc = v.value()
}
diff --git a/core_test.go b/core_test.go
index 07a905f..e263136 100644
--- a/core_test.go
+++ b/core_test.go
@@ -43,11 +43,11 @@ func TestEval(t *testing.T) {
end: Core{pc: 0xff},
},
{
- ins: []Instruction{Lit(1), Cond(0xff)},
+ ins: []Instruction{Literal(1), Conditional(0xff)},
end: Core{pc: 2},
},
{
- ins: []Instruction{Lit(0), Cond(0xff)},
+ ins: []Instruction{Literal(0), Conditional(0xff)},
end: Core{pc: 0xff},
},
{
@@ -55,39 +55,39 @@ func TestEval(t *testing.T) {
end: Core{pc: 0xff, r: stack{data: [0x20]uint16{0x00, 0x02}, sp: 1}},
},
{
- ins: []Instruction{Lit(0xff)},
+ ins: []Instruction{Literal(0xff)},
end: Core{pc: 1, st0: 0xff, d: stack{sp: 1}},
},
{
- ins: []Instruction{Lit(0xff), Lit(0xfe)},
+ ins: []Instruction{Literal(0xff), Literal(0xfe)},
end: Core{pc: 2, st0: 0xfe, d: stack{data: [0x20]uint16{0x00, 0x00, 0xff}, sp: 2}},
},
{ // dup
- ins: []Instruction{Lit(0xff), ALU{Opcode: opT, TtoN: true, Ddir: 1}},
+ ins: []Instruction{Literal(0xff), ALU{Opcode: opT, TtoN: true, Ddir: 1}},
end: Core{pc: 2, st0: 0xff, d: stack{data: [0x20]uint16{0x00, 0x00, 0xff}, sp: 2}},
},
{ // over
- ins: []Instruction{Lit(0xaa), Lit(0xbb), ALU{Opcode: opN, TtoN: true, Ddir: 1}},
+ ins: []Instruction{Literal(0xaa), Literal(0xbb), ALU{Opcode: opN, TtoN: true, Ddir: 1}},
end: Core{pc: 3, st0: 0xaa, d: stack{data: [0x20]uint16{0x00, 0x00, 0xaa, 0xbb}, sp: 3}},
},
{ // invert
- ins: []Instruction{Lit(0x00ff), ALU{Opcode: opNotT}},
+ ins: []Instruction{Literal(0x00ff), ALU{Opcode: opNotT}},
end: Core{pc: 2, st0: 0xff00, d: stack{sp: 1}},
},
{ // +
- ins: []Instruction{Lit(1), Lit(2), ALU{Opcode: opTplusN, Ddir: -1}},
+ ins: []Instruction{Literal(1), Literal(2), ALU{Opcode: opTplusN, Ddir: -1}},
end: Core{pc: 3, st0: 3, d: stack{data: [0x20]uint16{0, 0, 1}, sp: 1}},
},
{ // swap
- ins: []Instruction{Lit(2), Lit(3), ALU{Opcode: opN, TtoN: true}},
+ ins: []Instruction{Literal(2), Literal(3), ALU{Opcode: opN, TtoN: true}},
end: Core{pc: 3, st0: 2, d: stack{data: [0x20]uint16{0, 0, 3}, sp: 2}},
},
{ // nip
- ins: []Instruction{Lit(2), Lit(3), ALU{Opcode: opT, Ddir: -1}},
+ ins: []Instruction{Literal(2), Literal(3), ALU{Opcode: opT, Ddir: -1}},
end: Core{pc: 3, st0: 3, d: stack{data: [0x20]uint16{0, 0, 2}, sp: 1}},
},
{ // drop
- ins: []Instruction{Lit(2), Lit(3), ALU{Opcode: opN, Ddir: -1}},
+ ins: []Instruction{Literal(2), Literal(3), ALU{Opcode: opN, Ddir: -1}},
end: Core{pc: 3, st0: 2, d: stack{data: [0x20]uint16{0, 0, 2}, sp: 1}},
},
{ // ;
@@ -95,15 +95,15 @@ func TestEval(t *testing.T) {
end: Core{pc: 11, r: stack{data: [0x20]uint16{0, 2, 22}, sp: 1}},
},
{ // >r
- ins: []Instruction{Lit(10), ALU{Opcode: opN, TtoR: true, Ddir: -1, Rdir: 1}},
+ ins: []Instruction{Literal(10), ALU{Opcode: opN, TtoR: true, Ddir: -1, Rdir: 1}},
end: Core{pc: 2, r: stack{data: [0x20]uint16{0, 10}, sp: 1}},
},
{ // r>
- ins: []Instruction{Lit(10), Call(20), ALU{Opcode: opR, TtoN: true, TtoR: true, Ddir: 1, Rdir: -1}},
+ ins: []Instruction{Literal(10), Call(20), ALU{Opcode: opR, TtoN: true, TtoR: true, Ddir: 1, Rdir: -1}},
end: Core{pc: 21, st0: 4, d: stack{data: [0x20]uint16{0, 0, 10}, sp: 2}, r: stack{data: [0x20]uint16{10, 4}}},
},
{ // r@
- ins: []Instruction{Lit(10), ALU{Opcode: opR, TtoN: true, TtoR: true, Ddir: 1}},
+ ins: []Instruction{Literal(10), ALU{Opcode: opR, TtoN: true, TtoR: true, Ddir: 1}},
end: Core{pc: 2, d: stack{data: [0x20]uint16{0, 0, 10}, sp: 2}, r: stack{data: [0x20]uint16{10}}},
},
{ // @
@@ -111,7 +111,7 @@ func TestEval(t *testing.T) {
end: Core{pc: 1},
},
{ // !
- ins: []Instruction{Lit(1), Lit(0), ALU{Opcode: opN, NtoAtT: true, Ddir: -1}},
+ ins: []Instruction{Literal(1), Literal(0), ALU{Opcode: opN, NtoAtT: true, Ddir: -1}},
end: Core{pc: 3, st0: 1, d: stack{data: [0x20]uint16{0, 0, 1}, sp: 1}, memory: [0x2000]uint16{1}},
},
}
diff --git a/parse.go b/parse.go
index e87703c..14d025b 100644
--- a/parse.go
+++ b/parse.go
@@ -6,11 +6,11 @@ import "fmt"
func Decode(v uint16) Instruction {
switch {
case v&(1<<15) == 1<<15:
- return newLit(v)
+ return newLiteral(v)
case v&(7<<13) == 0<<13:
return newJump(v)
case v&(7<<13) == 1<<13:
- return newCond(v)
+ return newConditional(v)
case v&(7<<13) == 2<<13:
return newCall(v)
case v&(7<<13) == 3<<13:
@@ -25,20 +25,20 @@ type Instruction interface {
compile() uint16
}
-// Lit is a literal
+// Literal value
//
// 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
// │ └──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴── value
// └─────────────────────────────────────────────── 1
//
-type Lit uint16
+type Literal uint16
-func newLit(v uint16) Lit { return Lit(v &^ uint16(1<<15)) }
-func (v Lit) String() string { return fmt.Sprintf("LIT %0.4X", uint16(v)) }
-func (v Lit) value() uint16 { return uint16(v) }
-func (v Lit) compile() uint16 { return v.value() | (1 << 15) }
+func newLiteral(v uint16) Literal { return Literal(v &^ uint16(1<<15)) }
+func (v Literal) String() string { return fmt.Sprintf("LIT %0.4X", uint16(v)) }
+func (v Literal) value() uint16 { return uint16(v) }
+func (v Literal) compile() uint16 { return v.value() | (1 << 15) }
-// Jump is an unconditional branch
+// Jump instruction
//
// 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
// │ │ │ └──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴── target
@@ -51,20 +51,20 @@ func (v Jump) String() string { return fmt.Sprintf("UBRANCH %0.4X", uint16(v<<1
func (v Jump) value() uint16 { return uint16(v) }
func (v Jump) compile() uint16 { return v.value() }
-// Cond is a conditional branch
+// Conditional jump instruction
//
// 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
// │ │ │ └──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴── target
// └──┴──┴───────────────────────────────────────── 0 0 1
//
-type Cond uint16
+type Conditional uint16
-func newCond(v uint16) Cond { return Cond(v &^ uint16(7<<13)) }
-func (v Cond) String() string { return fmt.Sprintf("0BRANCH %0.4X", uint16(v<<1)) }
-func (v Cond) value() uint16 { return uint16(v) }
-func (v Cond) compile() uint16 { return v.value() | (1 << 13) }
+func newConditional(v uint16) Conditional { return Conditional(v &^ uint16(7<<13)) }
+func (v Conditional) String() string { return fmt.Sprintf("0BRANCH %0.4X", uint16(v<<1)) }
+func (v Conditional) value() uint16 { return uint16(v) }
+func (v Conditional) compile() uint16 { return v.value() | (1 << 13) }
-// Call procedure
+// Call instruction
//
// 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
// │ │ │ └──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴── target
diff --git a/parse_test.go b/parse_test.go
index 9652b60..859f933 100644
--- a/parse_test.go
+++ b/parse_test.go
@@ -12,12 +12,12 @@ func TestDecode(t *testing.T) {
}{
{0x0000, Jump(0x0000)},
{0x1fff, Jump(0x1fff)},
- {0x2000, Cond(0x0000)},
- {0x3fff, Cond(0x1fff)},
+ {0x2000, Conditional(0x0000)},
+ {0x3fff, Conditional(0x1fff)},
{0x4000, Call(0x0000)},
{0x5fff, Call(0x1fff)},
- {0x8000, Lit(0x0000)},
- {0xffff, Lit(0x7fff)},
+ {0x8000, Literal(0x0000)},
+ {0xffff, Literal(0x7fff)},
{0x6000, ALU{Opcode: 0}},
{0x6100, ALU{Opcode: 1}},
{0x7000, ALU{Opcode: 0, RtoPC: true}},