added missing type info; constrained type_expr operations
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 24 Jun 2021 03:20:17 +0000 (22:20 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 24 Jun 2021 03:20:17 +0000 (22:20 -0500)
bin/onyx
core/type_info/helper.onyx
core/type_info/type_info.onyx
src/onyxchecker.c

index 13c8473badc8520beddc62cf0d497c7fda37bf20..f7c894b32b61703c45e0c236eafec35fa17a0064 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index 5dd1f8609e9ed55ee0653bd525854ff57b069bd7..d85a476de5a910ab6f831ef239d6037570e27e44 100644 (file)
@@ -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, "<unsized int>");
+                case .Unsized_Float do io.write_str(writer, "<unsized float>");
             }
         }
 
index 13b8c0c4a07f3267721f24ac635e0fc00eff0fec..8c26dd2719c64a42379923a44289fa4435b12cef 100644 (file)
@@ -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];
 }
index 9f953de9d7945e61903f1c617972f94b774d9661..bb46103befeac2da7f261ac373f72d8b371d69be 100644 (file)
@@ -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