eval: added %
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user