Presentation is loading. Please wait.

Presentation is loading. Please wait.

A Small Composition Language 11. Piccola. © 2003, Oscar Nierstrasz PS — Piccola 1.2  Applications = Components + Scripts  Piccola layers  Forms + Agents.

Similar presentations


Presentation on theme: "A Small Composition Language 11. Piccola. © 2003, Oscar Nierstrasz PS — Piccola 1.2  Applications = Components + Scripts  Piccola layers  Forms + Agents."— Presentation transcript:

1 A Small Composition Language 11. Piccola

2 © 2003, Oscar Nierstrasz PS — Piccola 1.2  Applications = Components + Scripts  Piccola layers  Forms + Agents + Channels  Wrapping components  Status: semantics, types … Roadmap

3 © 2003, Oscar Nierstrasz PS — Piccola 1.3  Applications = Components + Scripts  Piccola layers  Forms + Agents + Channels  Wrapping components  Status: semantics, types … Roadmap

4 © 2003, Oscar Nierstrasz PS — Piccola 1.4 Applications = Components + Scripts Components both import and export services Scripts plug components together

5 © 2003, Oscar Nierstrasz PS — Piccola 1.5 Towards a Composition Language Scripting languages Configure applications from components Coordination languages Configure applications from distributed services ADLs Specify architectural styles Glue languages Adapt components

6 © 2003, Oscar Nierstrasz PS — Piccola 1.6  Applications = Components + Scripts  Piccola layers  Forms + Agents + Channels  Wrapping components  Status: semantics, types … Roadmap

7 © 2003, Oscar Nierstrasz PS — Piccola 1.7 Piccola agents compose and coordinate external components Piccola — A Small Composition Language

8 © 2003, Oscar Nierstrasz PS — Piccola 1.8 Piccola Layers Applications components + scripts Compositional styles streams, events, GUIs,... Standard libraries basic coordination abstractions, built-in types Piccola operator syntax, introspection, component wrappers Piccola-calculus forms, agents, channels, services

9 © 2003, Oscar Nierstrasz PS — Piccola 1.9  Applications = Components + Scripts  Piccola layers  Forms + Agents + Channels  Wrapping components  Status: semantics, types … Roadmap

10 © 2003, Oscar Nierstrasz PS — Piccola 1.10 Forms + Agents + Channels  Forms embody structure —immutable, extensible records —they unify components, services and namespaces  Agents embody behaviour —concurrently executing scripts —they unify concurrency and composition  Channels embody state —mailboxes for communicating agents —unify synchronization and communication.

11 © 2003, Oscar Nierstrasz PS — Piccola 1.11  A form consists of a sequence of bindings:  A script composes components by invoking services  High-level connectors hide details of object wiring. Piccola in a Nutshell helloForm =# a form text = "hello world " # a binding do : println text# a service helloForm =# a form text = "hello world " # a binding do : println text# a service makeFrame title = "AWT Demo " component = Button.new(helloForm) ? ActionPerformed helloForm.do

12 © 2003, Oscar Nierstrasz PS — Piccola 1.12 Hello World

13 © 2003, Oscar Nierstrasz PS — Piccola 1.13 Piccola Syntax Values are bound with “=”, services with “:” a = 1# binding b = (x=1, y=2)# nested binding c = (b, z=3)# extension d = c.z# projection f: a# service (no arg) println f()# application (empty form) g u: u.x + u.y# service println g(b)# application h u v: u + v# curried service println (h 1 2)# curried application a = 1# binding b = (x=1, y=2)# nested binding c = (b, z=3)# extension d = c.z# projection f: a# service (no arg) println f()# application (empty form) g u: u.x + u.y# service println g(b)# application h u v: u + v# curried service println (h 1 2)# curried application 133133 133133

14 © 2003, Oscar Nierstrasz PS — Piccola 1.14 Indentation Complex forms can be expressed by multiple indented lines b =# nested form x = 1 y = 2 println# invoke println with arg… g# invoke g with arg … b# argument to g y=b.x# extended with new binding b =# nested form x = 1 y = 2 println# invoke println with arg… g# invoke g with arg … b# argument to g y=b.x# extended with new binding Cf. Haskell and Python 22 22

15 © 2003, Oscar Nierstrasz PS — Piccola 1.15 Fixpoints Recursive services and forms are specified with the def keyword def fib n:# naïve fibonacci if n<=2 then: 1 else: fib(n-1) + fib(n-2) def fib n:# naïve fibonacci if n<=2 then: 1 else: fib(n-1) + fib(n-2) Note that if is a curried service …

16 © 2003, Oscar Nierstrasz PS — Piccola 1.16 Control structures  Control structures are defined as standard Piccola services if bool cases: 'cases=(then:(),else:(),cases) bool.select(true=cases.then, false=cases.else)() if bool cases: 'cases=(then:(),else:(),cases) bool.select(true=cases.then, false=cases.else)()

17 © 2003, Oscar Nierstrasz PS — Piccola 1.17 Local bindings and defaults Bindings are made private with the ' operator Defaults are defined by extension if bool cases: 'default =# define defaults then:() else:() 'cases = (default, cases)# set defaults 'doit = bool.select# select service true = cases.then false = cases.else doit()# invoke it if bool cases: 'default =# define defaults then:() else:() 'cases = (default, cases)# set defaults 'doit = bool.select# select service true = cases.then false = cases.else doit()# invoke it

18 © 2003, Oscar Nierstrasz PS — Piccola 1.18 Agents and Channels You can start a concurrent agent by invoking run, passing it a form with a do service. A channel is a mailbox for communicating with agents: run do: … # do something time-consuming run do: … # do something time-consuming c = newChannel()# create a channel run (do: println c.receive())# start an agent c.send("hello!")# send it a message c = newChannel()# create a channel run (do: println c.receive())# start an agent c.send("hello!")# send it a message  hello!

19 © 2003, Oscar Nierstrasz PS — Piccola 1.19 Infix and prefix operators Services may be defined as infix or prefix operators: newVar X: 'c = newChannel() 'c.send(X) *_: 'val=c.receive() 'c.send(val) val _<-_ X: 'val=c.receive() 'c.send(X) X newVar X: 'c = newChannel() 'c.send(X) *_: 'val=c.receive() 'c.send(val) val _<-_ X: 'val=c.receive() 'c.send(X) X x = newVar(1) println (*x)  1 println (x<-2)  2 x = newVar(1) println (*x)  1 println (x<-2)  2 NB: Without agents and channels, Piccola is purely functional

20 © 2003, Oscar Nierstrasz PS — Piccola 1.20 Example: Futures Agents and channels can be used to define common coordination abstractions, like futures, semaphores, readers/writers synchronization policies and so on … A “future” is a ticket for a value that is still being computed: future task: 'result = newChannel() 'run(do: result.send(task.do())) result.receive future task: 'result = newChannel() 'run(do: result.send(task.do())) result.receive f12 = future(do: fib(12)) println f12()  144 f12 = future(do: fib(12)) println f12()  144

21 © 2003, Oscar Nierstrasz PS — Piccola 1.21 Explicit namespaces Everything is a form, including the current namespace, known as root. Is just sugar for: 'x=1 root=(root,x=1)

22 © 2003, Oscar Nierstrasz PS — Piccola 1.22 Reflection Piccola provides various built-in services to inspect and manipulate forms countLabels f: 'count = newVar(0) 'forEachLabel# a standard service form = f do L: count <- 1 + *count *count countLabels f: 'count = newVar(0) 'forEachLabel# a standard service form = f do L: count <- 1 + *count *count println (countLabels root)  75 println (countLabels root)  75

23 © 2003, Oscar Nierstrasz PS — Piccola 1.23  Applications = Components + Scripts  Piccola layers  Forms + Agents + Channels  Wrapping components  Status: semantics, types … Roadmap

24 © 2003, Oscar Nierstrasz PS — Piccola 1.24 Language bridging Piccola does not provide booleans, numbers or strings — instead, these are forms that wrap Host language objects as components —Host objects are automatically wrapped as forms when imported to Piccola, and unwrapped when Host services are invoked —Special wrappers may be registered to adapt the interfaces of selected components

25 © 2003, Oscar Nierstrasz PS — Piccola 1.25 Wrapping AWT components Java AWT Frames are automatically wrapped to add a ? connector: def wrapComponent X:... _?_ aHandler aClosure:... wrapper.frame X: wrapComponent X... registerWrapper "java.awt.Frame" wrapper.frame def wrapComponent X:... _?_ aHandler aClosure:... wrapper.frame X: wrapComponent X... registerWrapper "java.awt.Frame" wrapper.frame

26 © 2003, Oscar Nierstrasz PS — Piccola 1.26  Applications = Components + Scripts  Piccola layers  Forms + Agents + Channels  Wrapping components  Status: semantics, types … Roadmap

27 © 2003, Oscar Nierstrasz PS — Piccola 1.27 Other features  Module system based on explicit namespaces  Anonymous services (lambdas)  Dynamic scoping on demand  A simple testing framework  Lists, Sets and Maps

28 © 2003, Oscar Nierstrasz PS — Piccola 1.28 Piccola Semantics The semantics of Piccola is defined using a process calculus with first-class namespaces

29 © 2003, Oscar Nierstrasz PS — Piccola 1.29 How forms support composition

30 © 2003, Oscar Nierstrasz PS — Piccola 1.30 Results so far  Piccola implementations for Java and Squeak —Sophisticated language bridging —Efficient partial evaluation —Various experimental composition styles  Formal semantics —π calculus with first-class namespaces —Limited reasoning about styles and composition  Publications and software:

31 © 2003, Oscar Nierstrasz PS — Piccola 1.31  Explicit components, connectors & styles  Type-checking provided and required services  Reasoning about styles and compositions  Adapting/reengineering existing services What’s missing?

32 © 2003, Oscar Nierstrasz PS — Piccola 1.32  Dynamic composition of ubiquitous services  Service discovery and negotiation  Reconfiguration validation and run-time monitoring  New, fine-grained models of components, composition and evolution  Component models for mobile, pervasive and embedded systems The future of composition?

33 © 2003, Oscar Nierstrasz PS — Piccola 1.33 License > Attribution-ShareAlike 2.5 You are free: to copy, distribute, display, and perform the work to make derivative works to make commercial use of the work Under the following conditions: Attribution. You must attribute the work in the manner specified by the author or licensor. Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one. For any reuse or distribution, you must make clear to others the license terms of this work. Any of these conditions can be waived if you get permission from the copyright holder. Your fair use and other rights are in no way affected by the above. Attribution-ShareAlike 2.5 You are free: to copy, distribute, display, and perform the work to make derivative works to make commercial use of the work Under the following conditions: Attribution. You must attribute the work in the manner specified by the author or licensor. Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one. For any reuse or distribution, you must make clear to others the license terms of this work. Any of these conditions can be waived if you get permission from the copyright holder. Your fair use and other rights are in no way affected by the above.


Download ppt "A Small Composition Language 11. Piccola. © 2003, Oscar Nierstrasz PS — Piccola 1.2  Applications = Components + Scripts  Piccola layers  Forms + Agents."

Similar presentations


Ads by Google