Define and call are done

This commit is contained in:
Aearnus 2018-05-24 01:56:12 -07:00
parent 2618e5c87f
commit df5418432e
1 changed files with 9 additions and 0 deletions

View File

@ -72,6 +72,8 @@ genericTwoByteOp op arg = do
insState <- get
return $ appendBytesThenWord [op] arg insState
-- This allows you to define functions which can be called later using `call`.
-- Note: your function must end with an `rts`, I don't add that automatically
define :: String -> Instruction -> Instruction
define name definition = do
insState <- get
@ -79,6 +81,13 @@ define name definition = do
-- TODO: COMBINE THE FUNCTION DEFINITIONS HERE TOO NOT JUST BYTESTRINGS
return $ execState definition insState'
call :: String -> Instruction
call name = do
insState <- get
let pointer = case (M.lookup name (insState ^. functionTable)) of
Just ptr -> ptr
Nothing -> error ("Couldn't find function " ++ name ++ ". Perhaps it wasn't `define`d?")
jsr (Absolute $ fromIntegral pointer)
-- THE FOLLOWING WAS GENERATED BY
-- https://github.com/aearnus/assemblicom