import Data.Functor
import Control.Applicative
-:: Structmaker a = SM (SData [String] -> [String]) | Onzin a
-:: SData = {indent :: Int, fresh :: Int, inRecord :: Bool}
-
-indent :: SData [String] -> [String]
-indent s c = [createArray s.indent '\t':c]
-
-show :: String SData [String] -> [String]
-show str s c = indent s [str:c]
-
toEnumValue :: GenericConsDescriptor -> String
toEnumValue gcd = gcd.gcd_type_def.gtd_name +++ "_" +++ gcd.gcd_name
class gGenerateC a | gToCType{|*|}, gToCValue{|*|}, gToCEnums{|*|} a
-:: CInfo a =
- { header :: String
- , toValue :: a -> String
- }
+:: CInfo a = {header :: String , toValue :: a -> String}
generateCInfo :: CInfo a | gGenerateC a
generateCInfo =
- let (CEnums enums) = cast res gToCEnums{|*|}
- (SM types) = cast res gToCType{|*|}
- res = { header = join "\n" (removeDup (sort enums)) +++ "\n\n" +++ concat (types {fresh=0,inRecord=False,indent=0} [])
- , toValue = \a->concat (gToCValue{|*|} a [])
- }
- in res
+ let
+ (CEnums enums) = cast res gToCEnums{|*|}
+ (SM types) = cast res gToCType{|*|}
+ res =
+ { header = concat
+ [ join "\n" (removeDup (sort enums))
+ , "\n\n"
+ , concat (types {fresh=0,inRecord=False,indent=0} [])
+ , ";"
+ ]
+ , toValue = \a->concat (gToCValue{|*|} a [])
+ }
+ in res
where
cast :: (v a) -> ((w a) -> w a)
cast _ = id
-
generic gToCType a :: Structmaker a
+:: Structmaker a = SM (SData [String] -> [String]) | StructMakerOnzin a
+:: SData = {indent :: Int, fresh :: Int, inRecord :: Bool}
+indent s c = [createArray s.indent '\t':c]
+show str s c = indent s [str:c]
+
gToCType{|Int|} = SM (show "uint64_t")
gToCType{|Real|} = SM (show "double")
gToCType{|Bool|} = SM (show "bool")
| gtd.gtd_num_conses == 0 = SM f
= SM \s c
//Enumeration (no data)
- | and [gcd.gcd_arity == 0\\gcd<-gtd.gtd_conses]
- = indent s [toEnumType gtd:c]
+ | and [gcd.gcd_arity == 0\\gcd<-gtd.gtd_conses] = indent s [toEnumType gtd:c]
//Regular ADTs
# s` = {s & indent = s.indent + 1}
= indent s ["struct clean_", gtd.gtd_name, " {\n":
= SM \s c->indent s ["struct clean_", grd.grd_name, " {\n": f {s & indent=s.indent+1, inRecord=True} (indent s ["}":c])]
gToCType{|FIELD of gfd|} (SM f) = SM \s c->f s [" ", gfd.gfd_name,";\n":c]
-:: CEnums a = CEnums [String] | Onzin2 a
+:: CEnums a = CEnums [String] | CEnumsOnzin a
generic gToCEnums a :: CEnums a
gToCEnums{|a|} = CEnums []
gToCEnums{|UNIT|} = CEnums []
gToCEnums{|EITHER|} (CEnums fl) (CEnums fr) = CEnums (fl ++ fr)
gToCEnums{|PAIR|} (CEnums fl) (CEnums fr) = CEnums (fl ++ fr)
-gToCEnums{|OBJECT of gtd|} (CEnums f)
- = CEnums [concat [toEnumType gtd, " {", join ", " (map toEnumValue gtd.gtd_conses), "};"]:f]
+gToCEnums{|OBJECT of gtd|} (CEnums f) = CEnums [concat [toEnumType gtd, " {", join ", " (map toEnumValue gtd.gtd_conses), "};"]:f]
gToCEnums{|CONS|} (CEnums f) = CEnums f
gToCEnums{|RECORD|} (CEnums f) = CEnums f
gToCEnums{|FIELD|} (CEnums f) = CEnums f
gToCValue{|OBJECT of gtd|} f (OBJECT a) c
//Newtype
| gtd.gtd_num_conses == 0 = f a c
- | and [gcd.gcd_arity == 0\\gcd<-gtd.gtd_conses]
- = f a c
+ | and [gcd.gcd_arity == 0\\gcd<-gtd.gtd_conses] = f a c
= ["{":f a ["}":c]]
gToCValue{|CONS of gcd|} f (CONS a) c
//No data field
| gcd.gcd_arity == 0 = [toEnumValue gcd:c]
- | gcd.gcd_arity == 1
- = [" .cons=",toEnumValue gcd,", .data.",gcd.gcd_name,"=":f a c]
+ | gcd.gcd_arity == 1 = [" .cons=",toEnumValue gcd,", .data.",gcd.gcd_name,"=":f a c]
= [" .cons=",toEnumValue gcd,", .data.",gcd.gcd_name,"={":f a ["} ":c]]
-gToCValue{|RECORD|} f (RECORD a) c
- = ["{":f a ["}":c]]
-gToCValue{|FIELD of gfd|} f (FIELD a) c
- = [" .", gfd.gfd_name, "=": f a c]
+gToCValue{|RECORD|} f (RECORD a) c = ["{":f a ["}":c]]
+gToCValue{|FIELD of gfd|} f (FIELD a) c = [" .", gfd.gfd_name, "=": f a c]
:: DHTDetails
= DHT Int Bool
derive class gGenerateC DHTDetails, DHTType, Addr, Record
-Start :: CInfo DHTDetails
+Start :: CInfo Record
Start = generateCInfo
:: Record =
{ field1 :: Int
, field2 :: Bool
, field3 :: DHTType
+ , field4 :: DHTDetails
}
-
-s :: (Structmaker DHTDetails)
-s = gToCType{|*|}
-
-s` :: (Structmaker Record)
-s` = gToCType{|*|}
module test
-
+import qualified Data.Map as DM
import iTasks
-import System.File
-import System.Time
+import Data.Func
+import Data.Tuple
+import StdEnv
+
+Start w = doTasksWithOptions (\a o->Ok $ flip tuple {o & autoLayout=True} $
+ (parallel
+ [(Embedded, tab "tab1")
+ ,(Embedded, tab "tab2")
+ ]
+ [ OnAction (Action "New") (always (Embedded, tab "New tab"))
+ , OnAction (Action " ") (always (Embedded, tab "New tab"))
+ , OnAction (Action "Close") (never (Embedded, \_->treturn ()))
+ , OnAction (Action "Dis no icon") (never (Embedded, \_->treturn ()))
+ , OnAction (Action "+") (always (Embedded, tab "New tab"))
+ ]
+ <<@ ArrangeWithTabs True
+ <<@ ApplyLayout (setActionIcon ('DM'.put " " "new" 'DM'.newMap))
+ )) w
-Start w
- # (fi, w) = getFileInfo "/home/mrl/projects/clean/clean-tests/test.prj" w
- # (ns, w) = nsTime w
- = (fi, ns, w)
+tab title _ = tune (Title title)
+ $ viewInformation [] ()
+ >>* [OnAction (Action "Close") (always (treturn ()))]