Tata AIG General Insurance Company - Insurer Innovation Award 2024
Rascal Devnology Code Fest
1. Rascal Codefest
Woensdag 3 maart 2010
Jurgen Vinju
&& Tijs van der Storm
&& Bas Basten
&& Jeroen van den Bos
&& Mark Hills
Thursday, March 4, 2010
2. Installation art
go ah
ea d!
Eclipse 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
Thursday, March 4, 2010
3. Exam
ple o p
en so
urce
Java
proje
ct
http://www.rascal-mpl.org/releases/Prefuse.zip
http://www.prefuse.org
Thursday, March 4, 2010
4. Rascal Team
Paul Jurgen Tijs Bob
Klint Vinju v/d Storm Fuhrer
IBM
A
INRI I/INR
IA
CW
Arnold Bert
Bas Emilie Mark Jeroen
Lankamp Lisser
Basten Balland Hills van den Bos
Thursday, March 4, 2010
5. Codefest
Lightning intro
Coding Game
Ana
lysis
analysis !!
zatio n!!
visualization Visuali
transformation No Generat
ion to day
Disclaimers/Advertisements oday
sin gt
oPar
N
Thursday, March 4, 2010
6. Meta Software
(Static)
s Program
A nalysiDead code detection Tra
Goto elimination nsfor
matio
Slicing/Dependence Dialect transformation
Metrics Aspect weaving
Reverse engineering DSL compilers
Verification API migration
Architecture recovery Model-to-code
Code-to-model ...
...
Thursday, March 4, 2010
7. Challenges
Diversity
languages, dialects, frameworks, api, ...
Multi-disciplinary
parsing, static analysis, transformation, ...
Efficiency versus precision
trade-off must be programmable
Thursday, March 4, 2010
9. So, Rascal is a domain specific language
for
source code
analysis
and
transformation
and
visualization
and
generation
and
nothing less
(and nothing more)
Thursday, March 4, 2010
10. 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
13. Modules
module path::to::Examples
import IO;
public int fac(int n) {
if (n == 0) {
return 1;
}
return n * fac(n - 1);
}
Thursday, March 4, 2010
14. From coding to declaring
list[int] even(int max) {
list[int] result = [];
for (int i <- [0..max]) {
if (i % 2 == 0) {
result += i;
}
}
return result;
}
Thursday, March 4, 2010
15. From coding to declaring
list[int] even(int max) {
list[int] result = [];
for (int i <- [0..max], i%2 == 0) {
result += i;
}
return result;
}
Thursday, March 4, 2010
16. From coding to declaring
list[int] even(int max) {
result = [];
for (i <- [0..max], i%2 == 0) {
result += i;
}
return result;
}
Thursday, March 4, 2010
17. From coding to declaring
list[int] even(int max) {
return for (i <- [0..max], i%2 == 0)
append i;
}
Thursday, March 4, 2010
18. From coding to declaring
list[int] even(int max) {
return [i | i <- [0..max], i%2 == 0];
}
Thursday, March 4, 2010
19. Immutable values
WYSIWYG values (“1”:1, “2”:2)
true, false name(“Y.T.”)
1, 2, 3, ... <1,2>, <1,2,1.0>
1.0, 1.1, 1.11111111 {<1,2>,2,1>}
[1,2,3] Nest any way you
like
{1,2,3}
Thursday, March 4, 2010
20. Types
value
list[void]: []
list[int]: [1] int str list[value] ...
list[value]: [1, “1”]
set[int]: {1}
set[value]: {1,”1”} void
Thursday, March 4, 2010
21. Sub-types
value
list[value]
real
int list[real]
list[int]
bool
“A sub-type is a sub-set”
Thursday, March 4, 2010
22. Trees and Data
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”);
Thursday, March 4, 2010
23. Trees and Data
node myNode = “person”(“Y.T”, 18);
data Person = person(str name, int age)
| person(str first, str last);
node
Person YT = person(“Y.T”, 18);
Person MC = person(“Hiro”, “Protagonist”);
Person
Thursday, March 4, 2010
24. Switch
bool isPerson(node t) {
switch (t)
case person(_,_) : return true;
case person(_,_,_) : return true;
default: return false;
}
}
Thursday, March 4, 2010
25. Visit
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;
}
}
}
Thursday, March 4, 2010
26. Booleans & Patterns
true && 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
28. Unfi
Concrete Syntax nish
ed
import lang::ansiC::CompilationUnit
...
visit(s) {
case `if(!<expr>) <stat1> else <stat2>` =>
`if(<expr>) <stat2> else <stat1>`
}
Thursday, March 4, 2010
29. 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
30. Warm-up
1 + 1, 4 / 2, 2 * int a := b
2
<a,b> = <1,2>;
int a = 1;
if (1 > 2) println
b = 2; (“x”);
import Set; int fac(int n)
{ if (n == 0 )
max({1,2,3}) return 1; return n
* f(n - 1); }
{ i | i <-
[0..100]} prime numbers?
Thursday, March 4, 2010
40. Metrics
construct 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
41. Thank you!
http://www.rascal-mpl.org
Feedback is welcome
Look out for more alpha releases:
static (type) checker
concrete syntax features
IDE generation ! s"rce!
Read
Cases
DSL implementation
Tip: h
ttp://www
Refactoring implementation .eclip
se.or
g/imp
...
Thursday, March 4, 2010