mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-25 17:03:48 +00:00
Slice creation for SliceExpr
This commit is contained in:
@@ -312,16 +312,16 @@ void init_universal_scope(void) {
|
||||
}
|
||||
|
||||
// Constants
|
||||
add_global_constant(a, make_string("true"), &basic_types[Basic_UntypedBool], make_exact_value_bool(true));
|
||||
add_global_constant(a, make_string("false"), &basic_types[Basic_UntypedBool], make_exact_value_bool(false));
|
||||
add_global_constant(a, make_string("null"), &basic_types[Basic_UntypedPointer], 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_constant(a, make_string("null"), t_untyped_pointer, make_exact_value_pointer(NULL));
|
||||
|
||||
// Builtin Procedures
|
||||
for (isize i = 0; i < gb_count_of(builtin_procedures); i++) {
|
||||
BuiltinProcedureId id = cast(BuiltinProcedureId)i;
|
||||
Token token = {Token_Identifier};
|
||||
token.string = builtin_procedures[i].name;
|
||||
Entity *entity = alloc_entity(a, Entity_Builtin, NULL, token, &basic_types[Basic_Invalid]);
|
||||
Entity *entity = alloc_entity(a, Entity_Builtin, NULL, token, t_invalid);
|
||||
entity->builtin.id = id;
|
||||
add_global_entity(entity);
|
||||
}
|
||||
@@ -433,7 +433,7 @@ void add_type_and_value(CheckerInfo *i, AstNode *expression, AddressingMode mode
|
||||
|
||||
if (mode == Addressing_Constant) {
|
||||
GB_ASSERT(value.kind != ExactValue_Invalid);
|
||||
GB_ASSERT(type == &basic_types[Basic_Invalid] || is_type_constant_type(type));
|
||||
GB_ASSERT(type == t_invalid || is_type_constant_type(type));
|
||||
}
|
||||
|
||||
TypeAndValue tv = {};
|
||||
|
||||
+27
-27
@@ -167,7 +167,7 @@ void check_identifier(Checker *c, Operand *o, AstNode *n, Type *named_type) {
|
||||
switch (e->kind) {
|
||||
case Entity_Constant:
|
||||
add_declaration_dependency(c, e);
|
||||
if (e->type == &basic_types[Basic_Invalid])
|
||||
if (e->type == t_invalid)
|
||||
return;
|
||||
o->value = e->constant.value;
|
||||
GB_ASSERT(o->value.kind != ExactValue_Invalid);
|
||||
@@ -177,7 +177,7 @@ void check_identifier(Checker *c, Operand *o, AstNode *n, Type *named_type) {
|
||||
case Entity_Variable:
|
||||
add_declaration_dependency(c, e);
|
||||
e->variable.used = true;
|
||||
if (e->type == &basic_types[Basic_Invalid])
|
||||
if (e->type == t_invalid)
|
||||
return;
|
||||
o->mode = Addressing_Variable;
|
||||
break;
|
||||
@@ -306,7 +306,7 @@ Type *check_type_expr_extra(Checker *c, AstNode *e, Type *named_type) {
|
||||
break;
|
||||
}
|
||||
|
||||
Type *t = &basic_types[Basic_Invalid];
|
||||
Type *t = t_invalid;
|
||||
set_base_type(named_type, t);
|
||||
return t;
|
||||
}
|
||||
@@ -396,7 +396,7 @@ Type *check_type(Checker *c, AstNode *e, Type *named_type) {
|
||||
break;
|
||||
}
|
||||
|
||||
type = &basic_types[Basic_Invalid];
|
||||
type = t_invalid;
|
||||
set_base_type(named_type, type);
|
||||
|
||||
end:
|
||||
@@ -672,7 +672,7 @@ void check_comparison(Checker *c, Operand *x, Operand *y, Token op) {
|
||||
// TODO(bill): What should I do?
|
||||
}
|
||||
|
||||
x->type = &basic_types[Basic_UntypedBool];
|
||||
x->type = t_untyped_bool;
|
||||
}
|
||||
|
||||
void check_binary_expr(Checker *c, Operand *x, AstNode *node) {
|
||||
@@ -707,8 +707,8 @@ void check_binary_expr(Checker *c, Operand *x, AstNode *node) {
|
||||
}
|
||||
|
||||
if (!are_types_identical(x->type, y->type)) {
|
||||
if (x->type != &basic_types[Basic_Invalid] &&
|
||||
y->type != &basic_types[Basic_Invalid]) {
|
||||
if (x->type != t_invalid &&
|
||||
y->type != t_invalid) {
|
||||
gbString xt = type_to_string(x->type);
|
||||
gbString yt = type_to_string(y->type);
|
||||
defer (gb_string_free(xt));
|
||||
@@ -833,7 +833,7 @@ void convert_to_typed(Checker *c, Operand *operand, Type *target_type) {
|
||||
GB_ASSERT_NOT_NULL(target_type);
|
||||
if (operand->mode == Addressing_Invalid ||
|
||||
is_type_typed(operand->type) ||
|
||||
target_type == &basic_types[Basic_Invalid]) {
|
||||
target_type == t_invalid) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -883,7 +883,7 @@ void convert_to_typed(Checker *c, Operand *operand, Type *target_type) {
|
||||
case Type_Pointer:
|
||||
switch (operand->type->basic.kind) {
|
||||
case Basic_UntypedPointer:
|
||||
target_type = &basic_types[Basic_UntypedPointer];
|
||||
target_type = t_untyped_pointer;
|
||||
break;
|
||||
default:
|
||||
convert_untyped_error(c, operand, target_type);
|
||||
@@ -907,7 +907,7 @@ b32 check_index_value(Checker *c, AstNode *index_value, i64 max_count, i64 *valu
|
||||
return false;
|
||||
}
|
||||
|
||||
convert_to_typed(c, &operand, &basic_types[Basic_int]);
|
||||
convert_to_typed(c, &operand, t_int);
|
||||
if (operand.mode == Addressing_Invalid) {
|
||||
if (value) *value = 0;
|
||||
return false;
|
||||
@@ -1052,7 +1052,7 @@ b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id)
|
||||
|
||||
operand->mode = Addressing_Constant;
|
||||
operand->value = make_exact_value_integer(type_size_of(c->sizes, c->allocator, type));
|
||||
operand->type = &basic_types[Basic_int];
|
||||
operand->type = t_int;
|
||||
|
||||
} break;
|
||||
|
||||
@@ -1064,7 +1064,7 @@ b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id)
|
||||
|
||||
operand->mode = Addressing_Constant;
|
||||
operand->value = make_exact_value_integer(type_size_of(c->sizes, c->allocator, operand->type));
|
||||
operand->type = &basic_types[Basic_int];
|
||||
operand->type = t_int;
|
||||
break;
|
||||
|
||||
case BuiltinProcedure_align_of: {
|
||||
@@ -1076,7 +1076,7 @@ b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id)
|
||||
}
|
||||
operand->mode = Addressing_Constant;
|
||||
operand->value = make_exact_value_integer(type_align_of(c->sizes, c->allocator, type));
|
||||
operand->type = &basic_types[Basic_int];
|
||||
operand->type = t_int;
|
||||
} break;
|
||||
|
||||
case BuiltinProcedure_align_of_val:
|
||||
@@ -1087,7 +1087,7 @@ b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id)
|
||||
|
||||
operand->mode = Addressing_Constant;
|
||||
operand->value = make_exact_value_integer(type_align_of(c->sizes, c->allocator, operand->type));
|
||||
operand->type = &basic_types[Basic_int];
|
||||
operand->type = t_int;
|
||||
break;
|
||||
|
||||
case BuiltinProcedure_offset_of: {
|
||||
@@ -1118,7 +1118,7 @@ b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id)
|
||||
|
||||
operand->mode = Addressing_Constant;
|
||||
operand->value = make_exact_value_integer(type_offset_of(c->sizes, c->allocator, type, index));
|
||||
operand->type = &basic_types[Basic_int];
|
||||
operand->type = t_int;
|
||||
} break;
|
||||
|
||||
case BuiltinProcedure_offset_of_val: {
|
||||
@@ -1154,7 +1154,7 @@ b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id)
|
||||
|
||||
operand->mode = Addressing_Constant;
|
||||
operand->value = make_exact_value_integer(type_offset_of(c->sizes, c->allocator, type, index));
|
||||
operand->type = &basic_types[Basic_int];
|
||||
operand->type = t_int;
|
||||
} break;
|
||||
|
||||
case BuiltinProcedure_static_assert:
|
||||
@@ -1220,7 +1220,7 @@ b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id)
|
||||
}
|
||||
|
||||
operand->mode = mode;
|
||||
operand->type = &basic_types[Basic_int];
|
||||
operand->type = t_int;
|
||||
operand->value = value;
|
||||
|
||||
} break;
|
||||
@@ -1262,7 +1262,7 @@ b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id)
|
||||
return false;
|
||||
}
|
||||
|
||||
operand->type = &basic_types[Basic_int]; // Returns number of elements copied
|
||||
operand->type = t_int; // Returns number of elements copied
|
||||
operand->mode = Addressing_Value;
|
||||
} break;
|
||||
|
||||
@@ -1507,7 +1507,7 @@ ExpressionKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *typ
|
||||
ExpressionKind kind = Expression_Statement;
|
||||
|
||||
o->mode = Addressing_Invalid;
|
||||
o->type = &basic_types[Basic_Invalid];
|
||||
o->type = t_invalid;
|
||||
|
||||
switch (node->kind) {
|
||||
case_ast_node(be, BadExpr, node)
|
||||
@@ -1519,16 +1519,16 @@ ExpressionKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *typ
|
||||
case_end;
|
||||
|
||||
case_ast_node(bl, BasicLit, node);
|
||||
BasicKind basic_kind = Basic_Invalid;
|
||||
Type *t = t_invalid;
|
||||
switch (bl->kind) {
|
||||
case Token_Integer: basic_kind = Basic_UntypedInteger; break;
|
||||
case Token_Float: basic_kind = Basic_UntypedFloat; break;
|
||||
case Token_String: basic_kind = Basic_UntypedString; break;
|
||||
case Token_Rune: basic_kind = Basic_UntypedRune; break;
|
||||
case Token_Integer: t = t_untyped_integer; break;
|
||||
case Token_Float: t = t_untyped_float; break;
|
||||
case Token_String: t = t_untyped_string; break;
|
||||
case Token_Rune: t = t_untyped_rune; break;
|
||||
default: GB_PANIC("Unknown literal"); break;
|
||||
}
|
||||
o->mode = Addressing_Constant;
|
||||
o->type = &basic_types[basic_kind];
|
||||
o->type = t;
|
||||
o->value = make_exact_value_from_basic_literal(*bl);
|
||||
case_end;
|
||||
|
||||
@@ -1684,7 +1684,7 @@ ExpressionKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *typ
|
||||
max_count = o->value.value_string.len;
|
||||
}
|
||||
o->mode = Addressing_Value;
|
||||
o->type = &basic_types[Basic_u8];
|
||||
o->type = t_u8;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1866,7 +1866,7 @@ ExpressionKind check_expr_base(Checker *c, Operand *o, AstNode *node, Type *type
|
||||
ExactValue value = {ExactValue_Invalid};
|
||||
switch (o->mode) {
|
||||
case Addressing_Invalid:
|
||||
type = &basic_types[Basic_Invalid];
|
||||
type = t_invalid;
|
||||
break;
|
||||
case Addressing_NoValue:
|
||||
type = NULL;
|
||||
|
||||
+18
-18
@@ -73,7 +73,7 @@ b32 check_is_terminating(Checker *c, AstNode *node) {
|
||||
|
||||
b32 check_is_assignable_to(Checker *c, Operand *operand, Type *type) {
|
||||
if (operand->mode == Addressing_Invalid ||
|
||||
type == &basic_types[Basic_Invalid]) {
|
||||
type == t_invalid) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ void check_assignment(Checker *c, Operand *operand, Type *type, String context_n
|
||||
|
||||
Type *check_assignment_variable(Checker *c, Operand *op_a, AstNode *lhs) {
|
||||
if (op_a->mode == Addressing_Invalid ||
|
||||
op_a->type == &basic_types[Basic_Invalid]) {
|
||||
op_a->type == t_invalid) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -200,7 +200,7 @@ Type *check_assignment_variable(Checker *c, Operand *op_a, AstNode *lhs) {
|
||||
if (e) e->variable.used = used;
|
||||
|
||||
if (op_b.mode == Addressing_Invalid ||
|
||||
op_b.type == &basic_types[Basic_Invalid]) {
|
||||
op_b.type == t_invalid) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -233,10 +233,10 @@ Type *check_assignment_variable(Checker *c, Operand *op_a, AstNode *lhs) {
|
||||
// NOTE(bill): `content_name` is for debugging
|
||||
Type *check_init_variable(Checker *c, Entity *e, Operand *operand, String context_name) {
|
||||
if (operand->mode == Addressing_Invalid ||
|
||||
operand->type == &basic_types[Basic_Invalid] ||
|
||||
e->type == &basic_types[Basic_Invalid]) {
|
||||
operand->type == t_invalid ||
|
||||
e->type == t_invalid) {
|
||||
if (e->type == NULL)
|
||||
e->type = &basic_types[Basic_Invalid];
|
||||
e->type = t_invalid;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -244,9 +244,9 @@ Type *check_init_variable(Checker *c, Entity *e, Operand *operand, String contex
|
||||
// NOTE(bill): Use the type of the operand
|
||||
Type *t = operand->type;
|
||||
if (is_type_untyped(t)) {
|
||||
if (t == &basic_types[Basic_Invalid]) {
|
||||
if (t == t_invalid) {
|
||||
error(&c->error_collector, e->token, "Use of untyped thing in %.*s", LIT(context_name));
|
||||
e->type = &basic_types[Basic_Invalid];
|
||||
e->type = t_invalid;
|
||||
return NULL;
|
||||
}
|
||||
t = default_type(t);
|
||||
@@ -295,10 +295,10 @@ void check_init_variables(Checker *c, Entity **lhs, isize lhs_count, AstNode *in
|
||||
|
||||
void check_init_constant(Checker *c, Entity *e, Operand *operand) {
|
||||
if (operand->mode == Addressing_Invalid ||
|
||||
operand->type == &basic_types[Basic_Invalid] ||
|
||||
e->type == &basic_types[Basic_Invalid]) {
|
||||
operand->type == t_invalid ||
|
||||
e->type == t_invalid) {
|
||||
if (e->type == NULL)
|
||||
e->type = &basic_types[Basic_Invalid];
|
||||
e->type = t_invalid;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -307,7 +307,7 @@ void check_init_constant(Checker *c, Entity *e, Operand *operand) {
|
||||
error(&c->error_collector, ast_node_token(operand->expr),
|
||||
"`%.*s` is not a constant", LIT(ast_node_token(operand->expr).string));
|
||||
if (e->type == NULL)
|
||||
e->type = &basic_types[Basic_Invalid];
|
||||
e->type = t_invalid;
|
||||
return;
|
||||
}
|
||||
if (!is_type_constant_type(operand->type)) {
|
||||
@@ -330,7 +330,7 @@ void check_const_decl(Checker *c, Entity *e, AstNode *type_expr, AstNode *init_e
|
||||
GB_ASSERT(e->type == NULL);
|
||||
|
||||
if (e->variable.visited) {
|
||||
e->type = &basic_types[Basic_Invalid];
|
||||
e->type = t_invalid;
|
||||
return;
|
||||
}
|
||||
e->variable.visited = true;
|
||||
@@ -342,7 +342,7 @@ void check_const_decl(Checker *c, Entity *e, AstNode *type_expr, AstNode *init_e
|
||||
defer (gb_string_free(str));
|
||||
error(&c->error_collector, ast_node_token(type_expr),
|
||||
"Invalid constant type `%s`", str);
|
||||
e->type = &basic_types[Basic_Invalid];
|
||||
e->type = t_invalid;
|
||||
return;
|
||||
}
|
||||
e->type = t;
|
||||
@@ -464,7 +464,7 @@ void check_var_decl(Checker *c, Entity *e, Entity **entities, isize entity_count
|
||||
GB_ASSERT(e->kind == Entity_Variable);
|
||||
|
||||
if (e->variable.visited) {
|
||||
e->type = &basic_types[Basic_Invalid];
|
||||
e->type = t_invalid;
|
||||
return;
|
||||
}
|
||||
e->variable.visited = true;
|
||||
@@ -474,7 +474,7 @@ void check_var_decl(Checker *c, Entity *e, Entity **entities, isize entity_count
|
||||
|
||||
if (init_expr == NULL) {
|
||||
if (type_expr == NULL)
|
||||
e->type = &basic_types[Basic_Invalid];
|
||||
e->type = t_invalid;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -815,14 +815,14 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) {
|
||||
if (vd->type) {
|
||||
init_type = check_type(c, vd->type, NULL);
|
||||
if (init_type == NULL)
|
||||
init_type = &basic_types[Basic_Invalid];
|
||||
init_type = t_invalid;
|
||||
}
|
||||
|
||||
for (isize i = 0; i < entity_count; i++) {
|
||||
Entity *e = entities[i];
|
||||
GB_ASSERT(e != NULL);
|
||||
if (e->variable.visited) {
|
||||
e->type = &basic_types[Basic_Invalid];
|
||||
e->type = t_invalid;
|
||||
continue;
|
||||
}
|
||||
e->variable.visited = true;
|
||||
|
||||
@@ -246,6 +246,29 @@ gb_global Type basic_type_aliases[] = {
|
||||
{Type_Basic, {Basic_rune, BasicFlag_Integer, STR_LIT("rune")}},
|
||||
};
|
||||
|
||||
gb_global Type *t_invalid = &basic_types[Basic_Invalid];
|
||||
gb_global Type *t_bool = &basic_types[Basic_bool];
|
||||
gb_global Type *t_i8 = &basic_types[Basic_i8];
|
||||
gb_global Type *t_i16 = &basic_types[Basic_i16];
|
||||
gb_global Type *t_i32 = &basic_types[Basic_i32];
|
||||
gb_global Type *t_i64 = &basic_types[Basic_i64];
|
||||
gb_global Type *t_u8 = &basic_types[Basic_u8];
|
||||
gb_global Type *t_u16 = &basic_types[Basic_u16];
|
||||
gb_global Type *t_u32 = &basic_types[Basic_u32];
|
||||
gb_global Type *t_u64 = &basic_types[Basic_u64];
|
||||
gb_global Type *t_f32 = &basic_types[Basic_f32];
|
||||
gb_global Type *t_f64 = &basic_types[Basic_f64];
|
||||
gb_global Type *t_int = &basic_types[Basic_int];
|
||||
gb_global Type *t_uint = &basic_types[Basic_uint];
|
||||
gb_global Type *t_rawptr = &basic_types[Basic_rawptr];
|
||||
gb_global Type *t_string = &basic_types[Basic_string];
|
||||
gb_global Type *t_untyped_bool = &basic_types[Basic_UntypedBool];
|
||||
gb_global Type *t_untyped_integer = &basic_types[Basic_UntypedInteger];
|
||||
gb_global Type *t_untyped_float = &basic_types[Basic_UntypedFloat];
|
||||
gb_global Type *t_untyped_pointer = &basic_types[Basic_UntypedPointer];
|
||||
gb_global Type *t_untyped_string = &basic_types[Basic_UntypedString];
|
||||
gb_global Type *t_untyped_rune = &basic_types[Basic_UntypedRune];
|
||||
|
||||
|
||||
b32 is_type_named(Type *t) {
|
||||
if (t->kind == Type_Basic)
|
||||
|
||||
Reference in New Issue
Block a user