diff options
author | Camil Staps | 2018-01-06 22:34:14 +0100 |
---|---|---|
committer | Camil Staps | 2018-01-06 22:34:14 +0100 |
commit | 1011f38ccf1d16e820ff21c687a99b4d65b00e40 (patch) | |
tree | fd2ae838f14bc48dd3de7bc77bc6f4400b66e3b7 /assignment-13/uFPL.icl | |
parent | Working simulator with running per second (diff) |
Simulator improvements; continue with countdown example
Diffstat (limited to 'assignment-13/uFPL.icl')
-rw-r--r-- | assignment-13/uFPL.icl | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/assignment-13/uFPL.icl b/assignment-13/uFPL.icl index 129df92..234d2cd 100644 --- a/assignment-13/uFPL.icl +++ b/assignment-13/uFPL.icl @@ -98,7 +98,7 @@ instance Expr Char where litExpr c = CEChar c lit :: (t -> Expr t RO) lit = ELit -(?) infix 4 :: (Expr Bool rwa) (Expr t rwb, Expr t rwc) -> Expr t RO +(?) infix 5 :: (Expr Bool rwa) (Expr t rwb, Expr t rwc) -> Expr t RO (?) b (t,e) = EIf b t e (==.) infix 4 :: (Expr t rwa) (Expr t rwb) -> Expr Bool RO | Expr, == t @@ -116,6 +116,9 @@ lit = ELit (||.) infixr 4 :: (Expr Bool rwa) (Expr Bool rwb) -> Expr Bool RO (||.) a b = EOr bm a b +pressed :: (Expr Bool RO) -> Trigger +pressed shr = shr ?= true + instance :. Rule where (:.) a b = [a,b] instance :. [Rule] where (:.) r rs = [r:rs] @@ -275,10 +278,10 @@ where example_score :: [NamedRule] example_score = - "a" :=: b0 ?= true >>> [scorea <# scorea +. lit 1] - ||| "b" :=: b1 ?= true >>> [scoreb <# scoreb +. lit 1] - ||| "r" :=: b2 ?= true >>> [scorea <# lit 0, scoreb <# lit 0] - ||| "print" :=: Change scorea ?| Change scoreb >>> + "a" :=: pressed b0 >>> [scorea <# scorea +. lit 1] + ||| "b" :=: pressed b1 >>> [scoreb <# scoreb +. lit 1] + ||| "r" :=: pressed b2 >>> [scorea <# lit 0, scoreb <# lit 0] + ||| "print" :=: (Change scorea ?| Change scoreb) >>> SetCursor (lit 0, lit 0) :. Print scorea :. Print (lit '-') :. @@ -290,20 +293,25 @@ where example_countdown :: [NamedRule] example_countdown = "time" :=: - When (millis -. DELAY >. counter) ( + (Change millis >>> [When (millis -. DELAY >. counter) ( counter <# counter +. DELAY :. - seconds <# seconds -. lit 1 :. + seconds <# running ? (seconds -. lit 1, seconds) :. SetCursor (lit 0, lit 0) :. Print minutes :. Print (lit ':') :. Print seconds - ) :. - When (seconds ==. lit 0) (seconds <# lit 60 :. minutes <# minutes -. lit 1) - ||| "status" :=: - When (seconds ==. lit 60 &&. minutes ==. lit 0) [running <# false] + )]) :. + When (seconds ==. lit 0 &&. minutes >. lit 0) (seconds <# lit 60 :. minutes <# minutes -. lit 1) :. + When (seconds <. lit 0) [seconds <# lit 0] :. + When (minutes <. lit 0) [minutes <# lit 0] :. + When (seconds ==. lit 0 &&. minutes ==. lit 0) [running <# false] + ||| "setsec" :=: pressed b0 >>> [seconds <# seconds +. lit 1] + ||| "setmin" :=: pressed b1 >>> [minutes <# minutes +. lit 1] + ||| "on_off" :=: pressed b2 >>> [running <# running ? (false, true)] + ||| "reset" :=: pressed b3 >>> [seconds <# lit 0, minutes <# lit 0] where running = rwBool "running" False minutes = rwUInt "minutes" 0 seconds = rwUInt "seconds" 0 - counter = rwULong "counter" 1000 // If set to 0, this will overflow on first iteration + counter = rwULong "counter" 0 // If set to 0, this will overflow on first iteration DELAY = lit 1000 |