Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
95 lines (78 sloc) 2.67 KB
module Main where
-- import Visualise
import Utils
import HN.Parser2
import Test.ParserTest
import HN.Intermediate
import HN.SplExport
import CPP.Visualise ()
import CPP.TypeProducer
import SPL.Types
import qualified SPL.Top
simpleParse = head . fromRight . parseProg
-- testCodeGen = rt compileDefinition
-- test2 = rt getDefinitionFreeVars
rt f = mapM (print . f . simpleParse) testSet
testSet =
[
-- íóìåðàëû, âûçîâû ffi-ôóíêöèè
"main = incr 2"
-- îïðåäåëåíèå ôóíêöèè, 1 ïàðàìåòð
, "main x = incr x"
-- íåñêîëüêî ïàðàìåòðîâ
, "main x z = sum x z"
-- ïåðåêðûòèå fqn-ôóíêöèè àðãóìåíòîì
, "main sum = incr sum"
-- ïåðåêðûòèå fqn-ôóíêöèè ñòàòè÷åñêîé ëîêàëüíîé
-- BROKEN íå äîëæíî áûòü typedef local
, "main x = { elist a b = sum a b\nelist x x }"
-- ïåðåêðûòèå fqn-ôóíêöèè ëîêàëüíîé ïåðåìåííîé
, "main x z = { head = incr z\nsum x head }"
-- êîíñòàíòíûå ñòðîêè
, "main = \"aaa\""
-- ëîêàëüíîå çàìûêàíèå c àðãóìåíòîì
, "main a b = { c i = sum i b\nincr (sum a (c a)) }"
-- , "main a b = { c i x = sum b (sum x i)\nd i = sum i i\nincr (c a (d a)) }"
-- ëîêàëüíàÿ ïåðåìåííàÿ
, "main x = { y = sum x x\nsum y y }"
-- & ïåðåä óêàçàòåëÿìè íà ôóíêöèè (ðåêîìåíäóåòñÿ íîâûì ñòàíäàðòîì C++)
-- áèíäåðû ïðè ïåðåäà÷å ëîêàëüíûõ ôóíêöèé àðãóìåíòàìè
-- f x y a -> f(x, y, hn::bind(impl, &main_impl::a))
-- , "main x z l = { a = incr z\ny z = less (sum x a) z\nfilter y l }"
-- BROKEN & ïåðåä óêàçàòåëÿìè íà ñòàòè÷åñêèå ôóíêöèè
, "main l = {\n\tf x = less 1 x\n\tfilter f l\n}"
-- l*((f*(filter f l)) (x*less 1 x))
-- ïåðåêðûòèå fqn-ôóíêöèè ñòàòè÷åñêîé
, "main x = { head z a = z a x\nhead sum 5 }"
-- ñòàòè÷åñêàÿ ôóíêöèÿ
-- BROKEN íå äîëæíî áûòü typedef local
, "main x = { o a b = sum a b\no x x }"
-- polymorphic function
, "main l f = filter f l"
-- polymorphic function without free variables
, "flip f = { flipped x y = f y x\nflipped }"
, "map f l = {\n\tg x y = join1 (f x) y\n\tfoldr g elist l }"
-- parameter name conflicts with inferred type variable name
, "main a f = filter f a"
]
{-
defaultEnv = Env 1 $ M.fromList $ map (\(a, b) -> (a, simpleParse2 b)) [
("head", "(List 1) -> 1" )
, ("plus1", "Int -> Int" )
]
-}
testCheck3 = mapM (print . SPL.Top.check0 . convertExpr) [
Constant (ConstInt 123),
Atom "a",
Application (Atom "sum") $ map (Constant . ConstInt) [1, 2],
Application (Atom "incr") [Atom "x"]
]
main = do
runTests
-- testCheck3
-- rt convertDef
-- rt $ SPL.Top.check0 . convertDef
print $ cppType $ T "num"
-- testCodeGen
return ()
-- mapM (print . simpleParse2) $ [ "aaa", "aaa bbb", "aaa -> bbb", "(List 1) -> 1", "Int -> Int" ]