aboutsummaryrefslogtreecommitdiff
path: root/src/check_builtin.cpp
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2025-10-30 08:52:21 +0000
committergingerBill <gingerBill@users.noreply.github.com>2025-10-30 08:52:21 +0000
commit99520d82fd26316fc795ae524cc0dfa3477fdac8 (patch)
tree3b99392059a143a35970ac4dedf64cf7acb7f3cb /src/check_builtin.cpp
parent13ddf66cc96a50e96ce9c31875375926482b9cee (diff)
Add `intrinsics.constant_(floor|truncate|ceil|round)`
Diffstat (limited to 'src/check_builtin.cpp')
-rw-r--r--src/check_builtin.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp
index 2ff3136ff..85a3f4515 100644
--- a/src/check_builtin.cpp
+++ b/src/check_builtin.cpp
@@ -4768,6 +4768,42 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
break;
}
+ case BuiltinProc_constant_floor:
+ case BuiltinProc_constant_truncate:
+ case BuiltinProc_constant_ceil:
+ case BuiltinProc_constant_round:
+ {
+ Operand o = {};
+ check_expr(c, &o, ce->args[0]);
+
+ if (!is_type_integer_or_float(o.type) && (o.mode != Addressing_Constant)) {
+ error(ce->args[0], "Expected a constant number for '%.*s'", LIT(builtin_name));
+ return false;
+ }
+ operand->mode = Addressing_Constant;
+ operand->type = o.type;
+
+ ExactValue value = o.value;
+ if (value.kind == ExactValue_Integer) {
+ // do nothing
+ } else if (value.kind == ExactValue_Float) {
+ f64 f = value.value_float;
+ switch (id) {
+ case BuiltinProc_constant_floor: f = floor(f); break;
+ case BuiltinProc_constant_truncate: f = trunc(f); break;
+ case BuiltinProc_constant_ceil: f = ceil(f); break;
+ case BuiltinProc_constant_round: f = round(f); break;
+ default:
+ GB_PANIC("Unhandled built-in: %.*s", LIT(builtin_name));
+ break;
+ }
+ value = exact_value_float(f);
+ }
+
+ operand->value = value;
+ break;
+ }
+
case BuiltinProc_soa_struct: {
Operand x = {};
Operand y = {};