gengeng
[clean-tests.git] / gengen / Data / GenType / CType.icl
index c56e408..8ff9341 100644 (file)
@@ -1,7 +1,7 @@
 implementation module Data.GenType.CType
 
 import Control.Applicative
-import Control.Monad => qualified join
+import Control.Monad
 import Control.Monad.Fail
 import Control.Monad.Reader
 import Control.Monad.State
@@ -17,7 +17,8 @@ from Data.Map import :: Map(..)
 import Data.Maybe
 import Data.Tuple
 import StdEnv
-import Text
+import qualified Text
+from Text import class Text(concat), instance Text String
 
 instance MonadFail (Either String) where fail s = Left s
 
@@ -82,8 +83,7 @@ where
        ftd (TyObject ti fs) tl
                =   indent ["struct ", if tl (safe ti.gtd_name) "", " {\n"]
                >>| iindent (indent []) >>| enum ti fs >>| tell [" cons;\n"]
-               >>| indent [] >>| enum ti fs >>| tell [" cons;\n"]
-               >>| indent ["struct {\n"]
+               >>| iindent (indent ["struct {\n"])
                >>| mapM_ (iindent o iindent o fmtCons) fs
                >>| iindent (indent ["} data;\n"])
                >>| indent ["}", if tl ";" ""]
@@ -96,10 +96,9 @@ where
                        >>| indent ["} ", safe ci.gcd_name, ";\n"]
        ftd t tl = fail $ "cannot flatTypedef: " +++ toString t
 
-       
        enum :: GenericTypeDefDescriptor [(GenericConsDescriptor, [Type])] -> FTMonad
        enum ti fs = liftT (gets (lookup ti.gtd_name)) >>= \e->case e of
-               ?None = liftT (modify \s->[(ti.gtd_name, [consName ti, " {", join ", " [safe ci.gcd_name\\(ci, _)<-fs], "};\n"]):s]) >>| enum ti fs
+               ?None = liftT (modify \s->[(ti.gtd_name, [consName ti, " {", 'Text'.join ", " [safe ci.gcd_name\\(ci, _)<-fs], "};\n"]):s]) >>| enum ti fs
                ?Just _ = tell [consName ti]
 
        fmtField :: (String, Type) -> FTMonad
@@ -144,7 +143,7 @@ where
        //Enumeration
        typedef t=:(TyObject ti fs)
                | and [t =: [] \\ (_, t)<-fs] = header t
-                       [consName ti, " {", join ", " [safe ci.gcd_name\\(ci, _)<-fs], "};\n"]
+                       [consName ti, " {", 'Text'.join ", " [safe ci.gcd_name\\(ci, _)<-fs], "};\n"]
        //Single constructor, single field (box)
        typedef t=:(TyObject ti [(ci, [ty])]) = header t [] >>| tydef ti.gtd_name ci.gcd_type
        //Single constructor
@@ -155,7 +154,7 @@ where
        //Complex adt
        typedef t=:(TyObject ti fs) = header t
                ["struct ", safe ti.gtd_name, " {\n"
-               , "\tenum {", join ", " [safe ci.gcd_name\\(ci, _)<-fs], "} cons;\n"
+               , "\t", consName ti, " {", 'Text'.join ", " [safe ci.gcd_name\\(ci, _)<-fs], "} cons;\n"
                , "\tstruct {\n"]
                >>| mapM_ fmtCons fs
                >>| tell ["\t} data;\n};\n"]
@@ -182,7 +181,7 @@ where
        fmtField x (GenTypeApp l r) = fmtField x l
        fmtField x t=:(GenTypeArrow _ _)
                = mapM (fmap (concat o snd) o listen o fmtField "") (collectArgs t [])
-                       >>= \[r:as]->tell [r, " (*",x,")(",join ", " as, ")"]
+                       >>= \[r:as]->tell [r, " (*",x,")(",'Text'.join ", " as, ")"]
        where
                collectArgs (GenTypeArrow l r) c = collectArgs r (c ++ [l])
                collectArgs t c = [t:c]