University of British Columbia Software Practices Lab Expressive Programs Through Presentation...
-
date post
19-Dec-2015 -
Category
Documents
-
view
216 -
download
2
Transcript of University of British Columbia Software Practices Lab Expressive Programs Through Presentation...
University of British Columbia
Software Practices Lab
Expressive Programs
Through Presentation
ExtensionAndrew D. Eisenberg
andGregor Kiczales
Andrew Eisenberg and Gregor Kiczales — University of British Columbia 2
Code that Looks Like the Design
Andrew Eisenberg and Gregor Kiczales — University of British Columbia 3
Code that Looks Like the Design
Andrew Eisenberg and Gregor Kiczales — University of British Columbia 4
• Familiar goals, many approaches– Languages
• abstraction level, domain specificity, extensibility…– Editors
• language aware, highlighting, formatting…
• Contributions – New editor/compiler architecture
• synergistic presentation and semantic extensibility• compatible with existing code, tools, practice
– Eclipse-based implementation– Examples
• how light-touch uses of idea can be powerful
Code that Looks Like the Design
Andrew Eisenberg and Gregor Kiczales — University of British Columbia 5
Desirable Properties• Extensibility
– presentation • more than colors, fonts—substantial
difference from concrete syntax• free-form editing
– semantic• like syntax macros
– (abstract syntax graph, not tree)
• Compatibility– with existing code, tools– incremental adoption
• Traceability– of errors– for other tools
Andrew Eisenberg and Gregor Kiczales — University of British Columbia 6
Tool chains
Raw Text (Byte) Code
Other Tools
Display/Edit
Compiler/
Interpreter
Editor
Gnu/Linux
•Language extensibility•code formatting (colors, bold, italics, etc)•text pre-processors
•Communication is line number and character-based
Andrew Eisenberg and Gregor Kiczales — University of British Columbia 7
semantic extensibility
Syntax Macros
AST Expanded AST
Other Tools
Display/Edit
Lisp/Scheme
Raw Text (Byte) Code
•Language extensibility•code formatting•macros
•Communication is line number and character-based
Andrew Eisenberg and Gregor Kiczales — University of British Columbia 8
(Byte) CodeExpanded AST
Structure (Syntax-Directed) Editors
AST
InterlispCornell Program Synthesizer
Other Tools
Display/Edit
Raw Text
•Language extensibility•code formatting•pretty-printing (line breaks, white space, etc)•macros
•Communication between display and byte code can be AST-based
semantic extensibility
Andrew Eisenberg and Gregor Kiczales — University of British Columbia 9
State of the Practice IDEs
•AST easy to create from raw text•cheap, reliable, and fast•incremental•simultaneous maintenance of raw text & AST
•Communication is line-number or AST-based•Restricted extensibility
Eclipse, IntelliJ, Visual Studio, …
Other Tools
AST
Display/Edit
Raw Text (Byte) Code
semantic extensibility
Andrew Eisenberg and Gregor Kiczales — University of British Columbia 10
Raw Text
Display-Driven AST
•AST*—Abstract Syntax Graph•more freedom in displaying code
•Program store is determined by editor•communication is AST-based only•cannot use text-based tools
•Language extensibility•presentation•macros (DrScheme) and AST expansion (Intentional Programming)
DrSchemeIntentional ProgrammingSubtext
Other Tools
Display(AST*)
(Byte) Code
Store
AST
Expanded AST
semantic extensibility
presentation extensibility
Andrew Eisenberg and Gregor Kiczales — University of British Columbia 11
(Byte) CodeExpanded AST
Other Tools
Display/Edit
Raw Text
Presentation Extension of Plain Text
•Language extensibility•presentation•syntactic
•Compatible with modern IDEs•Tool infrastructure•Raw text is accessible
(with syntactic extension)
AST*
semantic extensibility
presentation extensibility
Andrew Eisenberg and Gregor Kiczales — University of British Columbia 12
ExpandedAST
Architecture
Legacy Tools
Display
AST
Byte CodeRaw Text
Andrew Eisenberg and Gregor Kiczales — University of British Columbia 13
ExpandedAST
Architecture
Display
AST
Byte Code
Legacy Tools
Raw Text
Andrew Eisenberg and Gregor Kiczales — University of British Columbia 14
ExpandedAST
Architecture
Display
AST
Byte CodeRaw Text
Andrew Eisenberg and Gregor Kiczales — University of British Columbia 15
Raw Text
ExpandedAST
Architecture
Display
Byte Code
AST
Pair of disjoint, but communicating metaobject protocols
Andrew Eisenberg and Gregor Kiczales — University of British Columbia 16
Implementation
Display
Byte Code
AST
Expanded AST
AST+EditMOs
AST+CompileMOs
Boxes
Controllers
M V
C
Error
Propagation
CTMOP
ETMOP
Pair of disjoint, but communicating metaobject protocols
Raw Text
Edit-Time Metaobject Protocol
Compile-Time Metaobject Protocol
Andrew Eisenberg and Gregor Kiczales — University of British Columbia 17
Traceability
Display
Byte Code
AST
Expanded AST
AST+EMOs
AST+CMOs
Boxes
Controllers
CTMOP
ETMOP
Pair of disjoint, but communicating metaobject protocols
Pair of disjoint, but communicating metaobject protocols
Raw Text
Edit-Time Metaobject Protocol
Compile-Time Metaobject Protocol
Andrew Eisenberg and Gregor Kiczales — University of British Columbia 18
Traceability Allows Error Propagation
Andrew Eisenberg and Gregor Kiczales — University of British Columbia 19
Traceability Allows Code Completion
Andrew Eisenberg and Gregor Kiczales — University of British Columbia 20
• Can be used to create graph edges
• Annotations are familiar
• Annotations work with existing tools
• Valid Java syntax
• Attached to source code
@Getter("get")
@Setter("set")
private int x;
@Previous
private int y;
Metaobjects Serialize to Annotations
Andrew Eisenberg and Gregor Kiczales — University of British Columbia 21
AspectJ Code Style↔Annotation Style
@org.aspectj.lang.annotation.Aspect()
class PointObserving{
@org.aspectj.lang.annotation.After(value="changes(p)")
void advice$aj$0(Point p){
Screen.notify();
}
@org.aspectj.lang.annotation.Pointcut(
"this(p) && execution(void Point.set*(int))")
void changes(Point p){}
}
Andrew Eisenberg and Gregor Kiczales — University of British Columbia 22
Uses
@ca.ubc.cs.etmop.annotations.Uses(
type=BufferedReader.class,
name="file",
init="new BufferedReader(new FileReader(fName))")
public String getFileContents(String fName) {
...
}
Andrew Eisenberg and Gregor Kiczales — University of British Columbia 23
Only presentation extensibility, no semantic
Backquote—Code Generation
return makeMethod( makeModifiers(PUBLIC), makeVoid(), makeName(makeSetterName(varName)), makeParameters( makeParameter(makeType(typeName), makeName(varName))), makeBlock(makeExpressionStatement( makeAssignment(makeFieldAccess( makeThis(), makeName(varName)), makeName(varName)))));
Andrew Eisenberg and Gregor Kiczales — University of British Columbia 24
Equations
public static double mean( final List<Integer> x) {@Equation(Return.DOUBLE)
int MOP_ANNOTATION_HOLDER$0;return Equ.div(
new Summer() { public int body(int i) { return x.get(i); } }.sum(0, x.size() - 1), x.size()); }
Andrew Eisenberg and Gregor Kiczales — University of British Columbia 25
Equation Video
Andrew Eisenberg and Gregor Kiczales — University of British Columbia 26
Stream Processing Automaton
Andrew Eisenberg and Gregor Kiczales — University of British Columbia 27
Presentation Extensions
(Byte) CodeExpanded AST
AST
Other Tools
Display/Edit
Raw Text
RawText
Display
Byte Code
AST
Expanded AST
AST+EMOs
AST+CMOs
Boxes
Controllers
CTMOP
ETMOP
ErrorPropagation
Andrew Eisenberg and Gregor Kiczales — University of British Columbia 28
Questions?
(Byte) CodeExpanded AST
AST
Other Tools
Display/Edit
Raw Text
RawText
Display
Byte Code
AST
Expanded AST
AST+EMOs
AST+CMOs
Boxes
Controllers
CTMOP
ETMOP
ErrorPropagation