aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--parse.go7
-rw-r--r--parse_test.go2
2 files changed, 7 insertions, 2 deletions
diff --git a/parse.go b/parse.go
index 76579ae..0c9d5a2 100644
--- a/parse.go
+++ b/parse.go
@@ -2,7 +2,7 @@ package j1
import "fmt"
-// Decode instruction
+// Decode instruction from binary form
func Decode(v uint16) Instruction {
switch {
case isLiteral(v):
@@ -19,6 +19,11 @@ func Decode(v uint16) Instruction {
return nil
}
+// Encode instruction to binary form
+func Encode(i Instruction) uint16 {
+ return i.compile()
+}
+
// Instruction interface
type Instruction interface {
value() uint16
diff --git a/parse_test.go b/parse_test.go
index 859f933..3e7ee2c 100644
--- a/parse_test.go
+++ b/parse_test.go
@@ -39,7 +39,7 @@ func TestDecode(t *testing.T) {
if ins != tc.ins {
t.Errorf("got %v, want %v", ins, tc.ins)
}
- if v := ins.compile(); v != tc.bin {
+ if v := Encode(ins); v != tc.bin {
t.Errorf("got %v, want %v", v, tc.bin)
}
})