aboutsummaryrefslogtreecommitdiff
path: root/src/check_builtin.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2024-01-05 14:45:03 +0000
committergingerBill <bill@gingerbill.org>2024-01-05 14:45:03 +0000
commit8545f316ffa37c2c9fedb1808a4a3d59b0088707 (patch)
tree696d6a8390986e4c4b331edd1451b702d7ccb607 /src/check_builtin.cpp
parent3bf7b416e72259059a91a785d70b50961f6c41c6 (diff)
Fix the type inference in `builtin.quaternion`
Diffstat (limited to 'src/check_builtin.cpp')
-rw-r--r--src/check_builtin.cpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp
index 0b3d65f78..09ca0bc23 100644
--- a/src/check_builtin.cpp
+++ b/src/check_builtin.cpp
@@ -2331,6 +2331,8 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
// quaternion :: proc(imag, jmag, kmag, real: float_type) -> complex_type
Operand xyzw[4] = {};
+ u32 first_index = 0;
+
// NOTE(bill): Invalid will be the default till fixed
operand->type = t_invalid;
operand->mode = Addressing_Invalid;
@@ -2388,10 +2390,10 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
i32 index = -1;
Operand o = {};
bool ok = check_field(c, &o, ce->args[i], &index);
- if (!ok) {
+ if (!ok || index < 0) {
return false;
}
-
+ first_index = cast(u32)index;
*refs[index] = o;
}
@@ -2414,11 +2416,16 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
}
}
}
- convert_to_typed(c, &xyzw[0], xyzw[1].type); if (xyzw[0].mode == Addressing_Invalid) return false;
- convert_to_typed(c, &xyzw[1], xyzw[0].type); if (xyzw[1].mode == Addressing_Invalid) return false;
- convert_to_typed(c, &xyzw[2], xyzw[0].type); if (xyzw[2].mode == Addressing_Invalid) return false;
- convert_to_typed(c, &xyzw[3], xyzw[0].type); if (xyzw[3].mode == Addressing_Invalid) return false;
+
+ for (u32 i = 0; i < 4; i++ ){
+ u32 j = (i + first_index) % 4;
+ if (j == first_index) {
+ convert_to_typed(c, &xyzw[j], xyzw[(first_index+1)%4].type); if (xyzw[j].mode == Addressing_Invalid) return false;
+ } else {
+ convert_to_typed(c, &xyzw[j], xyzw[first_index].type); if (xyzw[j].mode == Addressing_Invalid) return false;
+ }
+ }
if (xyzw[0].mode == Addressing_Constant &&
xyzw[1].mode == Addressing_Constant &&
xyzw[2].mode == Addressing_Constant &&
@@ -2476,7 +2483,7 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
operand->mode = Addressing_Constant;
}
- BasicKind kind = core_type(xyzw[0].type)->Basic.kind;
+ BasicKind kind = core_type(xyzw[first_index].type)->Basic.kind;
switch (kind) {
case Basic_f16: operand->type = t_quaternion64; break;
case Basic_f32: operand->type = t_quaternion128; break;