From 92875bfbe007056eb77be3db8f7c9e07fec82f25 Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Thu, 18 Oct 2012 03:42:49 -0400 Subject: [PATCH] BackendK3: Minor tweaks, more math --- src/Dyna/BackendK3/AST.hs | 15 +++++++++++++++ src/Dyna/BackendK3/Render.hs | 5 ++--- src/Dyna/ParserHS/Parser.hs | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Dyna/BackendK3/AST.hs b/src/Dyna/BackendK3/AST.hs index e6620e1..53cc1ed 100644 --- a/src/Dyna/BackendK3/AST.hs +++ b/src/Dyna/BackendK3/AST.hs @@ -52,6 +52,10 @@ data Ann a where AFunDep :: (RTupled fs, RTE fs ~ a, RTR fs ~ FunDepSpec) => fs -> Ann (CTE r t a) + -- XXX Declare an additional index + -- AIndex :: (RTupled fs, RTE fs ~ a, RTR fs ~ FunDepSpec) + -- => fs -> Ann (CTE r t a) + -- | An "Exactly-One-Of" annotation, used to convey variants (i.e. sums) -- to K3. AOneOf :: (RTupled mv, RTR mv ~ Maybe) => Ann mv @@ -350,11 +354,22 @@ instance BiNum Int Int where biadd = (+) bimul = (*) +instance BiNum Int Float where + type BNTF Int Float = Float + biadd a b = ((fromIntegral a) + b) + bimul a b = ((fromIntegral a) * b) + instance BiNum Float Float where type BNTF Float Float = Float biadd = (+) bimul = (*) +instance BiNum Float Int where + type BNTF Float Int = Float + biadd a b = (a + (fromIntegral b)) + bimul a b = (a * (fromIntegral b)) + + -- XXX More ------------------------------------------------------------------------}}} diff --git a/src/Dyna/BackendK3/Render.hs b/src/Dyna/BackendK3/Render.hs index 4617438..fbb19f7 100644 --- a/src/Dyna/BackendK3/Render.hs +++ b/src/Dyna/BackendK3/Render.hs @@ -71,7 +71,7 @@ instance K3Ty (AsK3Ty e) where tColl CTBag (AsK3Ty ta) = AsK3Ty$ encBag ta tColl CTList (AsK3Ty ta) = AsK3Ty$ brackets ta - tFun (AsK3Ty ta) (AsK3Ty tb) = AsK3Ty$ ta <+> "->" <+> tb + tFun (AsK3Ty ta) (AsK3Ty tb) = AsK3Ty$ ta `above` ("->" <+> tb) tRef (AsK3Ty ta) = AsK3Ty$ "ref" <+> ta @@ -257,8 +257,7 @@ shd :: Decl (AsK3Ty e) (AsK3 e) t -> Doc e shd (Decl (Var name) tipe body) = "declare " <> text name - <> space <> colon <> space - <> unAsK3Ty tipe + <+> align (colon <+> unAsK3Ty tipe) <> case body of Nothing -> empty Just b -> space <> equals `aboveBreak` (indent 2 $ unAsK3 b 0) diff --git a/src/Dyna/ParserHS/Parser.hs b/src/Dyna/ParserHS/Parser.hs index 7069b47..72176d9 100644 --- a/src/Dyna/ParserHS/Parser.hs +++ b/src/Dyna/ParserHS/Parser.hs @@ -15,7 +15,7 @@ -- -- * Doesn't handle shared subgoals ("whenever ... { ... }") --- Header material {{{ +{- Header material -} -- {{{ {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE NoMonomorphismRestriction #-} -- 2.50.1