//import iTasks
import iTasks._Framework.Generic
-import iTasks._Framework.Task
+from iTasks._Framework.Task import :: Task
import StdClass
from iTasks.API.Core.Types import :: Display
import gdynamic, gCons, GenEq, StdMisc, StdArray
:: In a b = In infix 0 a b
-read` :: Int (ReadWrite a) State -> (a,State) | dyn a
+read` :: Int (ReadWrite a) State` -> (a,State`) | dyn a
// ----- long ----- //
instance typeSelector Bool where typeSelector = c ".b"
instance typeSelector a where typeSelector = c ".w"
-read` :: Int (ReadWrite a) State -> (a,State) | dyn a
+read` :: Int (ReadWrite a) State` -> (a,State`) | dyn a
read` n Rd s = (fromJust (fromDyn (s.store !! n)), s)
read` n (Wrt a) s = (a,{s&store=updateAt n (toDyn a) s.store})
read` n (Updt f) s=:{store}
definition module mTaskInterpret
+from Data.Functor.Identity import :: Identity
+from Control.Monad.State import :: State, :: StateT
import mTask
:: BC
= BCNop
- | BCPush Int
+ | BCPush String
| BCPop
//Unary ops
| BCNeg
| BCMul
| BCDiv
-:: ByteCode a p = BC ((ReadWrite a) BCState -> ([BC], BCState))
+:: ByteCode a p = BC ((ReadWrite (ByteCode a Expr)) BCState -> ([BC], BCState))
:: BCState = {
a::()
}
implementation module mTaskInterpret
-import iTasks
+//import iTasks
import gdynamic, gCons, GenEq, StdMisc, StdArray
import GenPrint
import mTask
+from StdFunc import o
+import StdTuple
+import Data.Tuple
+import Control.Monad
+import Control.Monad.State
+from Data.Func import $
+
toByteVal :: BC -> String
toByteVal a = undef
toReadableByteVal :: BC -> String
toReadableByteVal a = printToString a
+//:: ByteCode a p = BC (BCState -> ([BC], BCState))
instance arith ByteCode where
- lit _ = undef
- (+.) _ _ = undef
- (-.) _ _ = undef
- (*.) _ _ = undef
- (/.) _ _ = undef
+ lit a = BC \_ s->([BCPush $ toCode a], s)
+ (+.) _ _ = undef
+ (-.) _ _ = undef
+ (*.) _ _ = undef
+ (/.) _ _ = undef
instance serial ByteCode where
- serialAvailable = undef
- serialPrint _ = undef
- serialPrintln _ = undef
- serialRead = undef
- serialParseInt = undef
-
-Start :: Main (ByteCode Int Expr)
-Start = {main=serialPrint (lit 36)}
+ serialAvailable = undef
+ serialPrint _ = undef
+ serialPrintln _ = undef
+ serialRead = undef
+ serialParseInt = undef
+
+instance zero BCState where
+ zero = {a=()}
+
+runByteCode :: (ByteCode Int Expr) BCState -> [BC]
+runByteCode (BC f) s = fst (f Rd s)
+
+//Start :: Main (ByteCode Int Expr)
+Start :: [BC]
+//Start :: ByteCode Int Expr
+Start = runByteCode (lit 36) zero
import mTask
-instance zero State
+instance zero State`
eval :: (Main (Eval t p)) -> [String] | toString t
-:: State =
- { tasks :: [(Int, State->State)]
+:: State` =
+ { tasks :: [(Int, State`->State`)]
, store :: [Dyn]
, dpins :: [(DigitalPin, Bool)]
, apins :: [(AnalogPin, Int)]
, millis:: Int
}
-//:: TaskSim :== (Int, State->State)
-:: Eval t p = E ((ReadWrite t) State -> (t, State))
-toS2S :: (Eval t p) -> (State->State)
+//:: TaskSim :== (Int, State`->State`)
+:: Eval t p = E ((ReadWrite t) State` -> (t, State`))
+toS2S :: (Eval t p) -> (State`->State`)
-unEval :: (Eval t p) -> ((ReadWrite t) State -> (t, State))
+unEval :: (Eval t p) -> ((ReadWrite t) State` -> (t, State`))
:: ReadWrite t = Rd | Wrt t | Updt (t->t)
instance + String
readPinA :: AnalogPin [(AnalogPin, Int)] -> Int
-writePinA :: AnalogPin Int State -> State
+writePinA :: AnalogPin Int State` -> State`
class readPinD p :: p [(DigitalPin,Bool)] [(AnalogPin,Int)] -> Bool
instance readPinD DigitalPin
instance readPinD AnalogPin
-class writePinD p :: p Bool State -> State
+class writePinD p :: p Bool State` -> State`
instance writePinD DigitalPin
instance writePinD AnalogPin
derive class iTask DigitalPin, AnalogPin, Dyn, StateInterface, DisplayVar, Pin
simulate :: (Main (Eval a p)) -> Task ()
-toView :: State -> StateInterface
-mergeView :: State StateInterface -> State
+toView :: State` -> StateInterface
+mergeView :: State` StateInterface -> State`
:: StateInterface =
{ serialOut :: Display [String]
, analogPins :: [(AnalogPin, Int)]
| LCD16x2 String String
| DisplayVar [String]
-step` :: State -> State
+step` :: State` -> State`
class stringQuotes t | type t :: (Code t p) -> Code t p
instance stringQuotes String
eval :: (Main (Eval t p)) -> [String] | toString t
eval {main=(E f)} = [toString (fst (f Rd zero))]
-:: State =
- { tasks :: [(Int, State->State)]
+:: State` =
+ { tasks :: [(Int, State`->State`)]
, store :: [Dyn]
, dpins :: [(DigitalPin, Bool)]
, apins :: [(AnalogPin, Int)]
, millis:: Int
}
-instance zero State where
+instance zero State` where
zero = {store = [], tasks = [], serial = [], millis = 0, dpins = [] , apins = []}
-//:: TaskSim :== (Int, State->State)
-:: Eval t p = E ((ReadWrite t) State -> (t, State))
-toS2S :: (Eval t p) -> (State->State)
+//:: TaskSim :== (Int, State`->State`)
+:: Eval t p = E ((ReadWrite t) State` -> (t, State`))
+toS2S :: (Eval t p) -> (State`->State`)
toS2S (E f) = \state.snd (f Rd state)
-unEval :: (Eval t p) -> ((ReadWrite t) State -> (t, State))
+unEval :: (Eval t p) -> ((ReadWrite t) State` -> (t, State`))
unEval (E f) = f
:: ReadWrite t = Rd | Wrt t | Updt (t->t)
[] = 0
[a:x] = a
-writePinA :: AnalogPin Int State -> State
+writePinA :: AnalogPin Int State` -> State`
writePinA p x s
= {s & apins = [(p, x):[(q, y) \\ (q, y) <- s.apins | p <> q]]}
= case [b \\ (q,b) <- lista | p == q] of
[] = False
[a:x] = a <> 0
-class writePinD p :: p Bool State -> State
+class writePinD p :: p Bool State` -> State`
instance writePinD DigitalPin where
writePinD p b s=:{dpins} = {s & dpins = [(p, b):[(q, c) \\ (q, c) <- dpins | p <> q]]}
instance writePinD AnalogPin where
]
]
-toView :: State -> StateInterface
+toView :: State` -> StateInterface
toView s =
{ serialOut = Display s.serial
, analogPins = s.apins
, taskCount = Display (length s.tasks)
}
-mergeView :: State StateInterface -> State
+mergeView :: State` StateInterface -> State`
mergeView s si =
{ s
& store = [fromDisplayVar new old \\ new <- si.var2iables & old <- s.store]
| DisplayVar [String]
-step` :: State -> State
+step` :: State` -> State`
step` s =
foldr appTask {s & millis = s.millis + delta, tasks = []}
[(w - delta, f) \\ (w, f) <- s.tasks]