PIL - A Platform Independent Language

  • 2,863 views
Uploaded on

Intermediate languages are used in compiler construction to simplify retargeting compilers to multiple machine architectures. In the implementation of \emph{domain-specific languages} (DSLs), …

Intermediate languages are used in compiler construction to simplify retargeting compilers to multiple machine architectures. In the implementation of \emph{domain-specific languages} (DSLs), compilers typically generate high-level source code, rather than low-level machine instructions. DSL compilers target a software platform, i.e. a programming language with a set of libraries, deployable on one or more operating systems. DSLs enable targeting \emph{multiple} software platforms if its abstractions are platform independent. While transformations from DSL to each targeted platform are often conceptually very similar, there is little reuse between transformations due to syntactic and API differences of the target platforms, making supporting multiple platforms expensive. In this paper, we discuss the design and implementation of PIL, a Platform Independent Language, an intermediate language providing a layer of abstraction between DSL and target platform code, abstracting from syntactic and API differences between platforms, thereby removing the need for platform-specific transformations. We discuss the use of PIL in an implemementation of WebDSL, a DSL for building web applications.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
2,863
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
34
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. PIL: A Platform Independent Language for Retargetable DSLs Zef Hemel, Eelco Visser Delft University of Techology, The Netherlands
  • 2. domain-specific languages Stratego/XT
  • 3. domain-specific languages Stratego/XT
  • 4. compiler
  • 5. “traditional” compilers
  • 6. “traditional” compilers ✘ low-level ✘ complex to generate ✘ machine-specific
  • 7. DSL compilers
  • 8. DSL compilers ✔ high-level ✔ easier to generate ✔ machine-independent
  • 9. DSL generators ✔ high-level ✔ easier to generate ✔ machine-independent
  • 10. DSL generators ✔ high-level ✔ easier to generate ✔ machine-independent
  • 11. DSL generators ✔ high-level ✔ easier to generate ✔ machine-independent
  • 12. DSL generators ✔ high-level ✔ easier to generate ✔ machine-independent
  • 13. software platforms
  • 14. data model user interface logic access control workflow data validation
  • 15. define page conference(c : Conference) { header { “Accepted papers” } list { for(p : Paper in c.papers where p.accepted) { listitem { output(p) } } } }
  • 16. http://tweetview.net/ev/sle09
  • 17. WebDSL compiler
  • 18. WebDSL compiler
  • 19. java
  • 20. java python
  • 21. ANTLR
  • 22. ANTLR perl 5 python objective-c action script c c# javascript c# 3 java delphi
  • 23. perl 5 objective-c python action script c javascript java c# c# 3 delphi
  • 24. ANTLR back-end support as of 4th of september 2009 language status Java in sync with ANTLR3 JavaScript in sync with ANTLR3 in sync with ANTLR3 (except no C# 3 support for -debug and -profile) currently catching up with Objective-C release version last working version is v3.0ea7. Ruby Catching up with v3.0b3
  • 25. DSL compiler architecture
  • 26. DSL (text) parse DSL front-end (model) typecheck DSL (checked) desugar DSL (core) generate code Platform back-end pretty-print Code
  • 27. DSL (text) parse DSL front-end (model) typecheck DSL (checked) desugar DSL (core) generate code Platform back-end pretty-print Code
  • 28. retargeting a DSL compiler
  • 29. DSL (core) Platform
  • 30. DSL (core) Platform 1 Platform 2
  • 31. DSL (core) large semantic gap Platform 1 Platform 2 front-end 25,000 back-ends 10,000 each
  • 32. Java page-elem-to-java: |[ list { elem* } ]| -> |[ out.print(“<ul>”); stat_elem* out.print(“</ul>”); ]| with stat_elem* := <map(elem-to-java)> elem*
  • 33. Java page-elem-to-java: |[ list { elem* } ]| -> |[ out.print(“<ul>”); stat_elem* out.print(“</ul>”); ]| with stat_elem* := <map(elem-to-java)> elem*
  • 34. servlets
  • 35. servlets flexibility control performance
  • 36. developer platform != code generator platform
  • 37. developer platforms OOP Java C# Python Ruby
  • 38. developer platforms dynamic typing lambda functions ORM framework event support flexible syntax inner classes anonymous classes iterators annotations OOP Java C# Python Ruby
  • 39. fancy platform features
  • 40. Java page-elem-to-java: |[ list { elem* } ]| -> |[ out.print(“<ul>”); stat_elem* out.print(“</ul>”); ]| with stat_elem* := <map(elem-to-java)> elem*
  • 41. Python page-elem-to-python: |[ list { elem* } ]| -> |[ out.print(“<ul>”) stat_elem* out.print(“</ul>”) ]| with stat_elem* := <map(elem-to-python)> elem*
  • 42. language translation DSL (core) Platform 1 Platform 2
  • 43. language translation DSL (core) Platform 1 Platform 2
  • 44. Microsoft™ Java™ language conversion assistant for Visual Studio™
  • 45. Microsoft™ Java™ language conversion assistant for Visual Studio™ incomplete
  • 46. DSL (core) C JRuby
  • 47. DSL (core) C JRuby
  • 48. compatibility
  • 49. compatibility performance
  • 50. compatibility performance maintenance
  • 51. compatibility performance maintenance just for JVM and .NET
  • 52. code generation OOP Java C# Python Ruby just subset of platforms
  • 53. DSL (core) Platform 1 Platform 2 Platform n
  • 54. DSL (core) IL Platform 1 Platform 2 Platform n
  • 55. UNCOL Universal Computer Oriented Language Melvin E. Conway, 1958
  • 56. C-- O-code UNCOL Universal Computer Oriented Language P-code Melvin E. Conway, 1958 gcc’s RTL
  • 57. traditional ILs High-level IL machine software platform architecture low-level high-level familiar abstract syntax concrete syntax
  • 58. abstract from platform familiar concrete syntax cheap to port easy DSL compiler integration platform interaction
  • 59. PIL Platform Independent Language
  • 60. DSL (core) PIL Java Python ...
  • 61. abstract from platform familiar concrete syntax cheap to port easy DSL compiler integration platform interaction
  • 62. ✔ abstract from platform familiar concrete syntax cheap to port easy DSL compiler integration platform interaction
  • 63. simplified Java ✘ visibility modifiers ✘ abstract classes ✘ interfaces ✘ inner/anonymous classes ✘ import com.somelib.*; ✘ checked exceptions ✘ primitive types ✘ one class per file ✘ static class members
  • 64. .
  • 65. a.b
  • 66. a.b a = package, class, field, variable?
  • 67. PIL a::b a.b this.a.b
  • 68. Java-like syntax class page::Home extends webdsl::web::Page { String title = null; String name = null; void init(pil::web::Request request) { this.name = request.getParameter(“name”); } void render(pil::util::PrintWriter out) { out.print(“<html><head><title>” + title + “</title></head><body>”); out.print(“<h1>Welcome “ + name + “</h1>”); out.print(“</body></html>”); } }
  • 69. Object Bool Int Float Char Byte String MutableString Array<T> List<T> Set<T> Map<K,V> Exception
  • 70. 1,200 lines Stratego/platform
  • 71. ✔ abstract from platform familiar concrete syntax cheap to port easy DSL compiler integration platform interaction
  • 72. ✔ abstract from platform ✔ familiar concrete syntax cheap to port easy DSL compiler integration platform interaction
  • 73. ✔ abstract from platform ✔ familiar concrete syntax ✔ cheap to port easy DSL compiler integration platform interaction
  • 74. Stratego/XT library imports libpil-front libpil-java-backend libpil-python-backend
  • 75. stand-alone compiler $ pilc -i application.pil --java $ pilc -i application.pil --python
  • 76. ✔ abstract from platform ✔ familiar concrete syntax ✔ cheap to port easy DSL compiler integration platform interaction
  • 77. ✔ abstract from platform ✔ familiar concrete syntax ✔ cheap to port ✔ easy DSL compiler integration platform interaction
  • 78. platform interaction
  • 79. external class pil::web::Request { String getParameter(String name); ... } platform-specific implementations
  • 80. Java implementation package pil.web; import javax.servlet.http.*; public class Request { private HttpServletResponse r; public Response(HttpServletResponse r) { this.r = r; } public String getParameter(String name) { return r.getParameter(name); } ... }
  • 81. Python implementation import cgi class Request(object): def __init__(self): self.fs = cgi.FieldStorage() def getParameter(self, name): return self.fs[name] ...
  • 82. NHibernate
  • 83. NHibernate
  • 84. NHibernate
  • 85. external class db::DatabaseSession { void beginTransaction(); void rollback(); void commit(); List<Object> getAll(Class cls); void persist(Object o); void delete(Object o); }
  • 86. WebDSL ORM PIL Interface Hibernate Java Python SQLAlchemy
  • 87. query API/language?
  • 88. query API/language? persistence behavior?
  • 89. WebDSL PIL/ORM PIL Java Python
  • 90. ✔ abstract from platform ✔ familiar concrete syntax ✔ cheap to port ✔ easy DSL compiler integration ✔ code-generation specific abstractions platform interaction
  • 91. ✔ abstract from platform ✔ familiar concrete syntax ✔ cheap to port ✔ easy DSL compiler integration ✔ code-generation specific abstractions ✔ platform interaction
  • 92. conclusion
  • 93. retargetability problem: software platforms
  • 94. retargetability problem: software platforms maintaining platform back-ends is expensive
  • 95. retargetability problem: software platforms maintaining platform back-ends is expensive PIL
  • 96. retargetability problem: software platforms maintaining platform back-ends is expensive PIL PIL/G
  • 97. Java & Python back-ends
  • 98. Java & Python back-ends Stratego/XT
  • 99. Java & Python back-ends Stratego/XT
  • 100. pil-lang.org webdsl.org twitter.com/zef