diff options
Diffstat (limited to 'boot/transpile.c')
| -rw-r--r-- | boot/transpile.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/boot/transpile.c b/boot/transpile.c index 0627bcb..9c94706 100644 --- a/boot/transpile.c +++ b/boot/transpile.c @@ -406,6 +406,19 @@ transpile_visit_expression_binary_operation(struct Visit* visit, struct Expressi TRANSPILE_PREAMBLE enum Binary_Operation op = expression->value.binary_operator.operation; + + // c has no built-in power operator. + // we route the operation via our own runtime library `pow_integer` function, + // which performs fast exponentiation by squaring. + if (op == BINARY_POWER) { + TRANSPILE_WRITE("pow_integer("); + transpile_emit_expression(visit, expression->value.binary_operator.left_operand, 0); + TRANSPILE_WRITE(", "); + transpile_emit_expression(visit, expression->value.binary_operator.right_operand, 0); + TRANSPILE_WRITE(")"); + return; + } + uint my_precedence = binary_operation_precedence(op); uint parent = transpiler->expression_parent_precedence; bool needs_parens = my_precedence < parent; |
