Disable stack modification by branching (j*) instructions

This commit is contained in:
2021-11-14 11:06:56 +01:00
parent 434d5a16ff
commit 6c50259228
3 changed files with 51 additions and 19 deletions

View File

@@ -110,6 +110,7 @@ jump [] _ = throwError "Address expected"
jumpIf :: (Int -> Int -> Bool) -> Params -> Pops -> ExceptT String Machine ()
jumpIf p (addr:_) (top:_) = lift $ do
pc <- getPc
push [top]
setPc $ if top `p` 0 then addr else pc + 2
return ()
jumpIf _ [] _ = throwError "Address expected"

View File

@@ -42,7 +42,7 @@ data Op = Nop -- 0x00
| Out -- 0x17
| Clr -- 0x18
| Roll -- 0x19
| Over -- 0x20
| Over -- 0x1A
deriving (Eq, Ord, Enum, Show, Read, Bounded)
type Machine = StateT VM IO