From: Brendan Hansen Date: Thu, 24 Jun 2021 03:20:17 +0000 (-0500) Subject: added missing type info; constrained type_expr operations X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=7d9be661da240ac15a1b4e89558c311a883677c5;p=onyx.git added missing type info; constrained type_expr operations --- diff --git a/bin/onyx b/bin/onyx index 13c8473b..f7c894b3 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/core/type_info/helper.onyx b/core/type_info/helper.onyx index 5dd1f860..d85a476d 100644 --- a/core/type_info/helper.onyx +++ b/core/type_info/helper.onyx @@ -35,7 +35,9 @@ write_type_name :: (writer: ^io.Writer, t: type_expr) { case .F64X2 do return io.write_str(writer, "f64x2"); case .V128 do return io.write_str(writer, "v128"); - case .Type_Index do return io.write_str(writer, "type_expr"); + case .Type_Index do io.write_str(writer, "type_expr"); + case .Unsized_Int do io.write_str(writer, ""); + case .Unsized_Float do io.write_str(writer, ""); } } diff --git a/core/type_info/type_info.onyx b/core/type_info/type_info.onyx index 13b8c0c4..8c26dd27 100644 --- a/core/type_info/type_info.onyx +++ b/core/type_info/type_info.onyx @@ -35,6 +35,8 @@ Type_Info_Basic :: struct { Kind :: enum { Void :: 0x00; Bool :: 0x01; + + Unsized_Int :: 0x02; I8 :: 0x03; U8 :: 0x04; I16 :: 0x05; @@ -44,6 +46,7 @@ Type_Info_Basic :: struct { I64 :: 0x09; U64 :: 0x0a; + Unsized_Float :: 0x0b; F32 :: 0x0c; F64 :: 0x0d; @@ -147,7 +150,9 @@ Type_Info_Compound :: struct { } get_type_info :: (t: type_expr) -> ^Type_Info { - if t < ~~0 || t >= ~~type_table.count do return null; + // Grossness to get around the fact that type_exprs are not technically comparable, because in most + // cases you should not compare them as the number assigned to them is arbitrary. + if ~~t < cast(i32) 0 || ~~t >= cast(i32) type_table.count do return null; return type_table[cast(i32) t]; } diff --git a/src/onyxchecker.c b/src/onyxchecker.c index 9f953de9..bb46103b 100644 --- a/src/onyxchecker.c +++ b/src/onyxchecker.c @@ -811,9 +811,10 @@ static b32 binary_op_is_allowed(BinaryOp operation, Type* type) { enum BasicFlag effective_flags = 0; switch (type->kind) { - case Type_Kind_Basic: effective_flags = type->Basic.flags; break; - case Type_Kind_Pointer: effective_flags = Basic_Flag_Pointer; break; - case Type_Kind_Enum: effective_flags = Basic_Flag_Integer; break; + case Type_Kind_Basic: effective_flags = type->Basic.flags; break; + case Type_Kind_Pointer: effective_flags = Basic_Flag_Pointer; break; + case Type_Kind_Enum: effective_flags = Basic_Flag_Integer; break; + case Type_Kind_Function: effective_flags = Basic_Flag_Equality; break; } return (binop_allowed[operation] & effective_flags) != 0; @@ -822,12 +823,6 @@ static b32 binary_op_is_allowed(BinaryOp operation, Type* type) { CheckStatus check_binaryop_compare(AstBinaryOp** pbinop) { AstBinaryOp* binop = *pbinop; - if ( type_is_structlike_strict(binop->left->type) - || type_is_structlike_strict(binop->right->type)) { - report_bad_binaryop(binop); - return Check_Error; - } - // HACK: Since ^... to rawptr is a one way conversion, strip any pointers // away so they can be compared as expected Type* ltype = binop->left->type; @@ -855,6 +850,11 @@ CheckStatus check_binaryop_compare(AstBinaryOp** pbinop) { } } + if (!binary_op_is_allowed(binop->operation, binop->left->type)) { + report_bad_binaryop(binop); + return Check_Error; + } + binop->type = &basic_types[Basic_Kind_Bool]; if (binop->flags & Ast_Flag_Comptime) { // NOTE: Not a binary op