added easier way to do types in value expressions
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 8 Jan 2021 00:40:30 +0000 (18:40 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 8 Jan 2021 00:40:30 +0000 (18:40 -0600)
bin/onyx
docs/watchout
onyx.exe
src/onyxparser.c
tests/struct_robustness.onyx

index f1c5173cb19698e24dafb5f29bc347237d5ed0f2..e532435510a50cb1de385e6d4f565b1bdf2e46da 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index cec05161de2b1a4a5c8978bd15951092b2d5b834..19c79e76df59479d38ccb944cf9cae0c2a75fec2 100644 (file)
@@ -15,4 +15,10 @@ Some tags to watch out for in the code with features that may be removed in the
 
         The implementation of `null_proc` is rather simple, but feels a
         little verbose an targential compared to everything else being done
-        in the compiler.
\ No newline at end of file
+        in the compiler.
+
+    :TypeValueInterchange
+        Angle brackets are being used to specify types in value expressions
+        and vice versa. This is just a temporary hack. The long term goal
+        is that type expressions are automatically detected in value
+        expressions.
\ No newline at end of file
index 4a501d357c1dec782e5208537e99526be82a9bf3..432a5a5e3ac9fea9dad314b83fdaf55ef0c07c48 100644 (file)
Binary files a/onyx.exe and b/onyx.exe differ
index c7b4cd68811c31687d38e674443eb517105abf15..9af7c208af2fb598f69a8e8a470ac65212541680 100644 (file)
@@ -428,6 +428,17 @@ static AstTyped* parse_factor(OnyxParser* parser) {
             break;
         }
 
+        // :TypeValueInterchange
+        case '<': {
+            AstTypeAlias* alias = make_node(AstTypeAlias, Ast_Kind_Type_Alias);
+            alias->token = expect_token(parser, '<');
+            alias->to = parse_type(parser);
+            expect_token(parser, '>');
+
+            retval = (AstTyped *) alias;
+            break;
+        }
+
         case '#': {
             if (parse_possible_directive(parser, "file_contents")) {
                 AstFileContents* fc = make_node(AstFileContents, Ast_Kind_File_Contents);
@@ -1542,6 +1553,16 @@ static AstType* parse_type(OnyxParser* parser) {
             break;
         }
 
+        else if (parser->curr->type == '<') {
+            // :TypeValueInterchange
+            expect_token(parser, '<');
+            *next_insertion = (AstType *) parse_expression(parser);
+            next_insertion = NULL;
+            expect_token(parser, '>');
+
+            break;
+        }
+
         else {
             onyx_report_error(parser->curr->pos, "unexpected token '%b'.", parser->curr->text, parser->curr->length);
             consume_token(parser);
index fb526c4adf3b3b2f9c426277ed345828570ed7b0..2e3872a05b1bad8369b0cb50b690978ca5900a0f 100644 (file)
@@ -117,7 +117,7 @@ main :: proc (args: [] cstr) {
         printf("PolyStruct<i32, f32>(%i, %f)\n", ps1.t_data, ps1.r_data);
 
         // Currently, this is how you have to do this.
-        ps2 := (#type PolyStruct(f32, i32)).{ 1234, 5678 };
+        ps2 := <PolyStruct(f32, i32)>.{ 1234, 5678 };
         printf("PolyStruct<f32, i32>(%f, %i)\n", ps2.t_data, ps2.r_data);
     }
 
@@ -129,7 +129,7 @@ main :: proc (args: [] cstr) {
             r_data : R = 5678;
         }
 
-        PolyStructTyped :: #type PolyStruct(i32, f32);
+        PolyStructTyped :: <PolyStruct(i32, f32)>;
 
         ps := PolyStructTyped.{};
         printf("PolyStruct<i32, f32>(%i, %f)\n", ps.t_data, ps.r_data);