Rascal Devnology Code Fest

1,151 views
997 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,151
On SlideShare
0
From Embeds
0
Number of Embeds
77
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Rascal Devnology Code Fest

  1. 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. 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. 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. 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. 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. 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. 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
  8. 8. Metaprogramming Transformation EASY Source Code Input Extraction Generation Extract Analysis Models Analyze Abstraction Formalization S Visualization Ynthesize Pictures Output Conversion Thursday, March 4, 2010
  9. 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. 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
  11. 11. Read-Eval-Print rascal>1 + 1 int: 2 rascal>[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
  12. 12. Read-Eval-Print rascal>import IO; ok rascal>for (i <- [1..10]) { >>>>>>> println("<i> * <i> = <i * i>"); >>>>>>>} 1 * 1 = 1 2 * 2 = 4 3 * 3 = 9 4 * 4 = 16 5 * 5 = 25 6 * 6 = 36 7 * 7 = 49 8 * 8 = 64 9 * 9 = 81 10 * 10 = 100 list[void]: [] rascal> Thursday, March 4, 2010
  13. 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. 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. 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. 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. 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. 18. From coding to declaring list[int] even(int max) { return [i | i <- [0..max], i%2 == 0]; } Thursday, March 4, 2010
  19. 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. 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. 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. 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. 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. 24. Switch bool isPerson(node t) { switch (t) case person(_,_) : return true; case person(_,_,_) : return true; default: return false; } } Thursday, March 4, 2010
  25. 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. 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
  27. 27. 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
  28. 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. 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. 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
  31. 31. Extension Charts Thursday, March 4, 2010
  32. 32. 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
  33. 33. Word cloud Pick a single class, or it’s probably to o slow Thursday, March 4, 2010
  34. 34. 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
  35. 35. Deep Inheritance Thursday, March 4, 2010
  36. 36. Deep Inheritance Import 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
  37. 37. Subtype graph Thursday, March 4, 2010
  38. 38. 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
  39. 39. Metrics Thursday, March 4, 2010
  40. 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. 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

×