Rename "Nil"->"Null" for consistency
This commit is contained in:
parent
2c90750a3e
commit
b0b23acf88
4
ast.c
4
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, "<Unknown>")
|
||||
T(Nil, "<Nil>%r</Nil>", type_ast_to_xml(data.type))
|
||||
T(Null, "<Null>%r</Null>", type_ast_to_xml(data.type))
|
||||
T(Bool, "<Bool value=\"%s\" />", data.b ? "yes" : "no")
|
||||
T(Var, "<Var>%s</Var>", data.name)
|
||||
T(Int, "<Int bits=\"%d\">%s</Int>", 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);
|
||||
|
4
ast.h
4
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;
|
||||
|
@ -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";
|
||||
|
6
parse.c
6
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))
|
||||
|
2
repl.c
2
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:
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user