removed "as" keyword
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 27 Aug 2022 21:12:01 +0000 (16:12 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 27 Aug 2022 21:12:01 +0000 (16:12 -0500)
12 files changed:
core/container/avl_tree.onyx
core/container/iter.onyx
core/container/map.onyx
core/container/set.onyx
core/hash.onyx
examples/13_use_keyword.onyx
examples/22_interfaces.onyx
include/lex.h
src/lex.c
src/parser.c
tests/complicated_polymorph.onyx
tests/interfaces.onyx

index 554ea44e2d2d78dc85d97047710f455f34ec1210..ff4094179f382d7be12930ac2de2590f9adf1e7c 100644 (file)
@@ -63,7 +63,10 @@ contains :: (tree: ^AVL_Tree, data: tree.T) -> bool {
 }
 
 print :: (tree: ^AVL_Tree) {
-    use package core {print as std_print, printf}
+    use core {
+        std_print :: print,
+        printf
+    }
 
     if tree == null {
         std_print("_ ");
index 829db3b6baed1eecfcd6768ef8edfe1c01d04ad2..33222bc11ec54a8bf803797ba1a2346c704d09ee 100644 (file)
@@ -29,7 +29,7 @@ package core.iter
 as_iterator :: #match {}
 
 #local __iterable_test :: macro (i: Iterator($V)) {}
-Iterable :: interface (T as t) {
+Iterable :: interface (t: $T) {
     as_iterator(t) |> __iterable_test();
 }
 
index df66e8c161121c807ce0a7171848beac5fe7a313..e12ebaceeedc5e2701c1db7b8d9d2facb2180f66 100644 (file)
@@ -11,7 +11,7 @@ package core.map
 }
 
 #local {
-    ValidKey :: interface (T as t) {
+    ValidKey :: interface (t: $T) {
         // In order to use a certain type as a key in a Map, you must
         // provide an implementation of core.hash.to_u32() for that type,
         // and you must provide an operator overload for ==.
index dd429e14c3ec7a8e5b82fbb75b378201017fe032..c758f0adab19460c933026c171d76574d4dbb717 100644 (file)
@@ -7,7 +7,7 @@ package core.set
     math :: package core.math
 }
 
-#local SetValue :: interface (T as t) {
+#local SetValue :: interface (t: $T) {
     { hash.to_u32(t) } -> u32;
     { t == t } -> bool;
 }
index 3d85ed1af55b61e2aabe18751acdeedfc71ba2f8..baa671251e4da2fb85e7aa73669e3191ea844054 100644 (file)
@@ -14,6 +14,6 @@ to_u32 :: #match {
     (key: type_expr) -> u32 do return to_u32(cast(u32) key);
 }
 
-Hashable :: interface (T as t) {
+Hashable :: interface (t: $T) {
     { to_u32(t) } -> u32;
 }
index b35764010944b1cd78d0a3767bc7515c5a4402f7..cb30eac094251940d1f2a830e4c25bd3ee4c1eae 100644 (file)
@@ -28,7 +28,7 @@ main :: (args: [] cstr) {
         use package core.alloc
 
         // You can also restrict and partially rename the symbols that collide
-        use package core.string { free as string_free }
+        use package core.string { string_free :: free }
     }
 
     {
index 7d5709d14c619c9c9dc5124f069ae88b8443f3b6..1bf958afecce30f727eeca6e1fabe167690d7296 100644 (file)
@@ -32,7 +32,7 @@ add_example :: () {
     // expressions do not type check correctly, then the set of parameters does not
     // satisfy the interface.
 
-    CanAdd :: interface (T as t) {
+    CanAdd :: interface (t: $T) {
         t + t;
     }
 
@@ -59,7 +59,7 @@ add_example :: () {
 
 // These have to be defined out here because #operator and #match are only allowed
 // as top level expressions currently.
-NumberLike :: interface (T as t) {
+NumberLike :: interface (t: $T) {
     // The constraints here are a little stricter than before. This syntax
     // allows you to specify the expected type of the expression. If the type
     // of the expression and the type after the arrow do not match, then the
@@ -101,7 +101,7 @@ overloaded_procedure_example :: () {
     // when the are combined with overloaded procedures.
 
     // Take this example. Here is the same CanAdd interface from before.
-    CanAdd :: interface (T as t) {
+    CanAdd :: interface (t: $T) {
         t + t;
     }
 
index f1395b72e29b02a0a5f07da3cee7b7c250bfd47d..df6844763b3ab1449ce39c3424aac4855017fc0e 100644 (file)
@@ -23,7 +23,6 @@ typedef enum TokenType {
     Token_Type_Keyword_Elseif,
     Token_Type_Keyword_Return,
     Token_Type_Keyword_Global,
-    Token_Type_Keyword_As,
     Token_Type_Keyword_Cast,
     Token_Type_Keyword_While,
     Token_Type_Keyword_For,
index c34cc951b1e44fdbb5acc915c7726c77cb2625ec..eba315ed9fd6aa320ea7632b3ee7ddba95491639 100644 (file)
--- a/src/lex.c
+++ b/src/lex.c
@@ -21,7 +21,6 @@ static const char* token_type_names[] = {
     "elseif",
     "return",
     "global",
-    "as",
     "cast",
     "while",
     "for",
@@ -342,7 +341,6 @@ whitespace_skipped:
     switch (curr) {
     case 'a':
         LITERAL_TOKEN("alignof",     1, Token_Type_Keyword_Alignof);
-        LITERAL_TOKEN("as",          1, Token_Type_Keyword_As);
         break;
     case 'b':
         LITERAL_TOKEN("break",       1, Token_Type_Keyword_Break);
index f41fe0939aa3f8a11dae000d3a994806dbf058b9..e98ffd16cfe55f6b439ff41187e9149a2ca4ce0a 100644 (file)
@@ -1398,12 +1398,13 @@ static AstNode* parse_use_stmt(OnyxParser* parser) {
             if (parser->hit_unexpected_token) return NULL;
 
             QualifiedUse qu;
-            qu.symbol_name = expect_token(parser, Token_Type_Symbol);
+            qu.as_name = expect_token(parser, Token_Type_Symbol);
+            qu.symbol_name = qu.as_name;
 
-            if (consume_token_if_next(parser, Token_Type_Keyword_As))
-                qu.as_name = expect_token(parser, Token_Type_Symbol);
-            else
-                qu.as_name = qu.symbol_name;
+            if (consume_token_if_next(parser, ':')) {
+                expect_token(parser, ':');
+                qu.symbol_name = expect_token(parser, Token_Type_Symbol);
+            }
 
             bh_arr_push(use_node->only, qu);
 
@@ -2151,9 +2152,10 @@ static AstInterface* parse_interface(OnyxParser* parser) {
         if (parser->hit_unexpected_token) return interface;
 
         InterfaceParam ip;
-        ip.type_token  = expect_token(parser, Token_Type_Symbol);
-        expect_token(parser, Token_Type_Keyword_As);
         ip.value_token = expect_token(parser, Token_Type_Symbol);
+        expect_token(parser, ':');
+        expect_token(parser, '$');
+        ip.type_token  = expect_token(parser, Token_Type_Symbol);
 
         bh_arr_push(interface->params, ip);
 
@@ -3112,6 +3114,19 @@ static void parse_top_level_statement(OnyxParser* parser) {
             goto submit_binding_to_entities;
         }
 
+        case '(': {
+            AstTyped *retval = NULL;
+            if (parse_possible_function_definition(parser, &retval)) {
+                ENTITY_SUBMIT(retval);
+                return;
+            }
+            if (parse_possible_quick_function_definition(parser, &retval)) {
+                ENTITY_SUBMIT(retval);
+                return;
+            }
+            break;
+        }
+
         case '#': {
             if (next_tokens_are(parser, 2, '#', Token_Type_Keyword_If)) {
                 AstIf* static_if = parse_static_if_stmt(parser, 0);
index aaa9c5583e9aadffde6a1e870afc41bce26dd98e..754edbc4de17ef3905dcfadeeb8db417aa0e29d9 100644 (file)
@@ -14,7 +14,7 @@ main :: (args: [] cstr) {
         return g(f(a));
     }
 
-    Number :: interface (T as t) {
+    Number :: interface (t: $T) {
         { t * t } -> T;
     }
 
index 6ac739029d89ed945374801bc93fdef981ff031d..897f903ae7ea59ecdd511e30c97b8752a1220a3f 100644 (file)
@@ -2,7 +2,7 @@
 
 use package core
 
-Hashable :: interface (T as t) {
+Hashable :: interface (t :$T) {
     { hash.to_u32(t) } -> u32;
 }
 
@@ -16,7 +16,7 @@ try_hash :: #match {
     },
 }
 
-CanCastTo :: interface (T as t, D as d) {
+CanCastTo :: interface (t: $T, d: $D) {
     { cast(D) t } -> D;
 }
 
@@ -37,7 +37,7 @@ do_math :: macro (x, y: $T) -> T where SemiRing(T) {
     return x + y + x * y;
 }
 
-SemiRing :: interface (T as t) {
+SemiRing :: interface (t: $T) {
     {t + t} -> T;
     {t * t} -> T;
 }
@@ -46,7 +46,7 @@ bit_math :: (x, y: $T) -> T where BitField(T) {
     return (x & y) | (x ^ y);
 }
 
-BitField :: interface (T as t) {
+BitField :: interface (t: $T) {
     { ~t } -> T;
     { t & t } -> T;
     { t | t } -> T;