-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
As you can see, they're still quite incomplete. Patches welcome.
- Loading branch information
1 parent
7c84f2e
commit 91a8b95
Showing
6 changed files
with
94 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module Masque.Objects.Double where | ||
|
||
import Masque.Monte | ||
import Masque.Objects | ||
|
||
ordering :: Ord a => a -> a -> Monte Obj | ||
ordering x y = wrapInt $ case x `compare` y of | ||
LT -> -1 | ||
EQ -> 0 | ||
GT -> 1 | ||
|
||
nan :: Monte Obj | ||
nan = wrapDouble $ 0 / 0 | ||
|
||
-- | Pass a message to a Double. | ||
callDouble :: Double -> String -> [Obj] -> [(Obj, Obj)]-> Monte Obj | ||
-- Unary. | ||
callDouble d "abs" [] _ = wrapDouble $ abs d | ||
callDouble d "negate" [] _ = wrapDouble $ negate d | ||
callDouble d "sqrt" [] _ = wrapDouble $ sqrt d | ||
-- Binary. | ||
callDouble d "add" [obj] _ = do | ||
x <- coerceDouble obj | ||
wrapDouble $ d + x | ||
callDouble d "approxDivide" [obj] _ = do | ||
x <- coerceDouble obj | ||
wrapDouble $ d / x | ||
callDouble d "multiply" [obj] _ = do | ||
x <- coerceDouble obj | ||
wrapDouble $ d * x | ||
callDouble d "subtract" [obj] _ = do | ||
x <- coerceDouble obj | ||
wrapDouble $ d - x | ||
callDouble d "op__cmp" [obj] _ = do | ||
x <- coerceDouble obj | ||
if isNaN d || isNaN x then nan else ordering d x | ||
callDouble _ _ _ _ = refuse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Masque.Objects.Int where | ||
|
||
import Data.Bits | ||
|
||
import Masque.Monte | ||
import Masque.Objects | ||
|
||
-- XXX I don't have the gumption to clean this up right now | ||
callInt :: Integer -> String -> [Obj] -> [(Obj, Obj)] -> Monte Obj | ||
-- Unary | ||
-- Binary | ||
-- callInt i "op__cmp" [DoubleObj d] _ = Just $ cmp (realToFrac i) d | ||
-- callInt i "op__cmp" [IntObj j] _ = Just $ cmp i j | ||
callInt i "add" [IntObj j] _ = wrapInt $ i + j | ||
callInt i "and" [IntObj j] _ = wrapInt $ i .&. j | ||
callInt i "approxDivide" [DoubleObj d] _ = wrapDouble $ realToFrac i / d | ||
callInt i "floorDivide" [IntObj j] _ = wrapInt $ i `div` j | ||
callInt i "multiply" [DoubleObj d] _ = wrapDouble $ d * realToFrac i | ||
callInt i "multiply" [IntObj j] _ = wrapInt $ i * j | ||
callInt i "pow" [IntObj j] _ = wrapInt $ i ^ j | ||
callInt i "subtract" [IntObj j] _ = wrapInt $ i - j | ||
-- Comparison | ||
callInt i "aboveZero" [] _ = wrapBool $ i > 0 | ||
callInt i "atLeastZero" [] _ = wrapBool $ i >= 0 | ||
callInt i "atMostZero" [] _ = wrapBool $ i <= 0 | ||
callInt i "belowZero" [] _ = wrapBool $ i < 0 | ||
callInt i "isZero" [] _ = wrapBool $ i == 0 | ||
callInt _ _ _ _ = refuse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters