Remove null
This commit is contained in:
16
globals.kl
16
globals.kl
@@ -4,7 +4,7 @@
|
||||
test_function :: (thing: int): *int
|
||||
function_type: test_function
|
||||
const_function_alias :: test_function
|
||||
null_function: (t: int): *int = null
|
||||
// null_function: (t: int): *int = null
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Booleans
|
||||
@@ -15,9 +15,9 @@ value_of_bool: int = cast(boolean: int)
|
||||
//-----------------------------------------------------------------------------
|
||||
// Nulls
|
||||
//-----------------------------------------------------------------------------
|
||||
int_null: int = null
|
||||
str_null: String = null
|
||||
bool_null: bool = null
|
||||
// int_null: int = null
|
||||
// str_null: String = null
|
||||
// bool_null: bool = null
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Compound expressions
|
||||
@@ -25,7 +25,7 @@ bool_null: bool = null
|
||||
array1: [4]int = [4]int(1,2,3,4)
|
||||
array2 := [32]int(1,2,3,4)
|
||||
array3 := [32]int(
|
||||
[0] = null,
|
||||
[0] = 0,
|
||||
[1] = 1,
|
||||
[2] = 2,
|
||||
[31] = 31,
|
||||
@@ -50,9 +50,9 @@ implicit_str :: "Hello world"
|
||||
//-----------------------------------------------------------------------------
|
||||
// Pointers
|
||||
//-----------------------------------------------------------------------------
|
||||
pointer1: *int = null
|
||||
pointer2: *int = pointer1
|
||||
pointer3: **int = null
|
||||
// pointer1: *int = 0
|
||||
// pointer2: *int = pointer1
|
||||
// pointer3: **int = 0
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// String types
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
a_type :: int
|
||||
pointer_type :: *int
|
||||
null_pointer: pointer_type = null
|
||||
// null_pointer: pointer_type = null
|
||||
|
||||
if_stmt :: (cond: int): type
|
||||
CONSTANT :: 10
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
Str16 :: String16
|
||||
arena_pointer: *Arena = null
|
||||
// arena_pointer: *Arena = null
|
||||
thing: Arena
|
||||
no_type := thing
|
||||
constant_access := Arena.constant_inside
|
||||
|
||||
arena := Arena(
|
||||
next = null,
|
||||
data = null,
|
||||
// next = null,
|
||||
// data = null,
|
||||
len = 1000,
|
||||
cap = 1000,
|
||||
)
|
||||
|
||||
@@ -16,13 +16,10 @@ resolve_type_pair(Token *pos, Ast_Resolved_Type *a, Ast_Resolved_Type *b){
|
||||
else if(a && !b) result = a;
|
||||
else if(!a && !b) parsing_error(pos, "Trying to resolve a type pair where both types are [Null]");
|
||||
else{ // a && b
|
||||
if(b->kind == TYPE_NULL) result = a;
|
||||
else if(a->kind == TYPE_NULL) result = b;
|
||||
else if(a != b) parsing_error(pos, "Expression and type specification are differing %s %s", type_names[a->kind], type_names[b->kind]);
|
||||
if(a != b) parsing_error(pos, "Expression and type specification are differing %s %s", type_names[a->kind], type_names[b->kind]);
|
||||
else result = a; // Types are the same
|
||||
}
|
||||
|
||||
if(result->kind == TYPE_NULL) parsing_error(pos, "Couldn't infer type of null value");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -200,11 +197,7 @@ resolve_expr(Ast_Expr *ast, Ast_Resolved_Type *expected_type, Sym *lambda_to_res
|
||||
CASE(IDENT, Atom){
|
||||
Sym *sym = resolve_name(node->pos, node->intern_val);
|
||||
|
||||
if(sym->type->kind == TYPE_NULL){
|
||||
if(!expected_type) parsing_error(node->pos, "Couldn't infer type of null");
|
||||
return operand_null(expected_type);
|
||||
}
|
||||
else if(sym->kind == SYM_CONST && sym->type != type_type && sym->type->kind != TYPE_LAMBDA){
|
||||
if(sym->kind == SYM_CONST && sym->type != type_type && sym->type->kind != TYPE_LAMBDA){
|
||||
rewrite_into_const(node, Ast_Atom, sym);
|
||||
return operand(sym);
|
||||
}
|
||||
@@ -380,7 +373,6 @@ resolve_expr(Ast_Expr *ast, Ast_Resolved_Type *expected_type, Sym *lambda_to_res
|
||||
if(type == expr.type);
|
||||
else if(expr.type == type_int && type == type_bool) type = type_bool;
|
||||
else if(expr.type == type_bool && type == type_int) type = type_int;
|
||||
else if(expr.type == type_null);
|
||||
else parsing_error(node->pos, "Failed to cast, incompatible types");
|
||||
return operand_rvalue(type);
|
||||
BREAK();
|
||||
|
||||
23
typecheck.h
23
typecheck.h
@@ -78,7 +78,6 @@ struct Ast_Resolved_Type{
|
||||
//-----------------------------------------------------------------------------
|
||||
const SizeU pointer_size = sizeof(SizeU);
|
||||
const SizeU pointer_align = __alignof(SizeU);
|
||||
global Ast_Resolved_Type type__null = {TYPE_NULL};
|
||||
global Ast_Resolved_Type type__void = {TYPE_VOID};
|
||||
global Ast_Resolved_Type type__int = {TYPE_INT, sizeof(int), __alignof(int)};
|
||||
global Ast_Resolved_Type type__string = {TYPE_STRING, sizeof(String), __alignof(String)};
|
||||
@@ -90,15 +89,14 @@ global Ast_Resolved_Type *type_void = &type__void;
|
||||
global Ast_Resolved_Type *type_int = &type__int;
|
||||
global Ast_Resolved_Type *type_string = &type__string;
|
||||
global Ast_Resolved_Type *type_bool = &type__bool;
|
||||
global Ast_Resolved_Type *type_null = &type__null;
|
||||
|
||||
global Ast_Resolved_Type type__untyped_bool = {TYPE_UNTYPED_BOOL, sizeof(bool), __alignof(bool)};
|
||||
global Ast_Resolved_Type type__untyped_int = {TYPE_UNTYPED_INT, sizeof(S64), __alignof(S64)};
|
||||
global Ast_Resolved_Type type__untyped_string = {TYPE_UNTYPED_STRING, sizeof(String), __alignof(String)};
|
||||
|
||||
global Ast_Resolved_Type *type_untyped_string = &type__untyped_string;
|
||||
global Ast_Resolved_Type *type_untyped_bool = &type__untyped_bool;
|
||||
global Ast_Resolved_Type *type_untyped_int = &type__untyped_int;
|
||||
global Ast_Resolved_Type *untyped_string = &type__untyped_string;
|
||||
global Ast_Resolved_Type *untyped_bool = &type__untyped_bool;
|
||||
global Ast_Resolved_Type *untyped_int = &type__untyped_int;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Symbols
|
||||
@@ -281,13 +279,6 @@ sym_insert_builtins(){
|
||||
Sym *sym = sym_new_resolved(SYM_CONST, string, type_bool, val, &empty_decl, false);
|
||||
sym_insert(sym);
|
||||
}
|
||||
|
||||
{
|
||||
Intern_String string = intern_string(&pctx->interns, "null"_s);
|
||||
Value val; val.int_val = 0;
|
||||
Sym *sym = sym_new_resolved(SYM_CONST, string, type_null, val, &empty_decl, false);
|
||||
sym_insert(sym);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -330,14 +321,6 @@ operand_str(Intern_String intern_val){
|
||||
return result;
|
||||
}
|
||||
|
||||
function Operand
|
||||
operand_null(Ast_Resolved_Type *type){
|
||||
Operand result = {type};
|
||||
result.is_const = true;
|
||||
result.is_lvalue = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
function Operand
|
||||
operand_lambda(Ast_Resolved_Type *type){
|
||||
Operand result = {};
|
||||
|
||||
Reference in New Issue
Block a user