From b0b23acf887bec28b5ef8d0dfe448c4228ee0eb3 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 11 Sep 2024 13:55:41 -0400 Subject: Rename "Nil"->"Null" for consistency --- ast.c | 4 ++-- ast.h | 4 ++-- compile.c | 6 +++--- parse.c | 6 +++--- repl.c | 2 +- typecheck.c | 8 ++++---- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/ast.c b/ast.c index 98d6f60d..1e89d29b 100644 --- a/ast.c +++ b/ast.c @@ -96,7 +96,7 @@ CORD ast_to_xml(ast_t *ast) switch (ast->tag) { #define T(type, ...) case type: { auto data = ast->__data.type; (void)data; return CORD_asprintf(__VA_ARGS__); } T(Unknown, "") - T(Nil, "%r", type_ast_to_xml(data.type)) + T(Null, "%r", type_ast_to_xml(data.type)) T(Bool, "", data.b ? "yes" : "no") T(Var, "%s", data.name) T(Int, "%s", data.bits, data.str) @@ -197,7 +197,7 @@ int printf_ast(FILE *stream, const struct printf_info *info, const void *const a PUREFUNC bool is_idempotent(ast_t *ast) { switch (ast->tag) { - case Int: case Bool: case Num: case Var: case Nil: case TextLiteral: return true; + case Int: case Bool: case Num: case Var: case Null: case TextLiteral: return true; case Index: { auto index = Match(ast, Index); return is_idempotent(index->indexed) && index->index != NULL && is_idempotent(index->index); diff --git a/ast.h b/ast.h index 02522a3e..e3108cae 100644 --- a/ast.h +++ b/ast.h @@ -106,7 +106,7 @@ struct type_ast_s { typedef enum { Unknown = 0, - Nil, Bool, Var, + Null, Bool, Var, Int, Num, TextLiteral, TextJoin, PrintStatement, Declare, Assign, @@ -139,7 +139,7 @@ struct ast_s { struct {} Unknown; struct { type_ast_t *type; - } Nil; + } Null; struct { bool b; } Bool; diff --git a/compile.c b/compile.c index 85321000..4b8bdfeb 100644 --- a/compile.c +++ b/compile.c @@ -1689,8 +1689,8 @@ static bool string_literal_is_all_ascii(CORD literal) CORD compile(env_t *env, ast_t *ast) { switch (ast->tag) { - case Nil: { - type_t *t = parse_type_ast(env, Match(ast, Nil)->type); + case Null: { + type_t *t = parse_type_ast(env, Match(ast, Null)->type); if (t == THREAD_TYPE) return "NULL"; switch (t->tag) { @@ -1720,7 +1720,7 @@ CORD compile(env_t *env, ast_t *ast) env_t *enum_env = Match(t, EnumType)->env; return CORD_all("((", compile_type(t), "){", namespace_prefix(enum_env->libname, enum_env->namespace), "null})"); } - default: code_err(ast, "Nil isn't implemented for this type: %T", t); + default: code_err(ast, "Null isn't implemented for this type: %T", t); } } case Bool: return Match(ast, Bool)->b ? "yes" : "no"; diff --git a/parse.c b/parse.c index b0717f8c..e33b9ef2 100644 --- a/parse.c +++ b/parse.c @@ -1468,12 +1468,12 @@ PARSER(parse_lambda) { return NewAST(ctx->file, start, pos, Lambda, .id=ctx->next_lambda_id++, .args=args, .body=body); } -PARSER(parse_nil) { +PARSER(parse_null) { const char *start = pos; if (!match(&pos, "!")) return NULL; type_ast_t *type = parse_type(ctx, pos); if (!type) return NULL; - return NewAST(ctx->file, start, type->end, Nil, .type=type); + return NewAST(ctx->file, start, type->end, Null, .type=type); } PARSER(parse_var) { @@ -1488,7 +1488,7 @@ PARSER(parse_term_no_suffix) { ast_t *term = NULL; (void)( false - || (term=parse_nil(ctx, pos)) + || (term=parse_null(ctx, pos)) || (term=parse_num(ctx, pos)) || (term=parse_int(ctx, pos)) || (term=parse_negative(ctx, pos)) diff --git a/repl.c b/repl.c index 372fcba4..ae00f545 100644 --- a/repl.c +++ b/repl.c @@ -337,7 +337,7 @@ void eval(env_t *env, ast_t *ast, void *dest) type_t *t = get_type(env, ast); size_t size = type_size(t); switch (ast->tag) { - case Nil: + case Null: if (dest) *(void**)dest = 0; break; case Bool: diff --git a/typecheck.c b/typecheck.c index dabd5532..e23ece88 100644 --- a/typecheck.c +++ b/typecheck.c @@ -489,8 +489,8 @@ type_t *get_type(env_t *env, ast_t *ast) { if (!ast) return NULL; switch (ast->tag) { - case Nil: { - type_t *t = parse_type_ast(env, Match(ast, Nil)->type); + case Null: { + type_t *t = parse_type_ast(env, Match(ast, Null)->type); return Type(OptionalType, .type=t); } case Bool: { @@ -726,7 +726,7 @@ type_t *get_type(env_t *env, ast_t *ast) auto indexing = Match(ast, Index); type_t *indexed_t = get_type(env, indexing->indexed); if (indexed_t->tag == OptionalType && !indexing->index) - code_err(ast, "You're attempting to dereference a value whose type indicates it could be nil"); + code_err(ast, "You're attempting to dereference a value whose type indicates it could be null"); if (indexed_t->tag == PointerType && !indexing->index) return Match(indexed_t, PointerType)->pointed; @@ -1360,7 +1360,7 @@ type_t *parse_type_string(env_t *env, const char *str) PUREFUNC bool is_constant(env_t *env, ast_t *ast) { switch (ast->tag) { - case Bool: case Num: case Nil: case TextLiteral: return true; + case Bool: case Num: case Null: case TextLiteral: return true; case Int: { auto info = Match(ast, Int); if (info->bits == IBITS_UNSPECIFIED) { -- cgit v1.2.3