Skip to content

Instantly share code, notes, and snippets.

@luiscubal
Forked from joaobispo/closure_idivide.lara
Created October 8, 2015 19:01
Show Gist options
  • Save luiscubal/abf10c6c85cef6aacb99 to your computer and use it in GitHub Desktop.
Save luiscubal/abf10c6c85cef6aacb99 to your computer and use it in GitHub Desktop.
LARA Example - idivide
// 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