diff options
| author | gingerBill <bill@gingerbill.org> | 2021-10-20 16:03:16 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-10-20 16:03:16 +0100 |
| commit | 3e4c2e49320b6ddd905b38fc884ec47aa8da7748 (patch) | |
| tree | 67a9d1e0e6cade4b721a27179a728fac5cb79168 /src/check_builtin.cpp | |
| parent | 30c141ceb98d4b65418fb70c572f86cd701dd872 (diff) | |
Support `conj` on array and matrix types
Diffstat (limited to 'src/check_builtin.cpp')
| -rw-r--r-- | src/check_builtin.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp index b60509c03..7dc4784f8 100644 --- a/src/check_builtin.cpp +++ b/src/check_builtin.cpp @@ -1266,7 +1266,10 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32 case BuiltinProc_conj: { // conj :: proc(x: type) -> type Operand *x = operand; - if (is_type_complex(x->type)) { + Type *t = x->type; + Type *elem = core_array_type(t); + + if (is_type_complex(t)) { if (x->mode == Addressing_Constant) { ExactValue v = exact_value_to_complex(x->value); f64 r = v.value_complex->real; @@ -1276,7 +1279,7 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32 } else { x->mode = Addressing_Value; } - } else if (is_type_quaternion(x->type)) { + } else if (is_type_quaternion(t)) { if (x->mode == Addressing_Constant) { ExactValue v = exact_value_to_quaternion(x->value); f64 r = +v.value_quaternion->real; @@ -1288,7 +1291,11 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32 } else { x->mode = Addressing_Value; } - } else { + } else if (is_type_array_like(t) && (is_type_complex(elem) || is_type_quaternion(elem))) { + x->mode = Addressing_Value; + } else if (is_type_matrix(t) && (is_type_complex(elem) || is_type_quaternion(elem))) { + x->mode = Addressing_Value; + }else { gbString s = type_to_string(x->type); error(call, "Expected a complex or quaternion, got '%s'", s); gb_string_free(s); |