aboutsummaryrefslogtreecommitdiff
path: root/src/check_expr.c
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2017-06-01 14:52:33 +0100
committerGinger Bill <bill@gingerbill.org>2017-06-01 14:52:33 +0100
commit13b8a1e34805b97986841f92a31ed7a4be1f2740 (patch)
tree372ced0a3a583d827989150d3457be979c081c00 /src/check_expr.c
parent0d4945dc8788e8aa134fbdbd0941d9a6db0b67bc (diff)
Remove `quaternion128` and `quaternion256` as core types
Diffstat (limited to 'src/check_expr.c')
-rw-r--r--src/check_expr.c199
1 files changed, 9 insertions, 190 deletions
diff --git a/src/check_expr.c b/src/check_expr.c
index 2997cbbfb..468598caf 100644
--- a/src/check_expr.c
+++ b/src/check_expr.c
@@ -170,11 +170,6 @@ i64 check_distance_between_types(Checker *c, Operand *operand, Type *type) {
return 1;
}
break;
- case Basic_UntypedQuaternion:
- if (is_type_quaternion(dst)) {
- return 1;
- }
- break;
}
}
return 2;
@@ -2055,35 +2050,6 @@ bool check_representable_as_constant(Checker *c, ExactValue in_value, Type *type
}
return false;
- } else if (is_type_quaternion(type)) {
- ExactValue v = exact_value_to_quaternion(in_value);
- if (v.kind != ExactValue_Quaternion) {
- return false;
- }
-
- switch (type->Basic.kind) {
- case Basic_quaternion128:
- case Basic_quaternion256: {
- ExactValue real = exact_value_real(v);
- ExactValue imag = exact_value_imag(v);
- ExactValue jmag = exact_value_jmag(v);
- ExactValue kmag = exact_value_kmag(v);
- if (real.kind != ExactValue_Invalid &&
- imag.kind != ExactValue_Invalid &&
- jmag.kind != ExactValue_Invalid &&
- kmag.kind != ExactValue_Invalid) {
- ExactValue ov = exact_binary_operator_value(Token_Add, real, exact_value_make_imag(imag));
- ov = exact_binary_operator_value(Token_Add, ov, exact_value_make_jmag(jmag));
- ov = exact_binary_operator_value(Token_Add, ov, exact_value_make_kmag(kmag));
- if (out_value) *out_value = ov;
- return true;
- }
- } break;
- case Basic_UntypedQuaternion:
- return true;
- }
-
- return false;
}else if (is_type_pointer(type)) {
if (in_value.kind == ExactValue_Pointer) {
return true;
@@ -2510,10 +2476,6 @@ bool check_is_castable_to(Checker *c, Operand *operand, Type *y) {
return true;
}
- if (is_type_quaternion(src) && is_type_quaternion(dst)) {
- return true;
- }
-
// Cast between pointers
if (is_type_pointer(src) && is_type_pointer(dst)) {
Type *s = base_type(type_deref(src));
@@ -2904,8 +2866,6 @@ ExactValue convert_exact_value_for_type(ExactValue v, Type *type) {
v = exact_value_to_integer(v);
} else if (is_type_complex(t)) {
v = exact_value_to_complex(v);
- } else if (is_type_quaternion(t)) {
- v = exact_value_to_quaternion(v);
}
return v;
}
@@ -2959,7 +2919,6 @@ void convert_to_typed(Checker *c, Operand *operand, Type *target_type, i32 level
case Basic_UntypedInteger:
case Basic_UntypedFloat:
case Basic_UntypedComplex:
- case Basic_UntypedQuaternion:
case Basic_UntypedRune:
if (!is_type_numeric(target_type)) {
operand->mode = Addressing_Invalid;
@@ -4128,149 +4087,36 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
}
} break;
- case BuiltinProc_quaternion: {
- // quaternion :: proc(real, imag, jmag, kmag: float_type) -> quaternion_type
- Operand x = *operand;
- Operand y = {0};
- Operand z = {0};
- Operand w = {0};
-
- // NOTE(bill): Invalid will be the default till fixed
- operand->type = t_invalid;
- operand->mode = Addressing_Invalid;
-
- check_expr(c, &y, ce->args.e[1]); if (y.mode == Addressing_Invalid) return false;
- check_expr(c, &z, ce->args.e[2]); if (z.mode == Addressing_Invalid) return false;
- check_expr(c, &w, ce->args.e[3]); if (w.mode == Addressing_Invalid) return false;
-
-#define _QUAT_CTT(x, y, z, w) do { \
- convert_to_typed(c, &(x), (y).type, 0); if ((x).mode == Addressing_Invalid) return false; \
- convert_to_typed(c, &(x), (z).type, 0); if ((x).mode == Addressing_Invalid) return false; \
- convert_to_typed(c, &(x), (w).type, 0); if ((x).mode == Addressing_Invalid) return false; \
- } while (0)
- _QUAT_CTT(x, y, z, w);
- _QUAT_CTT(y, z, w, x);
- _QUAT_CTT(z, w, x, y);
- _QUAT_CTT(w, x, y, z);
-#undef _QUAT_CTT
-
- if (x.mode == Addressing_Constant &&
- y.mode == Addressing_Constant &&
- z.mode == Addressing_Constant &&
- w.mode == Addressing_Constant) {
-#define _QUAT_EXACT_VAL(x) do { \
- if (is_type_numeric((x).type) && \
- exact_value_imag((x).value).value_float == 0 && \
- exact_value_jmag((x).value).value_float == 0 && \
- exact_value_kmag((x).value).value_float == 0) { \
- (x).type = t_untyped_float; \
- } \
- } while (0)
- _QUAT_EXACT_VAL(x);
- _QUAT_EXACT_VAL(y);
- _QUAT_EXACT_VAL(z);
- _QUAT_EXACT_VAL(w);
-#undef _QUAT_EXACT_VAL
- }
-
- if (!are_types_identical(x.type, y.type)) {
- gbString tx = type_to_string(x.type);
- gbString ty = type_to_string(y.type);
- gbString tz = type_to_string(z.type);
- gbString tw = type_to_string(w.type);
- error_node(call, "Mismatched types to `complex`, `%s`, `%s` `%s`, `%s`", tx, ty, tz, tw);
- gb_string_free(tw);
- gb_string_free(tz);
- gb_string_free(ty);
- gb_string_free(tx);
- return false;
- }
-
- if (!is_type_float(x.type)) {
- gbString s = type_to_string(x.type);
- error_node(call, "Arguments have type `%s`, expected a floating point", s);
- gb_string_free(s);
- return false;
- }
-
- if (x.mode == Addressing_Constant &&
- y.mode == Addressing_Constant &&
- z.mode == Addressing_Constant &&
- w.mode == Addressing_Constant) {
- ExactValue v = exact_binary_operator_value(Token_Add, x.value, y.value);
- v = exact_binary_operator_value(Token_Add, v, z.value);
- v = exact_binary_operator_value(Token_Add, v, w.value);
- operand->value = v;
- operand->mode = Addressing_Constant;
- } else {
- operand->mode = Addressing_Value;
- }
-
- BasicKind kind = core_type(x.type)->Basic.kind;
- switch (kind) {
- case Basic_f32: operand->type = t_quaternion128; break;
- case Basic_f64: operand->type = t_quaternion256; break;
- case Basic_UntypedFloat: operand->type = t_untyped_quaternion; break;
- default: GB_PANIC("Invalid type"); break;
- }
- } break;
-
case BuiltinProc_real:
- case BuiltinProc_imag:
- case BuiltinProc_jmag:
- case BuiltinProc_kmag: {
+ case BuiltinProc_imag: {
// real :: proc(x: type) -> float_type
// imag :: proc(x: type) -> float_type
- // jmag :: proc(x: type) -> float_type
- // kmag :: proc(x: type) -> float_type
Operand *x = operand;
if (is_type_untyped(x->type)) {
if (x->mode == Addressing_Constant) {
if (is_type_numeric(x->type)) {
- if (id == BuiltinProc_jmag ||
- id == BuiltinProc_kmag) {
- x->type = t_untyped_quaternion;
- } else {
- x->type = t_untyped_complex;
- }
+ x->type = t_untyped_complex;
}
} else {
- if (id == BuiltinProc_jmag ||
- id == BuiltinProc_kmag) {
- convert_to_typed(c, x, t_quaternion256, 0);
- } else {
- convert_to_typed(c, x, t_complex128, 0);
- }
+ convert_to_typed(c, x, t_complex128, 0);
if (x->mode == Addressing_Invalid) {
return false;
}
}
}
- if (id == BuiltinProc_jmag ||
- id == BuiltinProc_kmag) {
- if (!is_type_quaternion(x->type)) {
- gbString s = type_to_string(x->type);
- error_node(call, "Argument has type `%s`, expected a quaternion type", s);
- gb_string_free(s);
- return false;
- }
- } else {
- if (!is_type_complex(x->type) && !is_type_quaternion(x->type)) {
- gbString s = type_to_string(x->type);
- error_node(call, "Argument has type `%s`, expected a complex or quaternion type", s);
- gb_string_free(s);
- return false;
- }
+ if (!is_type_complex(x->type)) {
+ gbString s = type_to_string(x->type);
+ error_node(call, "Argument has type `%s`, expected a complex type", s);
+ gb_string_free(s);
+ return false;
}
if (x->mode == Addressing_Constant) {
switch (id) {
case BuiltinProc_real: x->value = exact_value_real(x->value); break;
case BuiltinProc_imag: x->value = exact_value_imag(x->value); break;
- case BuiltinProc_jmag: x->value = exact_value_jmag(x->value); break;
- case BuiltinProc_kmag: x->value = exact_value_kmag(x->value); break;
}
} else {
x->mode = Addressing_Value;
@@ -4281,9 +4127,6 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
case Basic_complex64: x->type = t_f32; break;
case Basic_complex128: x->type = t_f64; break;
case Basic_UntypedComplex: x->type = t_untyped_float; break;
- case Basic_quaternion128: x->type = t_f32; break;
- case Basic_quaternion256: x->type = t_f64; break;
- case Basic_UntypedQuaternion: x->type = t_untyped_float; break;
default: GB_PANIC("Invalid type"); break;
}
} break;
@@ -4301,18 +4144,6 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
} else {
x->mode = Addressing_Value;
}
- } else if (is_type_quaternion(x->type)) {
- if (x->mode == Addressing_Constant) {
- ExactValue v = exact_value_to_quaternion(x->value);
- f64 r = v.value_quaternion.real;
- f64 i = v.value_quaternion.imag;
- f64 j = v.value_quaternion.jmag;
- f64 k = v.value_quaternion.kmag;
- x->value = exact_value_quaternion(r, i, j, k);
- x->mode = Addressing_Constant;
- } else {
- x->mode = Addressing_Value;
- }
} else {
gbString s = type_to_string(x->type);
error_node(call, "Expected a complex or quaternion, got `%s`", s);
@@ -4535,13 +4366,6 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
f64 i = operand->value.value_complex.imag;
operand->value = exact_value_float(gb_sqrt(r*r + i*i));
} break;
- case ExactValue_Quaternion: {
- f64 r = operand->value.value_complex.real;
- f64 i = operand->value.value_complex.imag;
- f64 j = operand->value.value_complex.imag;
- f64 k = operand->value.value_complex.imag;
- operand->value = exact_value_float(gb_sqrt(r*r + i*i + j*j + k*k));
- } break;
default:
GB_PANIC("Invalid numeric constant");
break;
@@ -4552,10 +4376,8 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
if (is_type_complex(operand->type)) {
operand->type = base_complex_elem_type(operand->type);
- } else if (is_type_quaternion(operand->type)) {
- operand->type = base_quaternion_elem_type(operand->type);
}
- GB_ASSERT(!is_type_complex(operand->type) && !is_type_quaternion(operand->type));
+ GB_ASSERT(!is_type_complex(operand->type));
} break;
case BuiltinProc_clamp: {
@@ -5218,9 +5040,6 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
Rune r = s.text[s.len-1];
switch (r) {
case 'i': t = t_untyped_complex; break;
- case 'j': case 'k':
- t = t_untyped_quaternion;
- break;
}
} break;
default: GB_PANIC("Unknown literal"); break;