This commit is contained in:
Ginger Bill
2017-08-12 20:04:58 +01:00
3 changed files with 48 additions and 97 deletions

View File

@@ -190,7 +190,7 @@ read :: proc(fd: Handle, data: []u8) -> (int, Errno) {
seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
assert(fd != -1);
final_offset := i64(unix_lseek(fd, offset, whence));
final_offset := i64(unix_lseek(fd, int(offset), whence));
if(final_offset == -1) {
return 0, 1;
}

View File

@@ -1072,6 +1072,40 @@ Entity *make_names_field_for_struct(Checker *c, Scope *scope) {
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) {
GB_ASSERT(is_type_struct(struct_type));
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`");
return;
}
Operand o = {};
check_expr(c, &o, st->align);
if (o.mode != Addressing_Constant) {
if (o.mode != Addressing_Invalid) {
error(st->align, "#align must be a constant");
}
return;
i64 custom_align = 1;
if (check_custom_align(c, st->align, &custom_align)) {
struct_type->Struct.custom_align = custom_align;
}
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) {
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;
if (ut->align != nullptr) {
Operand o = {};
check_expr(c, &o, ut->align);
if (o.mode != Addressing_Constant) {
if (o.mode != Addressing_Invalid) {
error(ut->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(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;
i64 custom_align = 1;
if (check_custom_align(c, ut->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;
}
}
error(ut->align, "#align must be an integer");
return;
}
}
// 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) {
Operand o = {};
check_expr(c, &o, bft->align);
if (o.mode != Addressing_Constant) {
if (o.mode != Addressing_Invalid) {
error(bft->align, "#align must be a constant");
}
return;
i64 custom_align = 1;
if (check_custom_align(c, bft->align, &custom_align)) {
bit_field_type->BitField.custom_align = custom_align;
}
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;
}
}

View File

@@ -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) {
#if defined(GB_SYSTEM_OSX)
return unlink(existing_filename) != -1;
return unlink(filename) != -1;
#else
return remove(filename) == 0;
#endif