From bf5d24fc841dce5fc311c26f0dffac9be8196c0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Przemys=C5=82aw=20Pluta?= Date: Mon, 8 Nov 2021 22:00:54 +0100 Subject: [PATCH] Implement DBG instruction --- app/VirtualMachine.hs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/VirtualMachine.hs b/app/VirtualMachine.hs index 7a3cede..5f4bcc5 100644 --- a/app/VirtualMachine.hs +++ b/app/VirtualMachine.hs @@ -54,6 +54,7 @@ data Op = Nop -- 0x00 | Ld -- 0x15 | In -- 0x16 | Out -- 0x17 + | Dbg -- 0x18 deriving (Eq, Ord, Enum, Show, Read, Bounded) type Args = [Int] @@ -103,6 +104,7 @@ instructions = [ Simple { _op = Nop, _noParams = 0, _noPops = 0, _sAction = (\ , Complex { _op = Jge, _noParams = 1, _noPops = 1, _cAction = jumpIf (>=) } , Complex { _op = Jle, _noParams = 1, _noPops = 1, _cAction = jumpIf (<=) } , Complex { _op = Out, _noParams = 0, _noPops = 1, _cAction = output } + , Complex { _op = Dbg, _noParams = 0, _noPops = 0, _cAction = debug } ] jumpIf :: (Int -> Int -> Bool) -> VM -> Args -> Pops -> ExceptT String IO VM @@ -117,6 +119,11 @@ output vm _ (char:_) = do liftIO $ putStr $ [chr char] return vm { _pc = _pc vm + 1, _stack = S.drop 1 $ _stack vm} +debug :: VM -> Args -> Pops -> ExceptT String IO VM +debug vm _ _ = do + liftIO $ print vm + return vm { _pc = _pc vm + 1 } + instructionByOp :: M.Map Op Instruction instructionByOp = M.fromList $ map (\i -> (_op i, i)) instructions