diff options
| author | Mel <mel@rnrd.eu> | 2026-05-24 20:30:11 +0200 |
|---|---|---|
| committer | Mel <mel@rnrd.eu> | 2026-05-24 20:30:11 +0200 |
| commit | 7af54064b23efe1f18fab9e7ee20b0fc811c36b5 (patch) | |
| tree | d8482ce29cdee1892c843f57be881e6fecb98d2d /boot/transpile.c | |
| parent | 2a893246711442dd8407264c05991b44d1d1f66f (diff) | |
| download | catskill-7af54064b23efe1f18fab9e7ee20b0fc811c36b5.tar.zst catskill-7af54064b23efe1f18fab9e7ee20b0fc811c36b5.zip | |
Power operator via runtime library implementation
Signed-off-by: Mel <mel@rnrd.eu>
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; |
