Upload
devnology
View
864
Download
1
Tags:
Embed Size (px)
Citation preview
Rascal Codefest
Jurgen Vinju&& Tijs van der Storm && Bas Basten && Jeroen van den Bos && Mark Hills
Woensdag 3 maart 2010
Thursday, March 4, 2010
Installation artEclipse Galileo 3.5 for RCP/Plugin developers
32-bit version (yes, also on 64-bit machine)
32-bit Java run-time (JRE >= version 1.5)
Install plugins
http://download.eclipse.org/technology/imp/updates
IMP run-time & IMP analysis features
http://www.meta-environment.org/updates
Rascal feature
go ahead!
Thursday, March 4, 2010
http://www.rascal-mpl.org/releases/Prefuse.zip
Example open source Java project
http://www.prefuse.org
Thursday, March 4, 2010
Rascal TeamPaulKlint
JurgenVinju
Tijsv/d Storm
ArnoldLankamp
BertLisser Bas
BastenMarkHills
Jeroenvan den Bos
BobFuhrer
IBM
EmilieBalland
INRIACWI/INRIA
Thursday, March 4, 2010
Codefest
Lightning intro
Coding Game
analysis
visualization
transformation
Disclaimers/Advertisements
No Parsing
today
Analysis!!
Visualization!!
No Generation today
Thursday, March 4, 2010
Meta SoftwareDead code detection
Slicing/Dependence
Metrics
Reverse engineering
Verification
Architecture recovery
Code-to-model
...
Goto elimination
Dialect transformation
Aspect weaving
DSL compilers
API migration
Model-to-code
...
(Static)
AnalysisProgram Transformation
Thursday, March 4, 2010
Challenges
Diversity
languages, dialects, frameworks, api, ...
Multi-disciplinary
parsing, static analysis, transformation, ...
Efficiency versus precision
trade-off must be programmable
Thursday, March 4, 2010
Metaprogramming
Source Code
Models
Pictures
GenerationExtraction
FormalizationVisualization
Transformation
Conversion
Analysis
Input
Abstraction
Output
Extract
Analyze
SYnthesize
EASY
Thursday, March 4, 2010
So, Rascal is a domain specific languagefor
source codeanalysis
andtransformation
andvisualization
andgeneration
andnothing less
(and nothing more)Thursday, March 4, 2010
Use
File extension: .rsc
Open “Rascal Persective”
Use “New Rascal Project” wizard
Use “New Rascal File” wizard
Context-menu on Rascal projects
Start Console
Thursday, March 4, 2010
Read-Eval-Print
rascal>1 + 1int: 2rascal>[1,2,3]list[int]: [1,2,3]rascal>{1,1,1}set[int]: {1}rascal>{ <i,i*i> | i <- [1..10]}rel[int,int]: {<1,1>,<2,4>,<3,9>,...
Thursday, March 4, 2010
Read-Eval-Printrascal>import IO;okrascal>for (i <- [1..10]) {>>>>>>> println("<i> * <i> = <i * i>");>>>>>>>}1 * 1 = 12 * 2 = 43 * 3 = 94 * 4 = 165 * 5 = 256 * 6 = 367 * 7 = 498 * 8 = 649 * 9 = 8110 * 10 = 100list[void]: []rascal>
Thursday, March 4, 2010
module path::to::Examplesimport IO;
public int fac(int n) { if (n == 0) { return 1; } return n * fac(n - 1);}
Modules
Thursday, March 4, 2010
list[int] even(int max) { list[int] result = []; for (int i <- [0..max]) { if (i % 2 == 0) { result += i; } } return result;}
From coding to declaring
Thursday, March 4, 2010
list[int] even(int max) { list[int] result = []; for (int i <- [0..max], i%2 == 0) { result += i; } return result;}
From coding to declaring
Thursday, March 4, 2010
list[int] even(int max) { result = []; for (i <- [0..max], i%2 == 0) { result += i; } return result;}
From coding to declaring
Thursday, March 4, 2010
list[int] even(int max) { return for (i <- [0..max], i%2 == 0) append i;}
From coding to declaring
Thursday, March 4, 2010
list[int] even(int max) { return [i | i <- [0..max], i%2 == 0];}
From coding to declaring
Thursday, March 4, 2010
Immutable values
WYSIWYG values
true, false
1, 2, 3, ...
1.0, 1.1, 1.11111111
[1,2,3]
{1,2,3}
(“1”:1, “2”:2)
name(“Y.T.”)
<1,2>, <1,2,1.0>
{<1,2>,2,1>}
Nest any way you like
Thursday, March 4, 2010
Types
list[void]: []
list[int]: [1]
list[value]: [1, “1”]
set[int]: {1}
set[value]: {1,”1”}
value
void
int str list[value] ...
Thursday, March 4, 2010
Sub-typesvalue
intreal
bool
list[value]
list[int] list[real]
“A sub-type is a sub-set”
Thursday, March 4, 2010
node myNode = “person”(“Y.T”, 18);
data Person = person(str name, int age) | person(str first, str last);
Person YT = person(“Y.T”, 18);Person MC = person(“Hiro”, “Protagonist”);
Trees and Data
Thursday, March 4, 2010
node myNode = “person”(“Y.T”, 18);
data Person = person(str name, int age) | person(str first, str last);
Person YT = person(“Y.T”, 18);Person MC = person(“Hiro”, “Protagonist”);
node
Person
Trees and Data
Thursday, March 4, 2010
bool isPerson(node t) { switch (t) case person(_,_) : return true; case person(_,_,_) : return true; default: return false; }}
Switch
Thursday, March 4, 2010
set[Person] personTrafo(set[Person] s) { return visit(s) { case person(str f, str l) => person(“<l>,<f>”, 0) case person(str f, str l) : { name = “<l>, <f>”; println(name); insert name; } } }
Visit
Thursday, March 4, 2010
Booleans & Patternstrue && false, true || false, !true
true ==> false, true <==> false
all( i <- [2,4,6,8], i % 2 == 0)
int i := x
<int i, int j> := <1,”2”>
person(str name) <- {person(“x”)}
/<word:[a-z]+>/ <- [“123”,”abc”]
Thursday, March 4, 2010
Quoting & Antiquoting“Hello, I’m <myAge> year<s(myAge)> old”
“class <className> { <for (<type, name> <- fields) {> <type> <name>; public <type> get<capitalize(name)>() { return this.<name>; } <}>}”
Thursday, March 4, 2010
Concrete Syntax
import lang::ansiC::CompilationUnit...visit(s) { case `if(!<expr>) <stat1> else <stat2>` => `if(<expr>) <stat2> else <stat1>`}
Unfinished
Thursday, March 4, 2010
Finally! Coding
Warm-up
Analyze & visualize a Java project
Extension Pie Chart / Histogram
Make a word cloud for Java code
Compute deepest inherited classes
Visualize a type hierarchy
Visualize source code metrics
Thursday, March 4, 2010
Warm-up1 + 1, 4 / 2, 2 * 2
int a = 1;
b = 2;
import Set;
max({1,2,3})
{ i | i <- [0..100]}
int a := b
<a,b> = <1,2>;
if (1 > 2) println(“x”);
int fac(int n) { if (n == 0 ) return 1; return n * f(n - 1); }
prime numbers?
Thursday, March 4, 2010
Extension Charts
Thursday, March 4, 2010
Extension Charts
Import Resources, viz::Figure::Render, viz::Figure::Core, viz::Figure::Chart
|project://Prefuse|
loc l = ...; l.extension == “java”
Make a map[str, int]
myMap[elem]?0 += 1;
Thursday, March 4, 2010
Word cloud
Pick a single class, or it’s probably too slow
Thursday, March 4, 2010
Word cloud
import Resources
|project://myProjectName|
/file(loc l) := myResource
visit(myResource) { case file(l) : ... }
import IO;
readFileLines
/<myWord:[A-Za-z0-9]+>/ := line
Import viz::Figure::Core and Render
render, align, text, fontSize
|project://Prefuse/src/prefuse/data/parser/ByteParser.java|
Thursday, March 4, 2010
Deep Inheritance
Thursday, March 4, 2010
Deep InheritanceImport JDT, Java, Resources, Set;
Compute set[str], “deepest inherited” classes
facts = extractProject(project);
rel[Entity, Entity] x = facts@extends;
x+; // transitive closure
str readable(Entity e);
int size(set[&T] s);
viz::Basic, treeView(...)
Thursday, March 4, 2010
Subtype graph
Thursday, March 4, 2010
Subtype graph
Use viz::Figure::Core, viz::Figure::Render, JDT, Java, Resources, Set, Relation, and Graph modules
Visualize (a part of) the type hierarchy:
subtypes = facts@extends + facts@implements;
subtypes += top(subtypes) * makeClass(“java.lang.Object”);
filter on prefuse.data.expression.FunctionExpression using reach(...)
graph([width(600),height(600)],[text([id(name)],name)|name <- ... ],[edge(from,to) | <from,to> <- ... ])
Thursday, March 4, 2010
Metrics
Thursday, March 4, 2010
Metricsconstruct a view with a box for each class:
classes: rel[loc,Entity] x = fact@types;
height is #methods: facts@declaredMethods
width is #fields: facts@declaredFields
color is #implemented interface, less is red, more is blue.
use loc.length
fillColor(Color c)
colorRange([...],color(“red”),color(“blue”);
use pack([width(x),height(x)],[...])Thursday, March 4, 2010
Thank you!http://www.rascal-mpl.org
Feedback is welcome
Look out for more alpha releases:
static (type) checker
concrete syntax features
IDE generation
Cases
DSL implementation
Refactoring implementation
...
Tip: http://www.eclipse.org/imp
Read ! s"rce!
Thursday, March 4, 2010