From e4b7bcd0903b4d2bcfe305e4e78415e32a3a32b5 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Fri, 1 Mar 2019 17:14:49 +0100 Subject: add encode --- parse.go | 7 ++++++- parse_test.go | 2 +- 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) } }) -- cgit v1.2.3