From: Mart Lubbers Date: Thu, 14 Nov 2019 13:12:57 +0000 (+0100) Subject: tests X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=1e730669e3113d736ffc27814aa663b54c5fb72f;p=clean-tests.git tests --- diff --git a/generic_constraints/test.icl b/generic_constraints/test.icl new file mode 100644 index 0000000..758dd3b --- /dev/null +++ b/generic_constraints/test.icl @@ -0,0 +1,17 @@ +module test + +import StdGeneric + +:: T a = T a & C a + +class C a where c :: a -> Bool +instance C Int where c _ = True + +generic g a :: a -> Bool +g{|Int|} _ = True +g{|T|} ga (T a) = f a + +f :: a -> Bool +f _ = True + +Start = g{|*|} (T 42) diff --git a/stampedShare/test.icl b/stampedShare/test.icl index 1b2445c..04a142c 100644 --- a/stampedShare/test.icl +++ b/stampedShare/test.icl @@ -1,73 +1,19 @@ module test -import Data.Func -import iTasks.Extensions.DateTime -import qualified Data.Map as DM -import qualified Data.Set as DS +import iTasks.Internal.IWorld +import System.Time import iTasks -//:: SDSStamped sds p r w = SDSStamped String (sds p (DateTime, r) (DateTime, w)) -//instance Identifiable (SDSStamped sds) | Identifiable sds -//where -// nameSDS (SDSStamped n sds) acc = ["t$":nameSDS sds ["$t":acc]] -//instance Readable (SDSStamped sds) | Readable sds -//where -// readSDS (SDSStamped name sds) p c iworld -// = case readSDS sds p c iworld of -// (Error e, iworld) = (Error e, iworld) -// (Ok (ReadResult r ssds), iworld) -// = (Ok (ReadResult r (SDSStamped name ssds)), iworld) -// (Ok (AsyncRead sds), iworld) -// = (Ok (AsyncRead (SDSStamped name sds)), iworld) -// - -:: SDSNoNotify p r w = E.sds: SDSNoNotify (sds p r w) & RWShared sds -instance Identifiable SDSNoNotify where - nameSDS (SDSNoNotify sds) c = nameSDS sds c -instance Readable SDSNoNotify where - readSDS (SDSNoNotify sds) p c iworld - = case readSDS sds p c iworld of - (Error e, iworld) = (Error e, iworld) - (Ok (ReadResult r sds), iworld) - = (Ok (ReadResult r sds), iworld) - (Ok (AsyncRead sds), iworld) - = (Ok (AsyncRead sds), iworld) - -instance Writeable SDSNoNotify where - writeSDS (SDSNoNotify sds) p c w iworld - = case writeSDS sds p c w iworld of - (Error e, iworld) = (Error e, iworld) - (Ok (WriteResult _ sds), iworld) - = (Ok (WriteResult 'DS'.newSet (SDSNoNotify sds)), iworld) - (Ok (AsyncWrite sds), iworld) - = (Ok (AsyncWrite (SDSNoNotify sds)), iworld) -instance Registrable SDSNoNotify where - readRegisterSDS (SDSNoNotify sds) p c _ _ iworld - = case readSDS sds p c iworld of - (Error e, iworld) = (Error e, iworld) - (Ok (ReadResult r sds), iworld) - = (Ok (ReadResult r sds), iworld) - (Ok (AsyncRead sds), iworld) - = (Ok (AsyncRead sds), iworld) -instance Modifiable SDSNoNotify where - modifySDS mf (SDSNoNotify sds) p c iworld - = case modifySDS mf sds p c iworld of - (Error e, iworld) = (Error e, iworld) - (Ok (ModifyResult _ r w sds), iworld) - = (Ok (ModifyResult 'DS'.newSet r w (SDSNoNotify sds)), iworld) - (Ok (AsyncModify sds mf), iworld) - = (Ok (AsyncModify (SDSNoNotify sds) mf), iworld) - - -sh = sharedStore "bork" ({DateTime|year=0,mon=0,day=0,hour=0,min=0,sec=0}, 42) +sh = sharedStore "bork2" ({Timespec|tv_sec=0,tv_nsec=0}, 42) Start w = doTasks t w -//Start w = nameSDS (SDSStamped "bork" sh) [] - -stampedShare :: (Shared sds (DateTime, a)) -> SDSLens () (DateTime, a) a | TC a & RWShared sds -stampedShare sds = - mapReadWrite (fst , \a (_, dt)->Just ((dt, a), dt)) Nothing - $ sds >*< (mapWrite (\_ _->Nothing) Nothing currentDateTime) t = viewSharedInformation [] sh - -&&- updateSharedInformation [] (stampedShare sh) + -&&- updateSharedInformation [] ( + sdsTranslate "" (\p->((), p)) + (sdsStamp sh ticker (\x y->(x, y)))) + +// This gives you 100% cpu because you get updates very fast +//t = viewSharedInformation [] ticker + +ticker = sdsFocus {start={tv_sec=0,tv_nsec=0},interval={Timespec|tv_sec=0,tv_nsec=1000000}} iworldTimespec diff --git a/struct/struct.icl b/struct/struct.icl new file mode 100644 index 0000000..c1d2bdd --- /dev/null +++ b/struct/struct.icl @@ -0,0 +1,75 @@ +module struct + +import StdEnv +import StdGeneric +import StdDebug + +import Text + +import Data.Functor +import Control.Applicative + +:: Structmaker a = SM (Int [String] -> [String]) | Onzin a + +runSM :: (Structmaker a) -> (Int [String] -> [String]) +runSM (SM a) = a + +generic gToStruct a :: Structmaker a +gToStruct{|Int|} = SM \_ c->["int":c] +gToStruct{|Real|} = SM \_ c->["double":c] +gToStruct{|Bool|} = SM \_ c->["bool":c] + +gToStruct{|UNIT|} = SM \_->id +gToStruct{|EITHER|} fl fr = SM \i->runSM fl i o runSM fr i +gToStruct{|PAIR|} fl fr + = SM \i c->runSM fl i [" f", toString i, "; ":runSM fr (i+1) c] + +gToStruct{|OBJECT of gtd|} f + | gtd.gtd_num_conses == 0 = SM (runSM f) + = SM \i c-> + ["struct clean_", gtd.gtd_name, " {\n" + ,"uint8_t cons;\n" + ,"union {\n" + :runSM f i + ["} data;\n" + ,"}":c]] +gToStruct{|CONS of gcd|} f = SM \i c->["struct { ":runSM f i ["} ", gcd.gcd_name, ";\n":c]] +gToStruct{|RECORD of grd|} f + = SM \i c-> + ["struct clean_", grd.grd_name, " {\n" + :runSM f i + ["}":c]] +gToStruct{|FIELD of gfd|} f = SM \i c->runSM f i [gfd.gfd_name,";\n":c] + +:: DHTDetails + = DHT Int Bool + | SHT Addr + | XXX Int Int Int + | XXY Int Int Int + +:: Addr =: Addr Int + +:: DHTType = DHT11 | DHT12 | DHT22 + +derive gToStruct DHTDetails +derive gToStruct DHTType +derive gToStruct Addr +derive gToStruct Record + +Start = + (concat (runSM s 0 []) + ,concat (runSM s` 0 []) + ) + +:: Record = + { field1 :: Int + , field2 :: Bool + , field3 :: DHTType + } + +s :: (Structmaker DHTDetails) +s = gToStruct{|*|} + +s` :: (Structmaker Record) +s` = gToStruct{|*|} + diff --git a/test.icl b/test.icl index 88f470b..3289a5f 100644 --- a/test.icl +++ b/test.icl @@ -1,48 +1,10 @@ module test -import Data.Func -import qualified Data.Map as DM import iTasks +import System.File +import System.Time -/* -Start w = doTasksWithOptions -// (\a o->Ok o) - (\a o->Ok {o & autoLayout=False}) - (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, \_->treturn ())) - ] -// <<@ ArrangeWithTabs True - <<@ ApplyLayout (setActionIcon ('DM'.put " " "new" 'DM'.newMap)) - ) w - -tab title _ = tune (Title title) - $ viewInformation [] title - >>* [OnAction (Action "Close") (always (treturn ()))] -*/ - -import StdDebug, Text.GenPrint -Start w = doTasks (onStartup t) w - -null :: SDSSource () () () -null = nullShare - -t = tcpconnect "localhost" 9999 (Just 500) null -//t = tcpconnect "localhost" 9999 Nothing null - { onConnect = \cid host r = trace_n (printToString ("onConnect: ", cid, host, r)) - (Ok (), Nothing, [], False) - , onData = \ data l r = trace_n (printToString ("onData: ", data, l, r)) - (Ok (), Nothing, [], False) - , onShareChange = \ l r = trace_n (printToString ("onShareChange: ", l, r)) - (Ok (), Nothing, [], False) - , onDisconnect = \ l r = trace_n (printToString ("onDisconnect: ", l, r)) - (Ok (), Nothing) - , onDestroy = \ l = trace_n (printToString ("onDestroy: ", l)) - (Ok (), []) - } +Start w + # (fi, w) = getFileInfo "/home/mrl/projects/clean/clean-tests/test.prj" w + # (ns, w) = nsTime w + = (fi, ns, w)