summaryrefslogtreecommitdiff
path: root/DSL.hs
diff options
context:
space:
mode:
Diffstat (limited to 'DSL.hs')
-rw-r--r--DSL.hs28
1 files changed, 19 insertions, 9 deletions
diff --git a/DSL.hs b/DSL.hs
index e608bbe..3244c7f 100644
--- a/DSL.hs
+++ b/DSL.hs
@@ -32,6 +32,7 @@ data Intrinsic
| I_ROT
-- core arithmetic operations
| I_PLUS
+ | I_MINUS
deriving (Show, Eq)
data Operation
@@ -96,6 +97,7 @@ mainLexer = phrase $ mult1 $ firstOf subLexers
, ("OVER", I_OVER)
, ("ROT", I_ROT)
, ("+", I_PLUS)
+ , ("-", I_MINUS)
]
------------------------------------------------------------------------------
@@ -133,9 +135,9 @@ operationP = firstOf [ pushDataP
programP :: DSLParser Program
programP = do
- optional wsP
+ () <$ optional wsP
ops <- operationP `sepBy1` wsP
- optional wsP
+ () <$ optional wsP
eof
return ops
@@ -219,6 +221,13 @@ plus = StackModifier { smName="PLUS", smTypes=ts, smFunc=f }
f (StackInt x:StackInt y:xs) = return $ StackInt (x+y):xs
f _ = unreachable
+minus :: StackModifier
+minus = StackModifier { smName="MINUS", smTypes=ts, smFunc=f }
+ where
+ ts = [tInt, tInt]
+ f (StackInt x:StackInt y:xs) = return $ StackInt (x-y):xs
+ f _ = unreachable
+
------------------------------------------------------------------------------
-- Core operations
------------------------------------------------------------------------------
@@ -246,13 +255,14 @@ applyIntrinsic i m = do
Right s' -> return m{ stack=s' }
where
sm = case i of
- I_DUMP -> dump
- I_DROP -> drop'
- I_SWAP -> swap
- I_DUP -> dup
- I_OVER -> over
- I_ROT -> rot
- I_PLUS -> plus
+ I_DUMP -> dump
+ I_DROP -> drop'
+ I_SWAP -> swap
+ I_DUP -> dup
+ I_OVER -> over
+ I_ROT -> rot
+ I_PLUS -> plus
+ I_MINUS -> minus
------------------------------------------------------------------------------
-- Interpretation