From c3ca9892620ad50261b4a624c89969236754ffeb Mon Sep 17 00:00:00 2001 From: kolaente <k@knt.li> Date: Mon, 18 May 2020 21:16:03 +0200 Subject: [PATCH 1/2] Fix addnum --- hal/instructions.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/hal/instructions.go b/hal/instructions.go index 6f7e669..8d7a3e1 100644 --- a/hal/instructions.go +++ b/hal/instructions.go @@ -135,9 +135,22 @@ var InstructionJumpNeg = &Instruction{ }, } -var InstructionAddnum = &Instruction{ +var InstructionAdd = &Instruction{ + Name: "ADD", + ExecuteWithOperand: func(module *Module, operand float64) error { + index := int64(operand) + if _, ok := module.programStorage[index]; !ok { + return fmt.Errorf("index %d does not exist in program storage", index) + } + + return nil + }, +} + +var InstructionAddNum = &Instruction{ Name: "ADDNUM", - ExecuteWithOperand: func(module *Module, operand float64) { + ExecuteWithOperand: func(module *Module, operand float64) error { module.accumulator = module.accumulator + operand + return nil }, } From 1a9741d9c20bf6819cc63acff3761e16d097a4e0 Mon Sep 17 00:00:00 2001 From: kolaente <k@knt.li> Date: Mon, 18 May 2020 21:16:31 +0200 Subject: [PATCH 2/2] Add add and addnum to instructions --- hal/instructions.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hal/instructions.go b/hal/instructions.go index 8d7a3e1..318e224 100644 --- a/hal/instructions.go +++ b/hal/instructions.go @@ -45,7 +45,8 @@ var instructions = []*Instruction{ InstructionLoadNum, InstructionStore, InstructionJumpNeg, - InstructionAddnum, + InstructionAdd, + InstructionAddNum, } var InstructionStart = &Instruction{