From: Mart Lubbers Date: Thu, 21 Nov 2019 08:44:14 +0000 (+0100) Subject: structs X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=49f7dcc4c088dc816398a0c7854d75d7c2628f15;p=clean-tests.git structs --- diff --git a/struct/struct.icl b/struct/struct.icl index 97303ae..f5cb346 100644 --- a/struct/struct.icl +++ b/struct/struct.icl @@ -9,15 +9,6 @@ import Text 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 @@ -26,25 +17,33 @@ toEnumType gtd = "enum cleanc_" +++ gtd.gtd_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") @@ -59,8 +58,7 @@ gToCType{|OBJECT of gtd|} (SM f) | 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": @@ -78,14 +76,13 @@ gToCType{|RECORD of grd|} (SM f) = 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 @@ -101,19 +98,15 @@ gToCValue{|PAIR|} fl fr (PAIR l r) c = fl l [", ":fr r c] 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 @@ -127,17 +120,12 @@ gToCValue{|FIELD of gfd|} f (FIELD a) c 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{|*|} diff --git a/test.icl b/test.icl index 3289a5f..609d79e 100644 --- a/test.icl +++ b/test.icl @@ -1,10 +1,25 @@ 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 ()))]