authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-11-21 09:48:21+01:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-11-21 09:48:21+01:00
logccdaf946b969661220737ec747e5a720b13d0bc7
tree7fc1bd540aa4d15612880181c968647dc5ba4e6d
parent9b7d9c72b09bc268338b66e708b33213bbaae675

Rename back to extern, extend a stage1 parser hack

Make it recognize extern/export symbols prefixed by @ as a builtin rather than stand-alone keywords.

2 files changed, 9 insertions(+), 6 deletions(-)

src/stage1/codegen.cpp+1-1
......@@ -8826,7 +8826,7 @@ static void define_builtin_fns(CodeGen *g) {
88268826 create_builtin_fn(g, BuiltinFnIdAlignCast, "alignCast", 2);
88278827 create_builtin_fn(g, BuiltinFnIdSetAlignStack, "setAlignStack", 1);
88288828 create_builtin_fn(g, BuiltinFnIdExport, "export", 2);
8829 create_builtin_fn(g, BuiltinFnIdExtern, "extern1", 2);
8829 create_builtin_fn(g, BuiltinFnIdExtern, "extern", 2);
88308830 create_builtin_fn(g, BuiltinFnIdErrorReturnTrace, "errorReturnTrace", 0);
88318831 create_builtin_fn(g, BuiltinFnIdAtomicRmw, "atomicRmw", 5);
88328832 create_builtin_fn(g, BuiltinFnIdAtomicLoad, "atomicLoad", 3);
src/stage1/parser.cpp+8-5
......@@ -1652,18 +1652,21 @@ static AstNode *ast_parse_primary_type_expr(ParseContext *pc) {
16521652 // TODO: This is not in line with the grammar.
16531653 // Because the prev stage 1 tokenizer does not parse
16541654 // @[a-zA-Z_][a-zA-Z0-9_] as one token, it has to do a
1655 // hack, where it accepts '@' (IDENTIFIER / KEYWORD_export).
1655 // hack, where it accepts '@' (IDENTIFIER / KEYWORD_export /
1656 // KEYWORD_extern).
16561657 // I'd say that it's better if '@' is part of the builtin
16571658 // identifier token.
16581659 Token *at_sign = eat_token_if(pc, TokenIdAtSign);
16591660 if (at_sign != nullptr) {
16601661 Buf *name;
1661 Token *token = eat_token_if(pc, TokenIdKeywordExport);
1662 if (token == nullptr) {
1662 Token *token;
1663 if ((token = eat_token_if(pc, TokenIdKeywordExport)) != nullptr) {
1664 name = buf_create_from_str("export");
1665 } else if ((token = eat_token_if(pc, TokenIdKeywordExtern)) != nullptr) {
1666 name = buf_create_from_str("extern");
1667 } else {
16631668 token = expect_token(pc, TokenIdSymbol);
16641669 name = token_buf(token);
1665 } else {
1666 name = buf_create_from_str("export");
16671670 }
16681671
16691672 AstNode *res = ast_expect(pc, ast_parse_fn_call_arguments);