From 7af54064b23efe1f18fab9e7ee20b0fc811c36b5 Mon Sep 17 00:00:00 2001 From: Mel Date: Sun, 24 May 2026 20:30:11 +0200 Subject: Power operator via runtime library implementation Signed-off-by: Mel --- boot/transpile.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'boot/transpile.c') 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; -- cgit 1.4.1