Semantic Modularity for DSLs
Bruno C. d. S. Oliveira The University of Hong Kong
Semantic Modularity for DSLs Bruno C. d. S. Oliveira The - - PowerPoint PPT Presentation
Semantic Modularity for DSLs Bruno C. d. S. Oliveira The University of Hong Kong Can you give a 35m talk on Domain- specific type systems using Object Algebras? Sure! That should be easy I know Object Algebras well! Humm Wait a
Bruno C. d. S. Oliveira The University of Hong Kong
DSL components
week.
Binding \x . x, \x . (\y . y) x Arithmetic 1,3+4,5*6 Logic true, false, if true then false else true Graphics point(3,4), scale(2,point(4,5))
Type-checking tcheck (n) -> Int Evaluation [x+y] -> [x] + [y] Pretty Printing pp (x+y) -> pp x + “ + “ + pp y
Arithmetic + Logic + Binding \x . if x then x+1 else x Arithmetic + Binding + Graphics \x y. point(10+x, point 10 + y)
Evaluation + Pretty Printing [x+y] -> [x] + [y] pp (x+y) -> pp x + “ + “ + pp y Evaluation + Type- Checking [x+y] -> [x] + [y] tcheck (n) -> Int
Arithmetic Logic Binding Graphics Evaluation [n] -> n [true] -> true [x] = x [point(e1,e2)] = … Type- Checking tc(n) -> Int tc(true)
tc(x,e) -> lookup(x,e) tc(point(e1,e2))
Pretty- Printing pp(n) -> n.toString pp(true) -> true.toString pp(x) = x pp(point(e1,e2 )) = …
Reflection Casts
messageNotUnderstood errors; safe composition
while still having all of the above!
Arithmetic Logic Binding Graphics Evaluation [n] -> n [true] -> true [x] = x [point(e1,e2)] = … Type- Checking tc(n) -> Int tc(true)
tc(x,e) -> lookup(x,e) tc(point(e1,e2))
Pretty- Printing pp(n) -> n.toString pp(true) -> true.toString pp(x) = x pp(point(e1,e2 )) = …
Each cell can be viewed as a separate module! Each Module should allow for:
Each composition should ensure that interpretations handle all cases
Arithmetic Logic Binding Graphics Evaluation [n] -> n [true] -> true [x] = x [point(e1,e2)] = … Type- Checking tc(n) -> Int tc(true)
tc(x,e) -> lookup(x,e) tc(point(e1,e2))
Pretty- Printing pp(n) -> n.toString pp(true) -> true.toString pp(x) = x pp(point(e1,e2 )) = …
the Expression Problem and various other (semantic) modularity issues.
languages (Java, C#, Scala, …)
signatures
signature E lit: Int → E add: E × E → E A general algebraic sign
interface IntAlg<A> { A lit(int x); A add(A e1, A e2); }
interface IntBoolAlg<A> extends IntAlg<A> { A bool(Boolean b); A iff(A e1, A e2, A e3); }
Extensibility!
Object Algebras, ECOOP (2012)
interface BatchFactory<E> { E Var(String name); // variable reference E Data(Object value); // simple constant (number, string, or date) E Fun(String var, E body); E Prim(Op op, List<E> args); // unary and binary operators E Prop(E base, String field); // field access E Assign(Op op, E target, E source); // assignment E Let(String var, E expression, E body); // control flow E If(E condition, E thenExp, E elseExp); E Loop(Op op, String var, E collection, E body); E Call(E target, String method, List<E> args); // method invocation E In(String location); // reading and writing forest E Out(String location, E expression); }
Object Algebras, ECOOP (2012)
interface PartitionFactory<E> extends BatchFactory<E> { E Other(Object external, E... subs); E DynamicCall(E target, String method, List<E> args); E Mobile(String type, Object obj, E exp); }
long some_function(); /* int */ other_function(); /* int */ calling_function() { long test1; register /* int */ test2; test1 = some_function(); if (test1 > 0) test2 = 0; else test2 = other_function(); return test2; }
GPCE (2014)
form HouseOwning { soldHouse: "Did you sell a house?" boolean boughtHouse: "Did you buy a house?" boolean if (soldHouse) { sellingPrice: "Selling price:" integer privateDebt: "Private debts:" integer valueResidue: "Value residue:" integer = (sellingPrice - privateDebt) } }
int sum = widgets.stream() .filter(b -> b.getColor() == RED) .mapToInt(b -> b.getWeight()) .sum();
submitted
Object Algebras, ECOOP (2012)
algebras:
ECOOP (2013)
(2014)
GPCE (2014)
Classes
(2005)
simpler typed languages, APLAS (2007) & JFP (2009)
(2008)
FreeVars fv(e1+e2) -> fv(e1) + + fv(e2) Substitution [x -> e] (e1+e2) -> [x -> e] e1+ [x -> e] e2
Arithmetic Logic Binding Graphics FreeVars Boring! Boring! Interesting! Boring! Substitution Boring! Boring! Interesting! Boring!