b0b66ba9cded — Leonard Ritter 14 days ago
* type reprs now largely reflect valid constructor calls so users know how to construct the type
* `signed integer <width>` or `signed <integer-type>` can be used to construct / convert integer types
* `_:` is a valid alias for `Arguments`
* `raises` can be used as an infix operator
M lib/scopes/core.sc +31 -1
@@ 700,6 700,9 @@ sc_type_set_symbol Arguments '__typecall
                 add i 1
             box-pointer (sc_arguments_type pcount types)
 
+# shorter type constructor
+let _: = Arguments
+
 # static function type constructor
 sc_type_set_symbol function '__typecall
     box-spice-macro

          
@@ 1149,7 1152,33 @@ let mutable =
                 let T = (unbox-pointer self type)
                 let T = (sc_pointer_type T pointer-flag-non-writable unnamed)
                 return `[('mutable T)]
-            error "syntax: (mutable pointer-type) or (mutable pointer type)"
+            error "syntax: (mutable <pointer-type>) or (mutable pointer <type>)"
+
+let mutable@ =
+    spice-macro
+        fn (args)
+            let argc = (sc_argcount args)
+            verify-count argc 1 1
+            let self = (sc_getarg args 0)
+            let T = (unbox-pointer self type)
+            let T = (sc_pointer_type T pointer-flag-non-writable unnamed)
+            return `[('mutable T)]
+
+let signed =
+    spice-macro
+        fn (args)
+            let argc = (sc_argcount args)
+            verify-count argc 1 2
+            if (icmp== argc 1)
+                let self = (sc_getarg args 0)
+                let T = (unbox-pointer self type)
+                if (icmp== ('kind T) type-kind-integer)
+                    return `[(sc_integer_type ('bitcount T) true)]
+            elseif (ptrcmp== (unbox-pointer (sc_getarg args 0) type) integer)
+                let self = (sc_getarg args 1)
+                let width = (unbox-integer self i32)
+                return `[(sc_integer_type width true)]
+            error "syntax: (signed <integer-type>) or (signed integer <size>)"
 
 let protect =
     spice-macro

          
@@ 3524,6 3553,7 @@ define-infix> 600 //
 define-infix> 600 *
 define-infix< 700 ** pow
 define-infix> 750 as
+define-infix> 750 raises
 define-infix> 780 :
 define-infix> 800 .
 define-infix> 800 @

          
M src/qualifier/key_qualifier.cpp +4 -1
@@ 42,10 42,13 @@ KeyQualifier::KeyQualifier(Symbol _key)
     : Qualifier((QualifierKind)Kind), key(_key) {}
 
 void KeyQualifier::stream_prefix(StyledStream &ss) const {
-    ss << key.name()->data << "=";
+    ss << "(";
+    ss << key.name()->data;
+    ss << " = ";
 }
 
 void KeyQualifier::stream_postfix(StyledStream &ss) const {
+    ss << ")";
 }
 
 //------------------------------------------------------------------------------

          
M src/qualifier/refer_qualifier.cpp +14 -12
@@ 40,21 40,23 @@ static std::unordered_set<const ReferQua
 //------------------------------------------------------------------------------
 
 void ReferQualifier::stream_prefix(StyledStream &ss) const {
+    ss << "(";
+    if (pointer_flags_is_readable(flags) && pointer_flags_is_writable(flags)) {
+        ss << "mutable& ";
+    } else if (pointer_flags_is_readable(flags)) {
+        ss << "& ";
+    } else if (pointer_flags_is_writable(flags)) {
+        ss << "writeonly& ";
+    } else {
+        ss << "opaque& ";
+    }
+    if (storage_class != SYM_Unnamed) {
+        ss << "(storage = " << storage_class << ") ";
+    }
 }
 
 void ReferQualifier::stream_postfix(StyledStream &ss) const {
-    if (pointer_flags_is_readable(flags) && pointer_flags_is_writable(flags)) {
-        ss << "&";
-    } else if (pointer_flags_is_readable(flags)) {
-        ss << "(&)";
-    } else if (pointer_flags_is_writable(flags)) {
-        ss << "!&!";
-    } else {
-        ss << "<&>";
-    }
-    if (storage_class != SYM_Unnamed) {
-        ss << "[" << storage_class.name()->data << "]";
-    }
+    ss << ")";
 }
 
 const Type *ReferQualifier::get_pointer_type(const Type *ET) const {

          
M src/qualifier/unique_qualifiers.cpp +11 -11
@@ 153,29 153,29 @@ ViewQualifier::ViewQualifier(const IDSet
 }
 
 void ViewQualifier::stream_prefix(StyledStream &ss) const {
-    ss << "%";
-    if (sorted_ids.empty()) {
-        ss << "?";
-    } else {
+    ss << "(viewof ";
+}
+
+void ViewQualifier::stream_postfix(StyledStream &ss) const {
+    if (!sorted_ids.empty()) {
         for (int i = 0; i < sorted_ids.size(); ++i) {
-            if (i > 0) ss << "|";
+            ss << " ";
             stream_id(ss, sorted_ids[i]);
         }
     }
-    ss << ":";
-}
-
-void ViewQualifier::stream_postfix(StyledStream &ss) const {
+    ss << ")";
 }
 
 //------------------------------------------------------------------------------
 
 void UniqueQualifier::stream_prefix(StyledStream &ss) const {
-    stream_id(ss, id);
-    ss << ":";
+    ss << "(uniqueof ";
 }
 
 void UniqueQualifier::stream_postfix(StyledStream &ss) const {
+    ss << " ";
+    stream_id(ss, id);
+    ss << ")";
 }
 
 UniqueQualifier::UniqueQualifier(int _id)

          
M src/type/arguments_type.cpp +2 -4
@@ 53,11 53,9 @@ void ArgumentsType::stream_name(StyledSt
     if (values.size() == 0) {
         ss << "void";
     } else {
-        ss << "λ(";
+        ss << "(_:";
         for (size_t i = 0; i < values.size(); ++i) {
-            if (i > 0) {
-                ss << " ";
-            }
+            ss << " ";
             stream_type_name(ss, values[i]);
         }
         ss << ")";

          
M src/type/array_type.cpp +5 -6
@@ 37,14 37,13 @@ static std::unordered_set<const ArrayTyp
 //------------------------------------------------------------------------------
 
 void ArrayType::stream_name(StyledStream &ss) const {
-    ss << "[";
+    ss << "(array ";
     stream_type_name(ss, element_type);
-    ss << " x ";
-    if (is_unsized())
-        ss << "?";
-    else
+    if (!is_unsized()) {
+        ss << " ";
         ss << _count;
-    ss << "]";
+    }
+    ss << ")";
 }
 
 ArrayType::ArrayType(const Type *_element_type, size_t _count)

          
M src/type/function_type.cpp +15 -11
@@ 25,23 25,27 @@ namespace scopes {
 //------------------------------------------------------------------------------
 
 void FunctionType::stream_name(StyledStream &ss) const {
-    stream_type_name(ss, return_type);
-    ss << "<-";
-    if (has_exception()) {
-        ss << ">";
-        stream_type_name(ss, except_type);
+    bool exc = has_exception();
+    if (exc) {
+        ss << "(";
     }
     ss << "(";
+    if (vararg()) {
+        ss << "variadic function ";
+    } else {
+        ss << "function ";
+    }
+    stream_type_name(ss, return_type);
     for (size_t i = 0; i < argument_types.size(); ++i) {
-        if (i > 0) {
-            ss << " ";
-        }
+        ss << " ";
         stream_type_name(ss, argument_types[i]);
     }
-    if (vararg()) {
-        ss << " ...";
+    ss << ")";
+    if (exc) {
+        ss << " raises ";
+        stream_type_name(ss, except_type);
+        ss << ")";
     }
-    ss << ")";
 }
 
 FunctionType::FunctionType(const Type *_except_type,

          
M src/type/integer_type.cpp +19 -1
@@ 14,16 14,34 @@ namespace scopes {
 // INTEGER TYPE
 //------------------------------------------------------------------------------
 
+static bool is_standard_integer_size(int width) {
+    switch (width) {
+    case 8:
+    case 16:
+    case 32:
+    case 64:
+        return true;
+    default: return false;
+    }
+}
+
 void IntegerType::stream_name(StyledStream &ss) const {
     if ((width == 1) && !issigned) {
         ss << "bool";
-    } else {
+    } else if (is_standard_integer_size(width)) {
         if (issigned) {
             ss << "i";
         } else {
             ss << "u";
         }
         ss << width;
+    } else {
+        ss << "(";
+        if (issigned) {
+            ss << "signed ";
+        }
+        ss << "integer " << width;
+        ss << ")";
     }
 }
 

          
M src/type/matrix_type.cpp +7 -5
@@ 41,11 41,13 @@ static std::unordered_set<const MatrixTy
 //------------------------------------------------------------------------------
 
 void MatrixType::stream_name(StyledStream &ss) const {
-    ss << "<";
-    stream_type_name(ss, element_type);
-    ss << " * ";
-    ss << _count;
-    ss << ">";
+    ss << "(matrix ";
+    stream_type_name(ss, column_element_type);
+    ss << " ";
+    ss << count();
+    ss << " ";
+    ss << row_count;
+    ss << ")";
 }
 
 const VectorType *MatrixType::column_type() const {

          
M src/type/pointer_type.cpp +8 -6
@@ 42,19 42,21 @@ static std::unordered_set<const PointerT
 //------------------------------------------------------------------------------
 
 void PointerType::stream_name(StyledStream &ss) const {
-    stream_type_name(ss, element_type);
+    ss << "(";
     if (is_writable() && is_readable()) {
-        ss << "*";
+        ss << "mutable@ ";
     } else if (is_readable()) {
-        ss << "(*)";
+        ss << "@ ";
     } else if (is_writable()) {
-        ss << "!*!";
+        ss << "writeonly@ ";
     } else {
-        ss << "<*>";
+        ss << "opaque@ ";
     }
     if (storage_class != SYM_Unnamed) {
-        ss << "[" << storage_class.name()->data << "]";
+        ss << "(storage = " << storage_class << ") ";
     }
+    stream_type_name(ss, element_type);
+    ss << ")";
 }
 
 PointerType::PointerType(const Type *_element_type,

          
M src/type/tuple_type.cpp +7 -9
@@ 56,23 56,21 @@ static std::unordered_set<const TupleTyp
 //------------------------------------------------------------------------------
 
 void TupleType::stream_name(StyledStream &ss) const {
-    if (explicit_alignment) {
-        ss << "[align:" << align << "]";
+    if (packed) {
+        ss << "(packed ";
+    } else {
+        ss << "(tuple ";
     }
-    if (packed) {
-        ss << "<";
+    if (explicit_alignment) {
+        ss << "(__align = " << align << ") ";
     }
-    ss << "{";
     for (size_t i = 0; i < values.size(); ++i) {
         if (i > 0) {
             ss << " ";
         }
         stream_type_name(ss, values[i]);
     }
-    ss << "}";
-    if (packed) {
-        ss << ">";
-    }
+    ss << ")";
 }
 
 TupleType::TupleType(const Types &_values, bool _packed, size_t _alignment)

          
M src/type/vector_type.cpp +5 -6
@@ 39,14 39,13 @@ static std::unordered_set<const VectorTy
 //------------------------------------------------------------------------------
 
 void VectorType::stream_name(StyledStream &ss) const {
-    ss << "<";
+    ss << "(vector ";
     stream_type_name(ss, element_type);
-    ss << " x ";
-    if (is_unsized())
-        ss << "?";
-    else
+    if (!is_unsized()) {
+        ss << " ";
         ss << _count;
-    ss << ">";
+    }
+    ss << ")";
 }
 
 VectorType::VectorType(const Type *_element_type, size_t _count)