From: Brendan Hansen Date: Fri, 8 Jan 2021 00:40:30 +0000 (-0600) Subject: added easier way to do types in value expressions X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=50a4f38c5d91a264ca4de50e65ae00c82c20c976;p=onyx.git added easier way to do types in value expressions --- diff --git a/bin/onyx b/bin/onyx index f1c5173c..e5324355 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/docs/watchout b/docs/watchout index cec05161..19c79e76 100644 --- a/docs/watchout +++ b/docs/watchout @@ -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 diff --git a/onyx.exe b/onyx.exe index 4a501d35..432a5a5e 100644 Binary files a/onyx.exe and b/onyx.exe differ diff --git a/src/onyxparser.c b/src/onyxparser.c index c7b4cd68..9af7c208 100644 --- a/src/onyxparser.c +++ b/src/onyxparser.c @@ -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); diff --git a/tests/struct_robustness.onyx b/tests/struct_robustness.onyx index fb526c4a..2e3872a0 100644 --- a/tests/struct_robustness.onyx +++ b/tests/struct_robustness.onyx @@ -117,7 +117,7 @@ main :: proc (args: [] cstr) { printf("PolyStruct(%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 := .{ 1234, 5678 }; printf("PolyStruct(%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 :: ; ps := PolyStructTyped.{}; printf("PolyStruct(%i, %f)\n", ps.t_data, ps.r_data);