commit 5e1335de7713ff27ebff76c80bbff317a3ac306c
parent fabf255b249ab4ee5ddf58854e015c4ec179d5d4
Author: Ryan Sepassi <rsepassi@gmail.com>
Date: Mon, 1 Jun 2026 19:12:02 -0700
cg: remove the FP_REM façade (Track 4, decision #3)
CFREE_CG_FP_REM was advertise-but-panic: cfree_cg_fp_binop aborted on it,
api_map_fp_binop mapped it to BO_FDIV (dead and wrong), and the toy frontend's
only reference was unreachable (toy errors on float '%' before the op map).
Remove it; FP remainder is a libcall (fmod/fmodf/fmodl) the frontend emits.
Diffstat:
4 files changed, 3 insertions(+), 13 deletions(-)
diff --git a/include/cfree/cg.h b/include/cfree/cg.h
@@ -704,7 +704,8 @@ typedef enum CfreeCgFpBinOp {
CFREE_CG_FP_SUB,
CFREE_CG_FP_MUL,
CFREE_CG_FP_DIV,
- CFREE_CG_FP_REM,
+ /* No FP remainder: it is a libcall (fmod/fmodf/fmodl), which the frontend
+ * emits directly. */
} CfreeCgFpBinOp;
typedef enum CfreeCgFpCmpOp {
diff --git a/lang/toy/expr.c b/lang/toy/expr.c
@@ -1320,9 +1320,6 @@ static CfreeCgTypeId toy_parse_expr_mul(ToyParser* p) {
case TOK_SLASH:
fp_op = CFREE_CG_FP_DIV;
break;
- case TOK_PERCENT:
- fp_op = CFREE_CG_FP_REM;
- break;
default:
return CFREE_CG_TYPE_NONE;
}
diff --git a/src/cg/arith.c b/src/cg/arith.c
@@ -548,8 +548,6 @@ const char* api_f128_binop_helper(CfreeCgFpBinOp op) {
return "__multf3";
case CFREE_CG_FP_DIV:
return "__divtf3";
- case CFREE_CG_FP_REM:
- return NULL;
}
return NULL;
}
@@ -570,17 +568,13 @@ void api_f128_call_unary(CfreeCg* g, const char* name, CfreeCgTypeId ret,
void cfree_cg_fp_binop(CfreeCg* g, CfreeCgFpBinOp op, uint32_t flags) {
(void)flags;
- if (op == CFREE_CG_FP_REM) {
- compiler_panic(g->c, g->cur_loc, "CfreeCg: FP remainder is unsupported");
- return;
- }
if (api_f128_stack_top(g, 0) || api_f128_stack_top(g, 1)) {
CfreeCgTypeId f128 = builtin_id(CFREE_CG_BUILTIN_F128);
CfreeCgTypeId ps[2];
ApiSValue args[2];
const char* name = api_f128_binop_helper(op);
if (!name)
- compiler_panic(g->c, g->cur_loc, "CfreeCg: FP remainder is unsupported");
+ compiler_panic(g->c, g->cur_loc, "CfreeCg: unsupported f128 binop");
args[1] = api_pop(g);
args[0] = api_pop(g);
ps[0] = f128;
diff --git a/src/cg/value.c b/src/cg/value.c
@@ -601,8 +601,6 @@ BinOp api_map_fp_binop(CfreeCgFpBinOp op) {
return BO_FMUL;
case CFREE_CG_FP_DIV:
return BO_FDIV;
- case CFREE_CG_FP_REM:
- return BO_FDIV;
}
return BO_FADD;
}