mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 23:28:48 +00:00
Merge branch 'master' of https://github.com/gingerBill/Odin
This commit is contained in:
+1
-1
@@ -190,7 +190,7 @@ read :: proc(fd: Handle, data: []u8) -> (int, Errno) {
|
|||||||
seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
|
seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
|
||||||
assert(fd != -1);
|
assert(fd != -1);
|
||||||
|
|
||||||
final_offset := i64(unix_lseek(fd, offset, whence));
|
final_offset := i64(unix_lseek(fd, int(offset), whence));
|
||||||
if(final_offset == -1) {
|
if(final_offset == -1) {
|
||||||
return 0, 1;
|
return 0, 1;
|
||||||
}
|
}
|
||||||
|
|||||||
+46
-95
@@ -1072,6 +1072,40 @@ Entity *make_names_field_for_struct(Checker *c, Scope *scope) {
|
|||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool check_custom_align(Checker *c, AstNode *node, i64 *align_) {
|
||||||
|
GB_ASSERT(align_ != nullptr);
|
||||||
|
Operand o = {};
|
||||||
|
check_expr(c, &o, node);
|
||||||
|
if (o.mode != Addressing_Constant) {
|
||||||
|
if (o.mode != Addressing_Invalid) {
|
||||||
|
error(node, "#align must be a constant");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Type *type = base_type(o.type);
|
||||||
|
if (is_type_untyped(type) || is_type_integer(type)) {
|
||||||
|
if (o.value.kind == ExactValue_Integer) {
|
||||||
|
i64 align = i128_to_i64(o.value.value_integer);
|
||||||
|
if (align < 1 || !gb_is_power_of_two(align)) {
|
||||||
|
error(node, "#align must be a power of 2, got %lld", align);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE(bill): Success!!!
|
||||||
|
i64 custom_align = gb_clamp(align, 1, build_context.max_align);
|
||||||
|
if (custom_align < align) {
|
||||||
|
warning(node, "Custom alignment has been clamped to %lld from %lld", align, custom_align);
|
||||||
|
}
|
||||||
|
*align_ = custom_align;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
error(node, "#align must be an integer");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void check_struct_type(Checker *c, Type *struct_type, AstNode *node, Array<Operand> *poly_operands) {
|
void check_struct_type(Checker *c, Type *struct_type, AstNode *node, Array<Operand> *poly_operands) {
|
||||||
GB_ASSERT(is_type_struct(struct_type));
|
GB_ASSERT(is_type_struct(struct_type));
|
||||||
ast_node(st, StructType, node);
|
ast_node(st, StructType, node);
|
||||||
@@ -1294,40 +1328,11 @@ void check_struct_type(Checker *c, Type *struct_type, AstNode *node, Array<Opera
|
|||||||
syntax_error(st->align, "`#align` cannot be applied with `#packed`");
|
syntax_error(st->align, "`#align` cannot be applied with `#packed`");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
i64 custom_align = 1;
|
||||||
Operand o = {};
|
if (check_custom_align(c, st->align, &custom_align)) {
|
||||||
check_expr(c, &o, st->align);
|
struct_type->Struct.custom_align = custom_align;
|
||||||
if (o.mode != Addressing_Constant) {
|
|
||||||
if (o.mode != Addressing_Invalid) {
|
|
||||||
error(st->align, "#align must be a constant");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Type *type = base_type(o.type);
|
|
||||||
if (is_type_untyped(type) || is_type_integer(type)) {
|
|
||||||
if (o.value.kind == ExactValue_Integer) {
|
|
||||||
i64 align = i128_to_i64(o.value.value_integer);
|
|
||||||
if (align < 1 || !gb_is_power_of_two(align)) {
|
|
||||||
error(st->align, "#align must be a power of 2, got %lld", align);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE(bill): Success!!!
|
|
||||||
i64 custom_align = gb_clamp(align, 1, build_context.max_align);
|
|
||||||
if (custom_align < align) {
|
|
||||||
warning(st->align, "Custom alignment has been clamped to %lld from %lld", align, custom_align);
|
|
||||||
}
|
|
||||||
struct_type->Struct.custom_align = custom_align;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
error(st->align, "#align must be an integer");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
void check_union_type(Checker *c, Type *union_type, AstNode *node) {
|
void check_union_type(Checker *c, Type *union_type, AstNode *node) {
|
||||||
GB_ASSERT(is_type_union(union_type));
|
GB_ASSERT(is_type_union(union_type));
|
||||||
@@ -1376,43 +1381,15 @@ void check_union_type(Checker *c, Type *union_type, AstNode *node) {
|
|||||||
union_type->Union.variants = variants;
|
union_type->Union.variants = variants;
|
||||||
|
|
||||||
if (ut->align != nullptr) {
|
if (ut->align != nullptr) {
|
||||||
Operand o = {};
|
i64 custom_align = 1;
|
||||||
check_expr(c, &o, ut->align);
|
if (check_custom_align(c, ut->align, &custom_align)) {
|
||||||
if (o.mode != Addressing_Constant) {
|
if (variants.count == 0) {
|
||||||
if (o.mode != Addressing_Invalid) {
|
error(ut->align, "An empty union cannot have a custom alignment");
|
||||||
error(ut->align, "#align must be a constant");
|
} else {
|
||||||
}
|
union_type->Union.custom_align = custom_align;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Type *type = base_type(o.type);
|
|
||||||
if (is_type_untyped(type) || is_type_integer(type)) {
|
|
||||||
if (o.value.kind == ExactValue_Integer) {
|
|
||||||
i64 align = i128_to_i64(o.value.value_integer);
|
|
||||||
if (align < 1 || !gb_is_power_of_two(align)) {
|
|
||||||
error(ut->align, "#align must be a power of 2, got %lld", align);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE(bill): Success!!!
|
|
||||||
i64 custom_align = gb_clamp(align, 1, build_context.max_align);
|
|
||||||
if (custom_align < align) {
|
|
||||||
warning(ut->align, "Custom alignment has been clamped to %lld from %lld", align, custom_align);
|
|
||||||
}
|
|
||||||
if (variants.count == 0) {
|
|
||||||
error(ut->align, "An empty union cannot have a custom alignment");
|
|
||||||
} else {
|
|
||||||
union_type->Union.custom_align = custom_align;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
error(ut->align, "#align must be an integer");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// void check_raw_union_type(Checker *c, Type *union_type, AstNode *node) {
|
// void check_raw_union_type(Checker *c, Type *union_type, AstNode *node) {
|
||||||
@@ -1653,36 +1630,10 @@ void check_bit_field_type(Checker *c, Type *bit_field_type, AstNode *node) {
|
|||||||
|
|
||||||
|
|
||||||
if (bft->align != nullptr) {
|
if (bft->align != nullptr) {
|
||||||
Operand o = {};
|
i64 custom_align = 1;
|
||||||
check_expr(c, &o, bft->align);
|
if (check_custom_align(c, bft->align, &custom_align)) {
|
||||||
if (o.mode != Addressing_Constant) {
|
bit_field_type->BitField.custom_align = custom_align;
|
||||||
if (o.mode != Addressing_Invalid) {
|
|
||||||
error(bft->align, "#align must be a constant");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Type *type = base_type(o.type);
|
|
||||||
if (is_type_untyped(type) || is_type_integer(type)) {
|
|
||||||
if (o.value.kind == ExactValue_Integer) {
|
|
||||||
i64 align = i128_to_i64(o.value.value_integer);
|
|
||||||
if (align < 1 || !gb_is_power_of_two(align)) {
|
|
||||||
error(bft->align, "#align must be a power of 2, got %lld", align);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE(bill): Success!!!
|
|
||||||
i64 custom_align = gb_clamp(align, 1, build_context.max_align);
|
|
||||||
if (custom_align < align) {
|
|
||||||
warning(bft->align, "Custom alignment has been clamped to %lld from %lld", align, custom_align);
|
|
||||||
}
|
|
||||||
bit_field_type->BitField.custom_align = custom_align;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
error(bft->align, "#align must be an integer");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -7991,7 +7991,7 @@ gb_inline b32 gb_file_move(char const *existing_filename, char const *new_filena
|
|||||||
|
|
||||||
b32 gb_file_remove(char const *filename) {
|
b32 gb_file_remove(char const *filename) {
|
||||||
#if defined(GB_SYSTEM_OSX)
|
#if defined(GB_SYSTEM_OSX)
|
||||||
return unlink(existing_filename) != -1;
|
return unlink(filename) != -1;
|
||||||
#else
|
#else
|
||||||
return remove(filename) == 0;
|
return remove(filename) == 0;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user