From 1bff92c52b27b9a516599e172fe9852c3d99be38 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Tue, 2 Apr 2024 11:27:13 +0200 Subject: chore: add linters and some lint fixes (#8) * chore: add linters and some lint fixes Configure some golangci-lint linters to get the code quality right. Apply the first fixes. Next step will be to add github actions to run lint and tests in github CI. * chore: more lint, fixed comments and variable names. no semantic change. * chore: add Makefile This makefile is intended to be used as a local substitute to github actions. --- vm/vm.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'vm') diff --git a/vm/vm.go b/vm/vm.go index 6472dae..0b2a1ad 100644 --- a/vm/vm.go +++ b/vm/vm.go @@ -11,7 +11,7 @@ const debug = true // Byte-code instruction set. const ( - // instruction effect on stack: values consumed -- values produced + // Instruction effect on stack: values consumed -- values produced. Nop = iota // -- Add // n1 n2 -- sum ; sum = n1+n2 Addr // a -- &a ; @@ -229,7 +229,7 @@ func (m *Machine) Run() (err error) { case Pop: mem = mem[:sp-int(op[2])] case Push: - //mem = append(mem, reflect.ValueOf(int(op[2]))) + // mem = append(mem, reflect.ValueOf(int(op[2]))) mem = append(mem, NewValue(TypeOf(0))) mem[sp].Data.SetInt(op[2]) case Grow: @@ -268,12 +268,14 @@ func (m *Machine) Push(v ...Value) (l int) { m.mem = append(m.mem, v...) return l } + func (m *Machine) Pop() (v Value) { l := len(m.mem) - 1 v = m.mem[l] m.mem = m.mem[:l] return v } + func (m *Machine) Top() (v Value) { if l := len(m.mem); l > 0 { v = m.mem[l-1] -- cgit v1.2.3