aboutsummaryrefslogtreecommitdiff
path: root/src/checker/checker.cpp
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2016-10-06 17:11:17 +0100
committerGinger Bill <bill@gingerbill.org>2016-10-06 17:11:17 +0100
commit50301557b2425fc0b4dd213ad03fb635cbd6e454 (patch)
treebcb09c25f839099ac172529283bc7e4a147614d8 /src/checker/checker.cpp
parentfee504636f9cd7633217e1877ee1b99e555bba63 (diff)
Untyped `nil`
Diffstat (limited to 'src/checker/checker.cpp')
-rw-r--r--src/checker/checker.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/checker/checker.cpp b/src/checker/checker.cpp
index c69b5d27e..90f04c588 100644
--- a/src/checker/checker.cpp
+++ b/src/checker/checker.cpp
@@ -33,6 +33,10 @@ struct Operand {
BuiltinProcId builtin_id;
};
+b32 is_operand_nil(Operand *o) {
+ return o->mode == Addressing_Value && o->type == t_untyped_nil;
+}
+
struct TypeAndValue {
AddressingMode mode;
Type *type;
@@ -241,7 +245,9 @@ struct Checker {
gbArray(ProcedureInfo) procs; // NOTE(bill): Procedures to check
gbArena arena;
+ gbArena tmp_arena;
gbAllocator allocator;
+ gbAllocator tmp_allocator;
CheckerContext context;
@@ -501,9 +507,10 @@ void init_universal_scope(void) {
}
// Constants
- add_global_constant(a, make_string("true"), t_untyped_bool, make_exact_value_bool(true));
- add_global_constant(a, make_string("false"), t_untyped_bool, make_exact_value_bool(false));
- add_global_constant(a, make_string("null"), t_untyped_pointer, make_exact_value_pointer(NULL));
+ add_global_constant(a, make_string("true"), t_untyped_bool, make_exact_value_bool(true));
+ add_global_constant(a, make_string("false"), t_untyped_bool, make_exact_value_bool(false));
+
+ add_global_entity(make_entity_nil(a, NULL, make_token_ident(make_string("nil")), t_untyped_nil));
// Builtin Procedures
for (isize i = 0; i < gb_count_of(builtin_procs); i++) {
@@ -564,7 +571,10 @@ void init_checker(Checker *c, Parser *parser, BaseTypeSizes sizes) {
}
isize arena_size = 2 * item_size * total_token_count;
gb_arena_init_from_allocator(&c->arena, a, arena_size);
+ gb_arena_init_from_allocator(&c->tmp_arena, a, arena_size);
+
c->allocator = gb_arena_allocator(&c->arena);
+ c->tmp_allocator = gb_arena_allocator(&c->tmp_arena);
c->global_scope = make_scope(universal_scope, c->allocator);
c->context.scope = c->global_scope;
@@ -705,6 +715,10 @@ void add_type_info_type(Checker *c, Type *t) {
return;
}
t = default_type(t);
+ if (is_type_untyped(t)) {
+ return; // Could be nil
+ }
+
if (map_get(&c->info.type_info_map, hash_pointer(t)) != NULL) {
// Types have already been added
return;