From dbb11cdcde7d90cab20cc552218e1811781a92ae Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Mon, 5 Jun 2017 19:59:23 +0200 Subject: Make lint happy --- eval.go | 10 +++++++--- parse.go | 28 ++++++++++++++++++---------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/eval.go b/eval.go index 0caeaa0..43ec195 100644 --- a/eval.go +++ b/eval.go @@ -7,6 +7,7 @@ import ( "io/ioutil" ) +// J1 Forth processor VM type J1 struct { dsp uint16 // 5 bit Data stack pointer st0 uint16 // 5 bit Return stack pointer @@ -24,6 +25,7 @@ func (vm *J1) String() string { return s } +// LoadBytes into memory func (vm *J1) LoadBytes(data []byte) error { size := len(data) >> 1 if size > len(vm.memory) { @@ -32,6 +34,7 @@ func (vm *J1) LoadBytes(data []byte) error { return binary.Read(bytes.NewReader(data), binary.BigEndian, vm.memory[:size]) } +// LoadFile into memory func (vm *J1) LoadFile(fname string) error { data, err := ioutil.ReadFile(fname) if err != nil { @@ -40,6 +43,7 @@ func (vm *J1) LoadFile(fname string) error { return vm.LoadBytes(data) } +// Eval evaluates content of memory func (vm *J1) Eval() { for { ins := Decode(vm.memory[vm.pc]) @@ -58,7 +62,7 @@ func (vm *J1) eval(ins Instruction) { case Lit: vm.st0 = uint16(v) vm.dstack[vm.dsp] = vm.st0 - vm.dsp += 1 + vm.dsp++ case Jump: next = uint16(v) case Cond: @@ -66,10 +70,10 @@ func (vm *J1) eval(ins Instruction) { next = uint16(v) } vm.st0 = vm.dstack[vm.dsp] - vm.dsp -= 1 + vm.dsp-- case Call: vm.rstack[vm.rsp] = next - vm.rsp += 1 + vm.rsp++ next = uint16(v) case ALU: if v.RtoPC { diff --git a/parse.go b/parse.go index da363f0..1a768c6 100644 --- a/parse.go +++ b/parse.go @@ -6,6 +6,7 @@ import ( "os" ) +// ReadBin file func ReadBin(fname string) ([]uint16, error) { fd, err := os.Open(fname) if err != nil { @@ -24,6 +25,7 @@ func ReadBin(fname string) ([]uint16, error) { return body, nil } +// Decode instruction func Decode(v uint16) Instruction { switch { case v&(1<<15) != 0: @@ -40,34 +42,40 @@ func Decode(v uint16) Instruction { return nil } +// Instruction interface type Instruction interface { isInstruction() } +// Lit is a literal type Lit 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) isInstruction() {} +// Jump is an unconditional branch type Jump uint16 func newJump(v uint16) Jump { return Jump(v &^ uint16(7<<13)) } func (v Jump) String() string { return fmt.Sprintf("UBRANCH %0.4X", uint16(v<<1)) } func (v Jump) isInstruction() {} +// Cond is a conditional branch type Cond 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) isInstruction() {} +// Call procedure type Call uint16 func newCall(v uint16) Call { return Call(v &^ uint16(7<<13)) } func (v Call) String() string { return fmt.Sprintf("CALL %0.4X", uint16(v<<1)) } func (v Call) isInstruction() {} +// ALU instruction type ALU struct { Opcode uint16 RtoPC bool @@ -104,25 +112,25 @@ var opcodes = []string{ "N>T", "T-1", "R", "[T]", "N<