From 2bc8e5f74cdfca319f04ac2e6c13d04c05059137 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 21 Sep 2025 16:06:58 -0400 Subject: Deprecate `extern` keyword --- src/ast.c | 6 ------ src/ast.h | 5 ----- src/compile/expressions.c | 1 - src/compile/files.c | 1 - src/compile/headers.c | 18 ------------------ src/compile/statements.c | 1 - src/formatter/formatter.c | 5 ----- src/parse/expressions.c | 2 +- src/parse/files.c | 15 ++------------- src/parse/files.h | 1 - src/parse/typedefs.c | 6 +++--- src/parse/utils.c | 8 ++++---- src/typecheck.c | 10 ---------- test/extern.tm | 6 ------ 14 files changed, 10 insertions(+), 75 deletions(-) delete mode 100644 test/extern.tm diff --git a/src/ast.c b/src/ast.c index 06a0e486..4dfd7d0f 100644 --- a/src/ast.c +++ b/src/ast.c @@ -262,7 +262,6 @@ Text_t ast_to_sexp(ast_t *ast) { T(Pass, "(Pass)"); T(Defer, "(Defer ", ast_to_sexp(data.body), ")"); T(Return, "(Return ", ast_to_sexp(data.value), ")"); - T(Extern, "(Extern \"", data.name, "\" ", type_ast_to_sexp(data.type), ")"); T(StructDef, "(StructDef \"", data.name, "\" ", arg_defs_to_sexp(data.fields), " ", ast_to_sexp(data.namespace), ")"); T(EnumDef, "(EnumDef \"", data.name, "\" (tags ", tags_to_sexp(data.tags), ") ", ast_to_sexp(data.namespace), @@ -629,7 +628,6 @@ void ast_visit(ast_t *ast, void (*visitor)(ast_t *, void *), void *userdata) { ast_visit(Match(ast, Return)->value, visitor, userdata); return; } - case Extern: return; case StructDef: { DeclareMatch(def, ast, StructDef); ast_visit_args(def->fields, visitor, userdata); @@ -746,10 +744,6 @@ static void _type_ast_visit(ast_t *ast, void *userdata) { visit(Match(ast, Deserialize)->type, userdata); break; } - case Extern: { - visit(Match(ast, Extern)->type, userdata); - break; - } default: break; } } diff --git a/src/ast.h b/src/ast.h index a545e68c..53685b28 100644 --- a/src/ast.h +++ b/src/ast.h @@ -264,7 +264,6 @@ typedef enum { Pass, Defer, Return, - Extern, StructDef, EnumDef, LangDef, @@ -415,10 +414,6 @@ struct ast_s { struct { ast_t *value; } Return; - struct { - const char *name; - type_ast_t *type; - } Extern; struct { const char *name; arg_ast_t *fields; diff --git a/src/compile/expressions.c b/src/compile/expressions.c index e9906253..cd244fec 100644 --- a/src/compile/expressions.c +++ b/src/compile/expressions.c @@ -233,7 +233,6 @@ Text_t compile(env_t *env, ast_t *ast) { } case Use: code_err(ast, "Compiling 'use' as expression!"); case Defer: code_err(ast, "Compiling 'defer' as expression!"); - case Extern: code_err(ast, "Externs are not supported as expressions"); case TableEntry: code_err(ast, "Table entries should not be compiled directly"); case Declare: case Assign: diff --git a/src/compile/files.c b/src/compile/files.c index bd1e9cc3..f331a50a 100644 --- a/src/compile/files.c +++ b/src/compile/files.c @@ -150,7 +150,6 @@ Text_t compile_top_level_code(env_t *env, ast_t *ast) { extended->id_suffix = env->id_suffix; return compile_top_level_code(extended, extend->body); } - case Extern: return EMPTY_TEXT; case Block: { Text_t code = EMPTY_TEXT; for (ast_list_t *stmt = Match(ast, Block)->statements; stmt; stmt = stmt->next) { diff --git a/src/compile/headers.c b/src/compile/headers.c index f6313cd6..1865905c 100644 --- a/src/compile/headers.c +++ b/src/compile/headers.c @@ -51,24 +51,6 @@ Text_t compile_statement_namespace_header(env_t *env, Path_t header_path, ast_t block = def->namespace; break; } - case Extern: { - DeclareMatch(ext, ast, Extern); - type_t *t = parse_type_ast(env, ext->type); - Text_t decl; - if (t->tag == ClosureType) { - t = Match(t, ClosureType)->fn; - DeclareMatch(fn, t, FunctionType); - decl = Texts(compile_type(fn->ret), " ", ext->name, "("); - for (arg_t *arg = fn->args; arg; arg = arg->next) { - decl = Texts(decl, compile_type(arg->type)); - if (arg->next) decl = Texts(decl, ", "); - } - decl = Texts(decl, ")"); - } else { - decl = compile_declaration(t, Text$from_str(ext->name)); - } - return Texts("extern ", decl, ";\n"); - } case Declare: { DeclareMatch(decl, ast, Declare); const char *decl_name = Match(decl->var, Var)->name; diff --git a/src/compile/statements.c b/src/compile/statements.c index db8f5b1f..a7705adc 100644 --- a/src/compile/statements.c +++ b/src/compile/statements.c @@ -166,7 +166,6 @@ static Text_t _compile_statement(env_t *env, ast_t *ast) { ast_t *loop = WrapAST(ast, For, .vars = comp->vars, .iter = comp->iter, .body = body); return compile_statement(env, loop); } - case Extern: return EMPTY_TEXT; case InlineCCode: { DeclareMatch(inline_code, ast, InlineCCode); Text_t code = EMPTY_TEXT; diff --git a/src/formatter/formatter.c b/src/formatter/formatter.c index d37e2545..a07b903d 100644 --- a/src/formatter/formatter.c +++ b/src/formatter/formatter.c @@ -120,7 +120,6 @@ OptionalText_t format_inline_code(ast_t *ast, Table_t comments) { /*inline*/ case FunctionDef: /*inline*/ case ConvertDef: /*inline*/ case DocTest: - /*inline*/ case Extern: return NONE_TEXT; /*inline*/ case Assert: { DeclareMatch(assert, ast, Assert); @@ -580,10 +579,6 @@ Text_t format_code(ast_t *ast, Table_t comments, Text_t indent) { DeclareMatch(extend, ast, Extend); return Texts("lang ", Text$from_str(extend->name), format_namespace(extend->body, comments, indent)); } - /*multiline*/ case Extern: { - DeclareMatch(ext, ast, Extern); - return Texts("extern ", Text$from_str(ext->name), " : ", format_type(ext->type)); - } /*multiline*/ case Defer: return Texts("defer ", format_namespace(Match(ast, Defer)->body, comments, indent)); /*multiline*/ case List: { diff --git a/src/parse/expressions.c b/src/parse/expressions.c index 606c7b4e..7410f678 100644 --- a/src/parse/expressions.c +++ b/src/parse/expressions.c @@ -196,7 +196,7 @@ ast_t *parse_term_no_suffix(parse_ctx_t *ctx, const char *pos) { || (term = parse_deserialize(ctx, pos)) || (term = parse_var(ctx, pos)) || (term = parse_list(ctx, pos)) || (term = parse_reduction(ctx, pos)) || (term = parse_pass(ctx, pos)) || (term = parse_defer(ctx, pos)) || (term = parse_skip(ctx, pos)) || (term = parse_stop(ctx, pos)) || (term = parse_return(ctx, pos)) - || (term = parse_not(ctx, pos)) || (term = parse_extern(ctx, pos)) || (term = parse_inline_c(ctx, pos))); + || (term = parse_not(ctx, pos)) || (term = parse_inline_c(ctx, pos))); return term; } diff --git a/src/parse/files.c b/src/parse/files.c index 5ff41c68..caecbbe8 100644 --- a/src/parse/files.c +++ b/src/parse/files.c @@ -43,8 +43,8 @@ ast_t *parse_file_body(parse_ctx_t *ctx, const char *pos) { if ((stmt = optional(ctx, &pos, parse_struct_def)) || (stmt = optional(ctx, &pos, parse_func_def)) || (stmt = optional(ctx, &pos, parse_enum_def)) || (stmt = optional(ctx, &pos, parse_lang_def)) || (stmt = optional(ctx, &pos, parse_extend)) || (stmt = optional(ctx, &pos, parse_convert_def)) - || (stmt = optional(ctx, &pos, parse_use)) || (stmt = optional(ctx, &pos, parse_extern)) - || (stmt = optional(ctx, &pos, parse_inline_c)) || (stmt = optional(ctx, &pos, parse_top_declaration))) { + || (stmt = optional(ctx, &pos, parse_use)) || (stmt = optional(ctx, &pos, parse_inline_c)) + || (stmt = optional(ctx, &pos, parse_top_declaration))) { statements = new (ast_list_t, .ast = stmt, .next = statements); pos = stmt->end; whitespace(ctx, &pos); // TODO: check for newline @@ -151,17 +151,6 @@ ast_t *parse_use(parse_ctx_t *ctx, const char *pos) { return NewAST(ctx->file, start, pos, Use, .var = var, .path = name, .what = what); } -ast_t *parse_extern(parse_ctx_t *ctx, const char *pos) { - const char *start = pos; - if (!match_word(&pos, "extern")) return NULL; - spaces(&pos); - const char *name = get_id(&pos); - spaces(&pos); - if (!match(&pos, ":")) parser_err(ctx, start, pos, "I couldn't get a type for this extern"); - type_ast_t *type = expect(ctx, start, &pos, parse_type, "I couldn't parse the type for this extern"); - return NewAST(ctx->file, start, pos, Extern, .name = name, .type = type); -} - public ast_t *parse_file_str(const char *str) { file_t *file = spoof_file("", str); diff --git a/src/parse/files.h b/src/parse/files.h index 3073449e..ebebc20c 100644 --- a/src/parse/files.h +++ b/src/parse/files.h @@ -12,4 +12,3 @@ ast_t *parse_file(const char *path, jmp_buf *on_err); ast_t *parse_file_body(parse_ctx_t *ctx, const char *pos); ast_t *parse_use(parse_ctx_t *ctx, const char *pos); -ast_t *parse_extern(parse_ctx_t *ctx, const char *pos); diff --git a/src/parse/typedefs.c b/src/parse/typedefs.c index 50562536..fe48cb2c 100644 --- a/src/parse/typedefs.c +++ b/src/parse/typedefs.c @@ -27,8 +27,8 @@ ast_t *parse_namespace(parse_ctx_t *ctx, const char *pos) { if ((stmt = optional(ctx, &pos, parse_struct_def)) || (stmt = optional(ctx, &pos, parse_func_def)) || (stmt = optional(ctx, &pos, parse_enum_def)) || (stmt = optional(ctx, &pos, parse_lang_def)) || (stmt = optional(ctx, &pos, parse_extend)) || (stmt = optional(ctx, &pos, parse_convert_def)) - || (stmt = optional(ctx, &pos, parse_use)) || (stmt = optional(ctx, &pos, parse_extern)) - || (stmt = optional(ctx, &pos, parse_inline_c)) || (stmt = optional(ctx, &pos, parse_declaration))) { + || (stmt = optional(ctx, &pos, parse_use)) || (stmt = optional(ctx, &pos, parse_inline_c)) + || (stmt = optional(ctx, &pos, parse_declaration))) { statements = new (ast_list_t, .ast = stmt, .next = statements); pos = stmt->end; whitespace(ctx, &pos); // TODO: check for newline @@ -69,7 +69,7 @@ ast_t *parse_struct_def(parse_ctx_t *ctx, const char *pos) { for (;;) { if (match_word(&pos, "secret")) { secret = true; - } else if (match_word(&pos, "extern")) { + } else if (match_word(&pos, "external")) { external = true; } else if (match_word(&pos, "opaque")) { if (fields) diff --git a/src/parse/utils.c b/src/parse/utils.c index 0644bfa0..2048a3ff 100644 --- a/src/parse/utils.c +++ b/src/parse/utils.c @@ -12,10 +12,10 @@ #include "utils.h" static const char *keywords[] = { - "C_code", "_max_", "_min_", "and", "assert", "break", "continue", "defer", "deserialize", "do", - "else", "enum", "extend", "extern", "for", "func", "if", "in", "lang", "mod", - "mod1", "no", "none", "not", "or", "pass", "return", "skip", "skip", "stop", - "struct", "then", "unless", "use", "when", "while", "xor", "yes", + "C_code", "_max_", "_min_", "and", "assert", "break", "continue", "defer", "deserialize", "do", + "else", "enum", "extend", "for", "func", "if", "in", "lang", "mod", "mod1", + "no", "none", "not", "or", "pass", "return", "skip", "skip", "stop", "struct", + "then", "unless", "use", "when", "while", "xor", "yes", }; CONSTFUNC bool is_keyword(const char *word) { diff --git a/src/typecheck.c b/src/typecheck.c index c018c04e..64bf0fd8 100644 --- a/src/typecheck.c +++ b/src/typecheck.c @@ -611,13 +611,6 @@ void bind_statement(env_t *env, ast_t *statement) { } break; } - case Extern: { - DeclareMatch(ext, statement, Extern); - type_t *t = parse_type_ast(env, ext->type); - if (t->tag == ClosureType) t = Match(t, ClosureType)->fn; - set_binding(env, ext->name, t, Text$from_str(ext->name)); - break; - } default: break; } } @@ -1115,9 +1108,6 @@ type_t *get_type(env_t *env, ast_t *ast) { } return get_type(block_env, last->ast); } - case Extern: { - return parse_type_ast(env, Match(ast, Extern)->type); - } case Declare: case Assign: case UPDATE_CASES: diff --git a/test/extern.tm b/test/extern.tm deleted file mode 100644 index 79239a39..00000000 --- a/test/extern.tm +++ /dev/null @@ -1,6 +0,0 @@ -use -extern sqrt : func(n:Num->Num) - -func main() - >> sqrt(4) - = 2. -- cgit v1.2.3