eval: added %

This commit is contained in:
2017-05-30 05:15:55 -04:00
parent a7f74909d7
commit 714b8a936a

View File

@@ -1,5 +1,6 @@
module BC.Eval (eval) where
import Data.Fixed (mod')
import qualified Data.HashMap as M
import BC.State
@@ -116,9 +117,17 @@ binOp "/" = Just (/)
binOp "+" = Just (+)
binOp "-" = Just ( - )
binOp "^" = Just (**)
binOp "%" = Just ownMod
binOp _ = Nothing
ownMod :: Number -> Number -> Number
ownMod (BInt x) (BInt y) = BInt $ mod x y
ownMod (BInt x) (BFloat y) = BFloat $ mod' (fromIntegral x) y
ownMod (BFloat x) (BInt y) = BFloat $ mod' x (fromIntegral y)
ownMod (BFloat x) (BFloat y) = BFloat $ mod' x y
funCall :: State -> Value -> [[Value]] -> (Value, State)
funCall state (BFun name args body) provided =
if length args == length provided