PIL - A Platform Independent Language

3,910 views

Published 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), 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.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
3,910
On SlideShare
0
From Embeds
0
Number of Embeds
262
Actions
Shares
0
Downloads
40
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

PIL - A Platform Independent Language

  1. 1. PIL: A Platform Independent Language for Retargetable DSLs Zef Hemel, Eelco Visser Delft University of Techology, The Netherlands
  2. 2. domain-specific languages Stratego/XT
  3. 3. domain-specific languages Stratego/XT
  4. 4. compiler
  5. 5. “traditional” compilers
  6. 6. “traditional” compilers ✘ low-level ✘ complex to generate ✘ machine-specific
  7. 7. DSL compilers
  8. 8. DSL compilers ✔ high-level ✔ easier to generate ✔ machine-independent
  9. 9. DSL generators ✔ high-level ✔ easier to generate ✔ machine-independent
  10. 10. DSL generators ✔ high-level ✔ easier to generate ✔ machine-independent
  11. 11. DSL generators ✔ high-level ✔ easier to generate ✔ machine-independent
  12. 12. DSL generators ✔ high-level ✔ easier to generate ✔ machine-independent
  13. 13. software platforms
  14. 14. data model user interface logic access control workflow data validation
  15. 15. define page conference(c : Conference) { header { “Accepted papers” } list { for(p : Paper in c.papers where p.accepted) { listitem { output(p) } } } }
  16. 16. http://tweetview.net/ev/sle09
  17. 17. WebDSL compiler
  18. 18. WebDSL compiler
  19. 19. java
  20. 20. java python
  21. 21. ANTLR
  22. 22. ANTLR perl 5 python objective-c action script c c# javascript c# 3 java delphi
  23. 23. perl 5 objective-c python action script c javascript java c# c# 3 delphi
  24. 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. 25. DSL compiler architecture
  26. 26. DSL (text) parse DSL front-end (model) typecheck DSL (checked) desugar DSL (core) generate code Platform back-end pretty-print Code
  27. 27. DSL (text) parse DSL front-end (model) typecheck DSL (checked) desugar DSL (core) generate code Platform back-end pretty-print Code
  28. 28. retargeting a DSL compiler
  29. 29. DSL (core) Platform
  30. 30. DSL (core) Platform 1 Platform 2
  31. 31. DSL (core) large semantic gap Platform 1 Platform 2 front-end 25,000 back-ends 10,000 each
  32. 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. 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. 34. servlets
  35. 35. servlets flexibility control performance
  36. 36. developer platform != code generator platform
  37. 37. developer platforms OOP Java C# Python Ruby
  38. 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. 39. fancy platform features
  40. 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. 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. 42. language translation DSL (core) Platform 1 Platform 2
  43. 43. language translation DSL (core) Platform 1 Platform 2
  44. 44. Microsoft™ Java™ language conversion assistant for Visual Studio™
  45. 45. Microsoft™ Java™ language conversion assistant for Visual Studio™ incomplete
  46. 46. DSL (core) C JRuby
  47. 47. DSL (core) C JRuby
  48. 48. compatibility
  49. 49. compatibility performance
  50. 50. compatibility performance maintenance
  51. 51. compatibility performance maintenance just for JVM and .NET
  52. 52. code generation OOP Java C# Python Ruby just subset of platforms
  53. 53. DSL (core) Platform 1 Platform 2 Platform n
  54. 54. DSL (core) IL Platform 1 Platform 2 Platform n
  55. 55. UNCOL Universal Computer Oriented Language Melvin E. Conway, 1958
  56. 56. C-- O-code UNCOL Universal Computer Oriented Language P-code Melvin E. Conway, 1958 gcc’s RTL
  57. 57. traditional ILs High-level IL machine software platform architecture low-level high-level familiar abstract syntax concrete syntax
  58. 58. abstract from platform familiar concrete syntax cheap to port easy DSL compiler integration platform interaction
  59. 59. PIL Platform Independent Language
  60. 60. DSL (core) PIL Java Python ...
  61. 61. abstract from platform familiar concrete syntax cheap to port easy DSL compiler integration platform interaction
  62. 62. ✔ abstract from platform familiar concrete syntax cheap to port easy DSL compiler integration platform interaction
  63. 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. 64. .
  65. 65. a.b
  66. 66. a.b a = package, class, field, variable?
  67. 67. PIL a::b a.b this.a.b
  68. 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. 69. Object Bool Int Float Char Byte String MutableString Array<T> List<T> Set<T> Map<K,V> Exception
  70. 70. 1,200 lines Stratego/platform
  71. 71. ✔ abstract from platform familiar concrete syntax cheap to port easy DSL compiler integration platform interaction
  72. 72. ✔ abstract from platform ✔ familiar concrete syntax cheap to port easy DSL compiler integration platform interaction
  73. 73. ✔ abstract from platform ✔ familiar concrete syntax ✔ cheap to port easy DSL compiler integration platform interaction
  74. 74. Stratego/XT library imports libpil-front libpil-java-backend libpil-python-backend
  75. 75. stand-alone compiler $ pilc -i application.pil --java $ pilc -i application.pil --python
  76. 76. ✔ abstract from platform ✔ familiar concrete syntax ✔ cheap to port easy DSL compiler integration platform interaction
  77. 77. ✔ abstract from platform ✔ familiar concrete syntax ✔ cheap to port ✔ easy DSL compiler integration platform interaction
  78. 78. platform interaction
  79. 79. external class pil::web::Request { String getParameter(String name); ... } platform-specific implementations
  80. 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. 81. Python implementation import cgi class Request(object): def __init__(self): self.fs = cgi.FieldStorage() def getParameter(self, name): return self.fs[name] ...
  82. 82. NHibernate
  83. 83. NHibernate
  84. 84. NHibernate
  85. 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. 86. WebDSL ORM PIL Interface Hibernate Java Python SQLAlchemy
  87. 87. query API/language?
  88. 88. query API/language? persistence behavior?
  89. 89. WebDSL PIL/ORM PIL Java Python
  90. 90. ✔ abstract from platform ✔ familiar concrete syntax ✔ cheap to port ✔ easy DSL compiler integration ✔ code-generation specific abstractions platform interaction
  91. 91. ✔ abstract from platform ✔ familiar concrete syntax ✔ cheap to port ✔ easy DSL compiler integration ✔ code-generation specific abstractions ✔ platform interaction
  92. 92. conclusion
  93. 93. retargetability problem: software platforms
  94. 94. retargetability problem: software platforms maintaining platform back-ends is expensive
  95. 95. retargetability problem: software platforms maintaining platform back-ends is expensive PIL
  96. 96. retargetability problem: software platforms maintaining platform back-ends is expensive PIL PIL/G
  97. 97. Java & Python back-ends
  98. 98. Java & Python back-ends Stratego/XT
  99. 99. Java & Python back-ends Stratego/XT
  100. 100. pil-lang.org webdsl.org twitter.com/zef

×