User Tools

Site Tools


lara:docs:sheet

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
lara:docs:sheet [2017/07/12 20:30]
joaobispo
lara:docs:sheet [2019/09/22 15:47] (current)
Line 183: Line 183:
  
 <code lara> <code lara>
-call optimizer: OptimizeFunctions(functions,​ optimizations);​+// Current syntax 
 +var optimizer = call OptimizeFunctions(functions,​ optimizations);​ 
 + 
 +// Previous syntax 
 +call optimizer : OptimizeFunctions(functions,​ optimizations);​
  
 var changedFuncs = optimizer.optFuncs;​ var changedFuncs = optimizer.optFuncs;​
Line 194: Line 198:
 var optimizer = new OptimizeFunctions(functions,​ optimizations);​ var optimizer = new OptimizeFunctions(functions,​ optimizations);​
  
-call optimizer();​+call optimizer(); ​// or optimizer.call()
  
 var changedFuncs = optimizer.optFuncs;​ var changedFuncs = optimizer.optFuncs;​
Line 238: Line 242:
     $loop.exec tile(8); ​ // performed on the same loop as above     $loop.exec tile(8); ​ // performed on the same loop as above
 end end
 +</​code>​
 +
 +
 +If the action returns a result, we can use the following syntax:
 +
 +<code lara>
 +   var result = $jp.exec <​action_name>;​
 +</​code>​
 +
 +If '​result'​ is a variable that already exists, '​var'​ can be omitted:
 +
 +<code lara>
 +   ​result = $jp.exec <​action_name>;​
 +</​code>​
 +
 +The keyword '​.exec'​ can be omitted if you prefix the name of the action with the target join point, and add parenthesis:​
 +
 +<code lara>
 +  result = $jp.<​action_name>​();​
 </​code>​ </​code>​
  
Line 278: Line 301:
 To insert sections of code that span several lines, you can define codedef sections, which act as templates. Example: To insert sections of code that span several lines, you can define codedef sections, which act as templates. Example:
  
-<​code>​+<​code ​lara>
  
 codedef CodeTemplate(param1,​ param2) %{ codedef CodeTemplate(param1,​ param2) %{
Line 292: Line 315:
 Declared codedefs can then be used in the code as functions: Declared codedefs can then be used in the code as functions:
  
-<​code>​+<​code ​lara>
  
 code = CodeTemplate("​varName",​ 2); code = CodeTemplate("​varName",​ 2);
  
 </​code>​ </​code>​
 +
 +====== Miscellaneous ======
 +
 +==== Regular Expressions ====
 +
 +Lara supports JavaScript regular expressions,​ for instance:
 +
 +<code lara>
 +
 +var regex = /​(return\s+)(10)(\s*;​)/;​
 +regex.test("​return 10;"); // Returns '​true'​
 +
 +</​code>​
 +
 +Since **exec** is a LARA keyword, calling **regex.exec** is not permitted. However, you can access object properties using strings to circumvent this limitation:
 +
 +<code lara>
 +
 +(regex['​exec'​]("​return 10;"​))[2];​ // Returns '​10'​
 +
 +</​code>​
 +
 +Alternatively,​ you can also use the **match** function in strings:
 +
 +<code lara>
 +
 +String('​aaaa'​).match(new RegExp('​a*'​)) // Returns '​aaaa'​
 +
 +</​code>​
 +
 +Or you can also use the **match** boolean operator ( **~=** ):
 +
 +<code lara>
 +
 +'​aaaa'​ ~= /a*/ // Returns true
 +
 +</​code>​
 +
 +==== Importing LARA Files ====
 +
 +LARA supports importing LARA files that are present in the include path using the keyword **import**. To import a file, you have to use the path to the file from the include folder, using *.* as separator and omitting the extension of the file. For instance, if you add as include the folder *~/foo* and you want to import the file *~/​foo/​bar/​Aspect.lara*,​ you can write the following code:
 +
 +<code lara>
 +
 +import bar.Aspect;
 +
 +</​code>​
 +
 +Import statements must be the first statements in a LARA file. LARA weavers come bundled with support for a set of imports, which are part of their API (e.g., [[http://​specs.fe.up.pt/​tools/​clava/​doc/​|Clava API]]).
 +
 +
 +
 +==== Reading/​Writing JSON Files ====
 +
 +LARA supports reading from and writing to JSON objects with the object **Io**:
 +
 +<code lara>
 +
 +import lara.Io;
 +
 +...
 +
 +Io.writeJson("​file.json",​ anObject);
 +var loadedObject = Io.readJson("​file.json"​);​
 +
 +</​code>​
 +
 +
 +
lara/docs/sheet.1499884232.txt.gz · Last modified: 2019/09/22 15:46 (external edit)