Core: Fix casting from array to pointer of same base, improve errors
This commit is contained in:
@@ -52,12 +52,6 @@ Add(&guys, {100, 100})
|
|||||||
// This generates: int MAP[256] = (int [256]){[0] = 0, [0] = 1}; it doesn't work because of the (int[256]) is this MSVC being retarded here? not supporting C properly?
|
// This generates: int MAP[256] = (int [256]){[0] = 0, [0] = 1}; it doesn't work because of the (int[256]) is this MSVC being retarded here? not supporting C properly?
|
||||||
// Also this ^ ^
|
// Also this ^ ^
|
||||||
|
|
||||||
// @reproduction
|
|
||||||
// map_data: [16*16]int
|
|
||||||
// map: Map = {data = map_data->*int, 16, 16}
|
|
||||||
//
|
|
||||||
// Failed to cast from [[256]int] to [*int]
|
|
||||||
|
|
||||||
|
|
||||||
#import "raylib.core"
|
#import "raylib.core"
|
||||||
#load "array.core"
|
#load "array.core"
|
||||||
@@ -93,6 +87,7 @@ MouseSelectedActors: Array(*MAP.Actor) // @todo: ids
|
|||||||
main :: (): int
|
main :: (): int
|
||||||
MAP.Init()
|
MAP.Init()
|
||||||
|
|
||||||
|
|
||||||
// InitAudioDevice()
|
// InitAudioDevice()
|
||||||
// sound := LoadSound("catune - Pass the town, and to the C.mp3")
|
// sound := LoadSound("catune - Pass the town, and to the C.mp3")
|
||||||
// SetMasterVolume(0.01)
|
// SetMasterVolume(0.01)
|
||||||
|
|||||||
@@ -27,10 +27,16 @@ static void core_log_trace(int line, const char *file, const char *str, ...) {
|
|||||||
String core_stringify_message(Core_Ctx *pctx, Allocator *allocator, Core_Message *msg, int color_codes_enabled = false) {
|
String core_stringify_message(Core_Ctx *pctx, Allocator *allocator, Core_Message *msg, int color_codes_enabled = false) {
|
||||||
String_Builder &b = pctx->helper_builder;
|
String_Builder &b = pctx->helper_builder;
|
||||||
|
|
||||||
if (msg->kind == CORE_ERROR) b.addf("Error! ");
|
for (S64 i = 0; i < buff_cap(msg->tokens); i += 1) {
|
||||||
else if (msg->kind == CORE_WARNING) b.addf("Warning! ");
|
Token *it = msg->tokens[i];
|
||||||
else if (msg->kind == CORE_TRACE) b.addf("Trace: ");
|
if (it) {
|
||||||
else invalid_codepath;
|
b.addf("\n%s(%d): ", it->file.str, (S64)it->line + 1);
|
||||||
|
if (msg->kind == CORE_ERROR) b.addf("error ");
|
||||||
|
else if (msg->kind == CORE_WARNING) b.addf("warning ");
|
||||||
|
else if (msg->kind == CORE_TRACE) b.addf("trace ");
|
||||||
|
else invalid_codepath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < buff_cap(msg->tokens); i += 1) {
|
for (int i = 0; i < buff_cap(msg->tokens); i += 1) {
|
||||||
Token *it = msg->tokens[i];
|
Token *it = msg->tokens[i];
|
||||||
@@ -67,13 +73,6 @@ String core_stringify_message(Core_Ctx *pctx, Allocator *allocator, Core_Message
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (S64 i = 0; i < buff_cap(msg->tokens); i += 1) {
|
|
||||||
Token *it = msg->tokens[i];
|
|
||||||
if (it) {
|
|
||||||
b.addf("\n%s(%d): error", it->file.str, (S64)it->line + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String result = string_flatten(allocator, &b);
|
String result = string_flatten(allocator, &b);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -975,6 +975,14 @@ resolve_cast(Ast_Binary *node) {
|
|||||||
expr.type = type;
|
expr.type = type;
|
||||||
else goto failure;
|
else goto failure;
|
||||||
} break;
|
} break;
|
||||||
|
case TYPE_ARRAY: {
|
||||||
|
Ast_Type *array_base = expr.type->base;
|
||||||
|
Ast_Type *pointer_base = type_pointer(array_base);
|
||||||
|
if (pointer_base == type) {
|
||||||
|
expr.type = pointer_base;
|
||||||
|
}
|
||||||
|
else goto failure;
|
||||||
|
} break;
|
||||||
case TYPE_POINTER: {
|
case TYPE_POINTER: {
|
||||||
if (is_pointer(type))
|
if (is_pointer(type))
|
||||||
expr = operand_rvalue(type);
|
expr = operand_rvalue(type);
|
||||||
@@ -1061,8 +1069,7 @@ resolve_compound_array(Ast_Call *node, Ast_Type *type) {
|
|||||||
|
|
||||||
CORE_Static void
|
CORE_Static void
|
||||||
resolve_compound_struct(Ast_Call *node, Ast_Type *type) {
|
resolve_compound_struct(Ast_Call *node, Ast_Type *type) {
|
||||||
if (node->exprs.len != 1 && is_union(type))
|
if (node->exprs.len != 1 && is_union(type)) compiler_error(node->pos, "Too many union initializers. Only 1 named initializer required.");
|
||||||
compiler_error(node->pos, "Too many union initializers. Only 1 named initializer required.");
|
|
||||||
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
bool named_field_appeared = false;
|
bool named_field_appeared = false;
|
||||||
@@ -1075,7 +1082,7 @@ resolve_compound_struct(Ast_Call *node, Ast_Type *type) {
|
|||||||
counter += 1;
|
counter += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
S64 default_counter = 0;
|
int default_counter = 0;
|
||||||
For(node->exprs) {
|
For(node->exprs) {
|
||||||
Ast_Type *item_type = 0;
|
Ast_Type *item_type = 0;
|
||||||
if (is_flag_set(it->call_flags, CALL_NAME)) {
|
if (is_flag_set(it->call_flags, CALL_NAME)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user