1 / 28

SubScript : Extending Scala with the Algebra of Communicating Processes

SubScript : Extending Scala with the Algebra of Communicating Processes. André van Delft 17 April 2012 ScalaDays 2012, London. Overview. Why is Programming still Hard Algebra of Communicating Processes Example Application SubScript Features Experience Implementation Conclusion

tanner
Download Presentation

SubScript : Extending Scala with the Algebra of Communicating Processes

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SubScript:Extending Scala with theAlgebra of Communicating Processes • André van Delft • 17 April 2012 • ScalaDays 2012, London

  2. Overview • Why is Programming still Hard • Algebra of Communicating Processes • Example Application • SubScript Features • Experience • Implementation • Conclusion • Demonstration

  3. Why is Programming still Hard? • Parallelism • Concurrency • Event Handling • Code Execution Modes • Normal • newThread • GUI Thread • DB Thread • Event Handler • Simulation Time • Real Time • Processor Assignment

  4. Algebra of Communicating Processes - 1 Bergstra & Klop, Amsterdam, 1982 ACP~Boolean Algebra + atomic actions a,b,… + parallelism + communication + ... x+y = y+x (x+y)+z = x+(y+z) x+x = x (x+y)·z = x·z+y·z (x·y)·z = x·(y·z)

  5. Algebra of Communicating Processes - 2 • Specification & Verification • Communication Protocols • Production Plants • Railways • Coins and Coffee Machines • Money and Economy • Strengths • Familiar syntax • Precise semantics • Reasoning • Events as actions

  6. GUI application - 1 • Input Field • Search Button • Searching for… • Results

  7. GUI application - 2 • val searchButton = new Button("Go”){ • reactions.+= { • caseButtonClicked(b)=> • enabled = false • outputTA.text = "Starting search...” • newThread(newRunnable{ • defrun(){ • Thread.sleep(3000) • SwingUtilities.invokeLater(newRunnable{ • defrun() {outputTA.text="Search ready” • enabled = true • }}) • }}).start • } • }

  8. GUI application - 3 • live = clicked(searchButton) • @gui: {outputTA.text="Starting search.."} • {*Thread.sleep(3000)*} • @gui: {outputTA.text="Search ready"} • ... • Sequence operator: white space and ; • gui: code executor for SwingUtilities.InvokeLater+InvokeAndWait • {*...*}: by executor for new Thread • Enable/disable button: for free searchButton

  9. GUI application - 4 • live = searchSequence... searchSequence = searchCommand showSearchingText searchInDatabase showSearchResults searchCommand = searchButton showSearchingText= @gui: {outputTA.text = "…"} showSearchResults= @gui: {outputTA.text = "…"} searchInDatabase = {*Thread.sleep(3000)*}

  10. GUI application - 5 • Search: button or Enter key • Cancel: button or Escape key • Exit: button or ; ; “Are you sure?”… • Search only allowed when input field not empty • Progress indication

  11. GUI application - 6 • searchGuard = if(!searchTF.text.isEmpty) .anyEvent(searchTF) ... live = searchSequence... ||exit searchCommand = searchButton +Key.Enter cancelCommand = cancelButton+Key.Escape exitCommand = exitButton+windowClosing exit = exitCommand@gui:while(!areYouSure) cancelSearch = cancelCommand@gui:showCanceledText searchSequence = searchGuard searchCommand; showSearchingText searchInDatabase showSearchResults / cancelSearch searchInDatabase = {*Thread.sleep(3000)*}||progressMonitor progressMonitor = {*Thread.sleep( 250)*} @gui:{searchTF.text+=here.pass}...

  12. SubScript Features - 1 • "Scripts" – process refinements as class members • Called like methods from Scala • - with a ScriptExecutor as extra parameter • Call other scripts • Parameters: in, out?, forcing

  13. SubScript Features - 2 ACP Atomic Actions ~ Scala Code {…} start/end

  14. SubScript Features - 3

  15. SubScript Features - 4 Process Communication

  16. Experience • Scriptic: Java based predecessor • Analyse technical documentation • Input: ODF ~ XML Stream • Fun to use mixture of grammar and 'normal' code • Parser expectations to scanner • implicittext(s: String??) = @expect(here, TextToken(_s): {?accept(here)?} • implicitnumber(n: Int??) = @expect(here,NumberToken(_n): {?accept(here)?} • 30,000 accepted of 120,000 expected tokens per second

  17. Conclusion • Easy and efficient programming • Now DSL in 2000 lines of Scala code • Still much to do and to discover • Open Source:http://code.google.com/p/subscript/ • Help is welcome • Participation • Sponsoring • KickStarter • Thx Alex Schaafsma 17

  18. Demonstration Debugger built using SubScript • live = {* awaitMessageBeingHandled *} • if (shouldStep) • ( @gui: {!updateDisplay!}stepCommand • || if (autoCheckBox.isChecked) waitForStep • ) • { messageBeingHandled=false } • ... • ||exit • exit = exitCommand • @gui: {exitConfirmed=confirmExit } • while (!exitConfirmed) • def_exit = _script('exit) { • _seq(_exitCommand, • _at{gui}(_normal{exitConfirmed=confirmExit}), • _while{!exitConfirmed} • ) • }

  19. The End • Spare Slides next

  20. Experience - 2 • Low level scripts • implicit text(s: String??) = @expect(here, TextToken(_s): {?accept(here)?} • implicit number(n: Int??) = @expect(here,NumberToken(_n): {?accept(here)?} • anyText = s: String? • anyLine = anyText endOfLine • someEmptyLines = ..endOfLine • someLines = ..anyLine

  21. Experience - 3 • For-usage • tableRow(ss: String*) = startRow; for(s<-ss) cell(s); endRow • oneOf(r: String?, ss: String*) = for(s<-ss) + s {! r=s !}

  22. Experience - 4 • If-usage • footnoteRef(n: Int?) = "(" n? ")" • footnote(n: Int?, s: String?) = if (fnFormat==NUMBER_DOT) • (n? ".") • else (footnoteRef,n? "-") • s? • endOfLine

  23. Experience - 5 • Grammar ambiguity • var s: String • var n: Int • startCell s? endCell + startCell n? endCell • startCell s? endCell || startCell n? endCell • startCell s? endCell |+| startCell n? endCell • xmlTag(t: XMLTag),.. = @expect(here, t) {?accept(here)?} • startCell = xmlTag(startCellToken)

  24. Algebra of Communicating Processes Bergstra&Klop, Amsterdam, 1982 x+y = y+x (x+y)+z = x+(y+z) x+x = x (x+y)·z = x·z+y·z (x·y)·z = x·(y·z) a,b,… atomic actions O+x = x O·x = O 1·x = x x·1 = x δ+x = x δ·x = δ ε·x = x x·ε = x (x+ε)·y = x·y + ε·y = x·y + y

  25. x y = x y + y x Algebra of Communicating Processes x+y a·x δ ε (x+y)/z = x/z + y/z a·x/y = a·(x/y) + y δ/x = x ε/x = ε + x|y

  26. Sieve of Eratosthenes - 1

  27. Sieve of Eratosthenes - 2 • main = generator(2,1000000) • ==> (..==>sieve) • =={toPrint}==> printer • generator(s,e) = for(i<-s to e) <=i • sieve = =>p:Int? @toPrint:<=p; • ..=>i:Int? if (i%p!=0) <=i • printer = ..=>i:Int? println,i • <==>(i:Int) = {}

  28. Templates & Call Graphs • {Hello}+ε; {World} (x+ε)·y = x·y + ε·y = x·y + y

More Related