diff --git a/app/VirtualMachine/Instruction.hs b/app/VirtualMachine/Instruction.hs index 054cf79..c43c9f6 100644 --- a/app/VirtualMachine/Instruction.hs +++ b/app/VirtualMachine/Instruction.hs @@ -50,7 +50,7 @@ instructions = [ Simple { _op = Nop, _noParams = 0, _noPops = 0, _sAction = (\ , Complex { _op = Jl, _noParams = 1, _noPops = 1, _cAction = jumpIf (<) } , Complex { _op = Jge, _noParams = 1, _noPops = 1, _cAction = jumpIf (>=) } , Complex { _op = Jle, _noParams = 1, _noPops = 1, _cAction = jumpIf (<=) } - , Complex { _op = Ld, _noParams = 1, _noPops = 0, _cAction = load } + , Complex { _op = Lda, _noParams = 1, _noPops = 0, _cAction = load } , Complex { _op = In, _noParams = 0, _noPops = 0, _cAction = input } , Complex { _op = Out, _noParams = 0, _noPops = 1, _cAction = output } , Complex { _op = Clr, _noParams = 1, _noPops = 0, _cAction = clear } diff --git a/app/VirtualMachine/VM.hs b/app/VirtualMachine/VM.hs index 2d0480c..a97139d 100644 --- a/app/VirtualMachine/VM.hs +++ b/app/VirtualMachine/VM.hs @@ -37,7 +37,7 @@ data Op = Nop -- 0x00 | Jl -- 0x12 | Jge -- 0x13 | Jle -- 0x14 - | Ld -- 0x15 + | Lda -- 0x15 | In -- 0x16 | Out -- 0x17 | Clr -- 0x18 diff --git a/test/VirtualMachineSpec.hs b/test/VirtualMachineSpec.hs index effaddf..73c0e3c 100644 --- a/test/VirtualMachineSpec.hs +++ b/test/VirtualMachineSpec.hs @@ -747,12 +747,12 @@ spec = do actual <- exec vm input actual `shouldBe` expected - describe "ld" $ do + describe "lda" $ do it "lifts the function argument to the stack top" $ do let input = " push 14 \n\ \ call &f \n\ \ nop \n\ - \ f: ld 0 \n\ + \ f: lda 0 \n\ \ halt" let expected = done [14, 4, -1, 14] 7 1 actual <- run input @@ -763,9 +763,9 @@ spec = do \ push 4 \n\ \ call &f \n\ \ nop \n\ - \ f: ld 2 \n\ - \ ld 1 \n\ - \ ld 0 \n\ + \ f: lda 2 \n\ + \ lda 1 \n\ + \ lda 0 \n\ \ halt" let expected = done [4, 11, 14, 8, -1, 4, 11, 14] 15 3 actual <- run input @@ -775,15 +775,15 @@ spec = do \ push 11 \n\ \ call &sum \n\ \ halt \n\ - \ sum: ld 1 \n\ - \ ld 0 \n\ + \ sum: lda 1 \n\ + \ lda 0 \n\ \ add \n\ \ ret " let expected = done [25, 11, 14] 6 (-1) actual <- run input actual `shouldBe` expected it "raises error if stack is empty" $ do - let input = " ld 0 \n\ + let input = " lda 0 \n\ \ halt " let expected = Left "Index 0 out of stack bounds" let vm = empty { _stack = S.fromList [], _fp = 0 } @@ -791,28 +791,28 @@ spec = do actual `shouldBe` expected it "raises error if stack contains only previous fp" $ do let vm = empty { _stack = S.fromList [-1], _fp = 0 } - let input = " ld 0 \n\ + let input = " lda 0 \n\ \ halt " let expected = Left "Index 0 out of stack bounds" actual <- exec vm input actual `shouldBe` expected it "raises error if stack contains only previous fp and return address" $ do let vm = empty { _stack = S.fromList [2, -1], _fp = 0 } - let input = " ld 0 \n\ + let input = " lda 0 \n\ \ halt " let expected = Left "Index 0 out of stack bounds" actual <- exec vm input actual `shouldBe` expected it "loads the first (0) argument if stack contains only previous fp, return address and single argument" $ do let vm = empty { _stack = S.fromList [2, -1, 3], _fp = 1 } - let input = " ld 0 \n\ + let input = " lda 0 \n\ \ halt " let expected = done [3, 2, -1, 3] 2 1 actual <- exec vm input actual `shouldBe` expected it "raises error when accessint second (1) argument if stack contains only previous fp, return address and single argument" $ do let vm = empty { _stack = S.fromList [2, -1, 3], _fp = 1 } - let input = " ld 1 \n\ + let input = " lda 1 \n\ \ halt " let expected = Left "Index 1 out of stack bounds" actual <- exec vm input @@ -824,9 +824,9 @@ spec = do -- │ │ let vm = empty { _stack = S.fromList [ 2, -1, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 ], _fp = 12 } -- │ │ - -- argument indexes (ld): └─ 0 1 2 3 4 5 6 7 8 9 10 11 - -- └───── ld 11 results in pushing 0 on to the top of the stack - let input = " ld 11 \n\ + -- argument indexes (lda): └─ 0 1 2 3 4 5 6 7 8 9 10 11 + -- └───── lda 11 results in pushing 0 on to the top of the stack + let input = " lda 11 \n\ \ halt " let expected = done [0, 2, -1, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0] 2 12 actual <- exec vm input @@ -850,8 +850,8 @@ spec = do \ call &sum \n\ \ clr 2 \n\ \ halt \n\ - \ sum: ld 1 \n\ - \ ld 0 \n\ + \ sum: lda 1 \n\ + \ lda 0 \n\ \ add \n\ \ ret " let expected = done [25] 8 (-1) @@ -1004,13 +1004,13 @@ spec = do \ clr 2 \n\ \ halt \n\ \ \n\ - \ sum: ld 0 \n\ - \ ld 1 \n\ + \ sum: lda 0 \n\ + \ lda 1 \n\ \ add \n\ \ ret \n\ \ \n\ - \ prd: ld 0 \n\ - \ ld 1 \n\ + \ prd: lda 0 \n\ + \ lda 1 \n\ \ mul \n\ \ ret " let expected = done [2*3+5] 14 (-01)