forked from blynn/compiler
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wrap4.hs
97 lines (90 loc) · 3.23 KB
/
wrap4.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
-- GHC wrapper for "methodically" and friends.
-- $ cc -c stub.c
-- $ ghci wrap4.hs stub.o
{-# LANGUAGE BlockArguments, LambdaCase #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE ExtendedDefaultRules #-}
import Prelude (Bool(..), Char, Int, Word, String, IO)
import Data.Char (chr, ord)
import qualified Prelude
import qualified Data.Map as Map
import System.IO.Unsafe (unsafePerformIO)
import System.Exit (exitSuccess)
import Text.RawString.QQ
default (Int)
_to64 :: Word -> Word -> Word
_to64 a b = Prelude.fromIntegral a Prelude.+ Prelude.fromIntegral b Prelude.* (2 :: Word) Prelude.^ 32
_lohi :: Word -> (Word, Word)
_lohi w = (Prelude.fromIntegral r, Prelude.fromIntegral q)
where (q, r) = w `Prelude.divMod` (2 Prelude.^ 32)
intFromWord :: Word -> Int
intFromWord = Prelude.fromIntegral
word64Add a b c d = _lohi $ _to64 a b Prelude.+ _to64 c d
word64Sub a b c d = _lohi $ _to64 a b Prelude.- _to64 c d
word64Mul a b c d = _lohi $ _to64 a b Prelude.* _to64 c d
word64Div a b c d = _lohi $ _to64 a b `Prelude.div` _to64 c d
word64Mod a b c d = _lohi $ _to64 a b `Prelude.mod` _to64 c d
intAdd :: Int -> Int -> Int
intAdd = (Prelude.+)
intSub :: Int -> Int -> Int
intSub = (Prelude.-)
intMul :: Int -> Int -> Int
intMul = (Prelude.*)
intDiv :: Int -> Int -> Int
intDiv = Prelude.div
intMod :: Int -> Int -> Int
intMod = Prelude.mod
intQuot :: Int -> Int -> Int
intQuot = Prelude.quot
intRem :: Int -> Int -> Int
intRem = Prelude.rem
intEq :: Int -> Int -> Bool
intEq = (Prelude.==)
intLE :: Int -> Int -> Bool
intLE = (Prelude.<=)
wordAdd :: Word -> Word -> Word
wordAdd = (Prelude.+)
wordSub :: Word -> Word -> Word
wordSub = (Prelude.-)
wordMul :: Word -> Word -> Word
wordMul = (Prelude.*)
wordDiv :: Word -> Word -> Word
wordDiv = Prelude.div
wordMod :: Word -> Word -> Word
wordMod = Prelude.mod
wordQuot :: Word -> Word -> Word
wordQuot = Prelude.quot
wordRem :: Word -> Word -> Word
wordRem = Prelude.rem
wordEq :: Word -> Word -> Bool
wordEq = (Prelude.==)
wordLE :: Word -> Word -> Bool
wordLE = (Prelude.<=)
wordFromInt :: Int -> Word
wordFromInt = Prelude.fromIntegral
charEq :: Char -> Char -> Bool
charEq = (Prelude.==)
charLE :: Char -> Char -> Bool
charLE = (Prelude.<=)
ioPure = Prelude.pure :: a -> IO a
ioBind = (Prelude.>>=) :: IO a -> (a -> IO b) -> IO b
#define ffi foreign import ccall
#define export --
#include "methodically.hs"
instance Prelude.Functor Parser where fmap = fmap
instance Prelude.Applicative Parser where pure = pure ; (<*>) = (<*>)
instance Prelude.Monad Parser where return = return ; (>>=) = (>>=)
instance Prelude.Functor (Either a) where fmap = fmap
instance Prelude.Applicative (Either a) where pure = pure ; (<*>) = (<*>)
instance Prelude.Monad (Either a) where return = return ; (>>=) = (>>=)
instance Prelude.Functor Maybe where fmap = fmap
instance Prelude.Applicative Maybe where pure = pure ; (<*>) = (<*>)
instance Prelude.Monad Maybe where return = return ; (>>=) = (>>=)
-- instance Prelude.Show Pred where showsPrec _ = showPred
-- instance Prelude.Show Type where showsPrec _ = showType
-- instance Prelude.Show Ast where showsPrec _ = showAst False
-- instance Prelude.Show Qual where showsPrec _ = showQual