EFRP Programming EventDriven Systems AssignmentFree - PowerPoint PPT Presentation

1 / 24
About This Presentation
Title:

EFRP Programming EventDriven Systems AssignmentFree

Description:

Programming Event-Driven Systems. Assignment-Free. Zhanyong Wan, Walid Taha, and Paul Hudak ... Non-reactive behaviors. Not directly triggered by events ... – PowerPoint PPT presentation

Number of Views:43
Avg rating:3.0/5.0
Slides: 25
Provided by: zhanyo
Category:

less

Transcript and Presenter's Notes

Title: EFRP Programming EventDriven Systems AssignmentFree


1
E-FRPProgramming Event-Driven SystemsAssignment-
Free
  • Zhanyong Wan, Walid Taha, and Paul Hudak
  • Yale University
  • Department of Computer Science

2
Motivating Problem
  • Yale RoboCup Team

3
Simple RoboCup Controller (SRC)
behavior event delay
0-100
duty cycle
desired speed
SRC
0/1
power
speed
count
IR
0-100
ClkFast
ClkSlow
IncSpd
DecSpd
4
Green Boxes
event delay
  • Reactive behaviors
  • Output change triggered by event(s)
  • Immediate reaction o changes when e occurs
  • Delayed reaction o changes right after e occurs

5
Yellow Boxes
  • Non-reactive behaviors
  • Not directly triggered by events
  • Output is a pure function of input behavior(s)
  • Output changes when and only when any of the
    inputs changes

i1
o
f(i1, i2)
o f(i1, i2)
i2
6
Simple RoboCup Controller (SRC)
behavior event delay
0-100
duty cycle
desired speed
SRC
0/1
power
speed
count
IR
0-100
ClkFast
ClkSlow
IncSpd
DecSpd
7
SRC in C
  • Event handlers

init() ds s dc count power 0
onIncSpd() ds onDecSpd() ds--
onIR() s onClkFast() count
count gt 100 ? 0 count 1 power count lt
dc ? 1 0 onClkSlow() dc s lt ds ? dc
1 s gt ds ? dc 1 dc power
count lt dc ? 1 0 s 0
8
SRC in C Problem 1
  • Scattered definition

init() ds s dc count power 0
onIncSpd() ds onDecSpd() ds--
onIR() s onClkFast() count
count gt 100 ? 0 count 1 power count lt
dc ? 1 0 onClkSlow() dc s lt ds ? dc
1 s gt ds ? dc 1 dc power
count lt dc ? 1 0 s 0
duty cycle
desired speed
SRC
power
speed
count
9
SRC in C Problem 2
  • Code duplication

init() ds s dc count power 0
onIncSpd() ds onDecSpd() ds--
onIR() s onClkFast() count
count gt 100 ? 0 count 1 power count lt
dc ? 1 0 onClkSlow() dc s lt ds ? dc
1 s gt ds ? dc 1 dc power
count lt dc ? 1 0 s 0
duty cycle
desired speed
SRC
power
speed
count
10
Source of the Problems
  • Event-Oriented View

11
SRC in C Problem 3
  • Poor modularity

Change is global!
12
Solution Behavior-Oriented View
13
Our Contributions
  • The E-FRP (Event-Driven Functional Reactive
    Programming) language
  • Fits the model
  • Behavior-oriented rather than event-oriented
  • Doesnt suffer from the problems C has
  • Formal semantics
  • An E-FRP compiler
  • Generates efficient C code for PIC16C66 MCU
  • Provably correct
  • Preserves semantics
  • Resource bounded target code
  • Optimizations

14
E-FRP by Examples
  • Immediate reaction
  • Delayed reaction
  • One definition for each block in diagram
  • Formal syntax in the paper
  • Non-reactive behavior

f(i, o-)
o
i
e
o init c on e gt f(i,o)
i1
f(i1,i2)
f(i, o-)
o
o
i
i2
e
o f(i1,i2)
o init c on e gt f(i,o) later
15
What about Semantics?
  • Operational semantics
  • Input an (infinite) event sequence
  • Output an (infinite) store sequence
  • On an event, a program yields a store and is
    updated by a new program
  • Details in the paper
  • Important design choices
  • No user defined events
  • No simultaneous events
  • Simplifies semantics
  • Generates more efficient code

16
SRC in Two Languages
  • E-FRP
  • ds init 0 on IncSpd gt ds1,
  • DecSpd gt ds-1
  • s init 0 on IR gt s1,
  • ClkSlow gt 0 later
  • dc init 0 on ClkSlow gt
  • if s lt ds then dc1
  • else if s gt ds then dc-1
  • else dc
  • count init 0 on ClkFast gt
  • if count gt 100 then 0
  • else count1
  • power if count lt dc then 1
  • else 0
  • C
  • init()
  • ds s dc count power 0
  • onIncSpd() ds
  • onDecSpd() ds--
  • onIR() s
  • onClkFast()
  • count count gt 100 ? 0
  • count 1
  • power count lt dc ? 1 0
  • onClkSlow()
  • dc s lt ds ? dc 1

17
SRC in Two Languages
duty cycle
desired speed
SRC
power
speed
count
  • E-FRP
  • ds init 0 on IncSpd gt ds1,
  • DecSpd gt ds-1
  • s init 0 on IR gt s1,
  • ClkSlow gt 0 later
  • dc init 0 on ClkSlow gt
  • if s lt ds then dc1
  • else if s gt ds then dc-1
  • else dc
  • count init 0 on ClkFast gt
  • if count gt 100 then 0
  • else count1
  • power if count lt dc then 1
  • else 0
  • C
  • init()
  • ds s dc count power 0
  • onIncSpd() ds
  • onDecSpd() ds--
  • onIR() s
  • onClkFast()
  • count count gt 100 ? 0
  • count 1
  • power count lt dc ? 1 0
  • onClkSlow()
  • dc s lt ds ? dc 1

18
SRC in Two Languages
duty cycle
desired speed
SRC
power
speed
count
  • E-FRP
  • ds init 0 on IncSpd gt ds1,
  • DecSpd gt ds-1
  • s init 0 on IR gt s1,
  • ClkSlow gt 0 later
  • dc init 0 on ClkSlow gt
  • if s lt ds then dc1
  • else if s gt ds then dc-1
  • else dc
  • count init 0 on ClkFast gt
  • if count gt 100 then 0
  • else count1
  • power if count lt dc then 1
  • else 0
  • C
  • init()
  • ds s dc count power 0
  • onIncSpd() ds
  • onDecSpd() ds--
  • onIR() s
  • onClkFast()
  • count count gt 100 ? 0
  • count 1
  • power count lt dc ? 1 0
  • onClkSlow()
  • dc s lt ds ? dc 1

19
Compile E-FRP to C
  • Compilation
  • Data representation
  • Each behavior variable x in E-FRP ? two global
    variable x and x in C
  • Translation
  • For each event in E-FRP
  • Collect data dependencies
  • Determine order for assignments
  • Provably correct
  • Optimizations

20
Castling
  • Uses knowledge about compiler
  • Why is castling useful?
  • Fewer right-hand-side uses of x
  • Easier to eliminate x later

21
Unoptimized Target Code for SRC
  • Target code before optimization

onIncSpd() ds ds 1 power if count lt dc
then 1 else 0 ds ds power
if count lt dc then 1 else 0 onDecSpd() ds
ds - 1 power if count lt dc then 1 else 0
ds ds power if count lt dc then
1 else 0 onIR() s s 1 power if
count lt dc then 1 else 0 s s
power if count lt dc then 1 else 0
onClkFast() count count gt 100 ? 0
count 1 power count lt dc ? 1 0
count count power count lt dc ? 1
0 onClkSlow() s 0 dc s lt ds ? dc
1 s gt ds ? dc 1 dc power
count lt dc ? 1 0 s s dc dc power
count lt dc ? 1 0
22
Optimized Target Code for SRC
  • Target code after optimization

onIncSpd() ds ds 1 onDecSpd() ds
ds - 1 onIR() s s 1
onClkFast() count count gt 100 ? 0
count 1 power count lt dc ? 1
0 onClkSlow() dc s lt ds ? dc 1
s gt ds ? dc 1 dc power count lt dc ? 1
0 s 0
23
Related Work
  • Languages for event-driven systems

Languages for reactive systems
Declarative
Resource-bounded
Fit forevent-drivensystems
Esterel
FRP
RT-FRP
E-FRP
Lustre
24
End of Talk
  • Video of Yale soccer-bots
Write a Comment
User Comments (0)
About PowerShow.com