-
-
Save luiscubal/abf10c6c85cef6aacb99 to your computer and use it in GitHub Desktop.
LARA Example - idivide
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Replaces division operations in closure function with a MATISSE primitive that performs integer division | |
sequencedef closure_idivide | |
select function{"closure"} end | |
apply | |
call replace_operator("/", "N", "2", "matisse_idivide"); | |
// Implicit update here | |
call replace_operator("/", "ii", "2", "matisse_idivide"); | |
end | |
end | |
aspectdef replace_operator | |
input operatorSymbol, leftOperand, rightOperand, newOperator end | |
select operator end | |
apply | |
call operands : get_operands($operator); | |
var leftValue = operands.jp_operands[0].value; | |
var rightValue = operands.jp_operands[1].value; | |
if(leftValue != leftOperand) { | |
continue; | |
} | |
if(rightValue != rightOperand) { | |
continue; | |
} | |
$operator.insert around%{[[newOperator]]([[leftValue]], [[rightValue]])}%; | |
end | |
condition $operator.symbol == operatorSymbol end | |
end | |
aspectdef get_operands | |
input jp_operator end | |
output jp_operands end | |
jp_operands = []; | |
select jp_operator.operand end | |
apply | |
jp_operands[$operand.index] = $operand; | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment