From d8c80fb7a3ffbbc28f892a458d68afc409f9292c Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Wed, 29 Mar 2023 11:42:40 +0200 Subject: [PATCH] Add polymorph token --- core_compiler_interface.hpp | 1 + core_lexing.cpp | 10 ++++++++++ examples/push_struct.core | 2 +- examples/unions.core | 2 +- meta.py | 1 + 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/core_compiler_interface.hpp b/core_compiler_interface.hpp index 20de468..4de6999 100644 --- a/core_compiler_interface.hpp +++ b/core_compiler_interface.hpp @@ -127,6 +127,7 @@ for i in meta.token_kinds: TK_DoubleColon, TK_At, TK_Arrow, + TK_Polymorph, TK_ExprSizeof, TK_DocComment, TK_Comment, diff --git a/core_lexing.cpp b/core_lexing.cpp index 90aa149..576e099 100644 --- a/core_lexing.cpp +++ b/core_lexing.cpp @@ -410,6 +410,15 @@ lex__stream(Core_Ctx *lexer) { CASE3('&', TK_BitAnd, TK_AndAssign, TK_And); CASE3('|', TK_BitOr, TK_OrAssign, TK_Or); + case '$': { + t.kind = TK_Polymorph; + lex_parse_ident(table, s, &t); + t.str += 1; + t.len -= 1; + t.intern_val = intern_string(table, t.string); + if (t.len == 0) token_error(&t, "Polymorph token without content"_s); + } break; + case '#': { t.kind = TK_Pound; lex_parse_ident(table, s, &t); @@ -758,6 +767,7 @@ for i in meta.token_kinds: case TK_DoubleColon: return "::"; case TK_At: return "@"; case TK_Arrow: return "->"; + case TK_Polymorph: return "$"; case TK_ExprSizeof: return "[SizeOf]"; case TK_DocComment: return "[///]"; case TK_Comment: return "//"; diff --git a/examples/push_struct.core b/examples/push_struct.core index 94daf95..cb4e60e 100644 --- a/examples/push_struct.core +++ b/examples/push_struct.core @@ -1,7 +1,7 @@ MA :: #import "Arena.core" /* -PushStruct :: (a: *MA.Arena, $Type): *Type +PushStruct :: (a: *MA.Arena, $T: Type): *$T size := size_of(Type) result := PushSize(a, size) return result diff --git a/examples/unions.core b/examples/unions.core index ebf0338..14d54b7 100644 --- a/examples/unions.core +++ b/examples/unions.core @@ -37,4 +37,4 @@ examples/unions.core - Error! Couldn't infer type of compound expression c = {10} */ - return 0 \ No newline at end of file + return 0 diff --git a/meta.py b/meta.py index 6789cf1..8f6f4f3 100644 --- a/meta.py +++ b/meta.py @@ -83,6 +83,7 @@ token_rest = [ ["DoubleColon", "::"], ["At", "@"], ["Arrow", "->"], + ["Polymorph", "$"], ["ExprSizeof", "[SizeOf]"], ["DocComment", "[///]"], ["Comment", "//"],