PIL - A Platform Independent Language
-
Upload
zefhemel -
Category
Technology
-
view
3.695 -
download
1
Transcript of PIL - A Platform Independent Language
Zef Hemel, Eelco Visser
PIL: A Platform Independent Language for Retargetable DSLs
Delft University of Techology, The Netherlands
define page conference(c : Conference) { header { “Accepted papers” } list { for(p : Paper in c.papers where p.accepted) { listitem { output(p) } } }}
language status
Java in sync with ANTLR3
JavaScript in sync with ANTLR3
C# 3 in sync with ANTLR3 (except no support for -debug and -profile)
Objective-C currently catching up with release version
Ruby last working version is v3.0ea7. Catching up with v3.0b3
ANTLR back-end supportas of 4th of september 2009
DSL(model)
Platform
parse
typecheck
desugar
generate code
DSL(text)
DSL(checked)
DSL(core)
Code
pretty-print
fron
t-en
dba
ck-e
nd
DSL(model)
Platform
parse
typecheck
desugar
generate code
DSL(text)
DSL(checked)
DSL(core)
Code
pretty-print
fron
t-en
dba
ck-e
nd
page-elem-to-java: |[ list { elem* } ]| -> |[ out.print(“<ul>”); stat_elem* out.print(“</ul>”); ]| with stat_elem* := <map(elem-to-java)> elem*
Java
page-elem-to-java: |[ list { elem* } ]| -> |[ out.print(“<ul>”); stat_elem* out.print(“</ul>”); ]| with stat_elem* := <map(elem-to-java)> elem*
Java
developer platforms
Java C# Python Ruby
OOP
lambda functionsORM framework
event supportflexible syntaxinner classes
anonymous classesiterators
annotations
dynamic typing
page-elem-to-java: |[ list { elem* } ]| -> |[ out.print(“<ul>”); stat_elem* out.print(“</ul>”); ]| with stat_elem* := <map(elem-to-java)> elem*
Java
page-elem-to-python: |[ list { elem* } ]| -> |[ out.print(“<ul>”) stat_elem* out.print(“</ul>”) ]| with stat_elem* := <map(elem-to-python)> elem*
Python
traditional ILs High-level IL
machine architecture software platform
low-level high-level
abstract syntax familiarconcrete syntax
abstract from platform
familiar concrete syntax
platform interaction
easy DSL compiler integration
cheap to port
abstract from platform
familiar concrete syntax
platform interaction
easy DSL compiler integration
cheap to port
abstract from platform
familiar concrete syntax
platform interaction
easy DSL compiler integration
cheap to port
✔
simplified Java
✘ visibility modifiers✘ abstract classes✘ interfaces✘ inner/anonymous classes✘ import com.somelib.*;✘ checked exceptions✘ primitive types✘ one class per file✘ static class members
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>”); }}
Java-like syntax
abstract from platform
familiar concrete syntax
platform interaction
easy DSL compiler integration
cheap to port
✔
abstract from platform
familiar concrete syntax
platform interaction
easy DSL compiler integration
cheap to port
✔
✔
abstract from platform
familiar concrete syntax
platform interaction
easy DSL compiler integration
cheap to port
✔
✔
✔
abstract from platform
familiar concrete syntax
platform interaction
easy DSL compiler integration
cheap to port
✔
✔
✔
abstract from platform
familiar concrete syntax
platform interaction
easy DSL compiler integration
cheap to port
✔
✔
✔
✔
external class pil::web::Request { String getParameter(String name); ...}
platform-specific implementations
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); } ...}
Java implementation
import cgi
class Request(object): def __init__(self): self.fs = cgi.FieldStorage()
def getParameter(self, name): return self.fs[name] ...
Python implementation
external class db::DatabaseSession { void beginTransaction(); void rollback(); void commit(); List<Object> getAll(Class cls); void persist(Object o); void delete(Object o);}
abstract from platform
familiar concrete syntax
code-generation specific abstractions
platform interaction
easy DSL compiler integration
cheap to port
✔
✔
✔
✔
✔
abstract from platform
familiar concrete syntax
code-generation specific abstractions
platform interaction
easy DSL compiler integration
cheap to port
✔
✔
✔
✔
✔
✔
webdsl.org
twitter.com/zef
pil-lang.org