We got type sizing, it matches the C compiler for windows struct, we got
a real compiler on our hands
This commit is contained in:
1
base.cpp
1
base.cpp
@@ -21,6 +21,7 @@ typedef S64 SizeS;
|
|||||||
typedef float F32;
|
typedef float F32;
|
||||||
typedef double F64;
|
typedef double F64;
|
||||||
|
|
||||||
|
|
||||||
#define U64MAX UINT64_MAX
|
#define U64MAX UINT64_MAX
|
||||||
#define U32MAX UINT32_MAX
|
#define U32MAX UINT32_MAX
|
||||||
#define U16MAX UINT16_MAX
|
#define U16MAX UINT16_MAX
|
||||||
|
|||||||
@@ -1234,6 +1234,11 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_context){
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ast_Type *type = name.type == type_type ? name.type_val : name.type;
|
Ast_Type *type = name.type == type_type ? name.type_val : name.type;
|
||||||
|
type_complete(type);
|
||||||
|
if(type->size == 0){
|
||||||
|
compiler_error(node->pos, "Internal compiler error: calling SizeOf but the resulting size of type is obviously invalid suggesting that type was not completed properly");
|
||||||
|
}
|
||||||
|
|
||||||
Value v = value_int(type->size);
|
Value v = value_int(type->size);
|
||||||
rewrite_into_const(node, Ast_Builtin, v);
|
rewrite_into_const(node, Ast_Builtin, v);
|
||||||
return operand_const_rvalue(v);
|
return operand_const_rvalue(v);
|
||||||
@@ -1265,8 +1270,16 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_context){
|
|||||||
Ast_Expr *expr = unpack_ast_call_expr_for_builtin(node);
|
Ast_Expr *expr = unpack_ast_call_expr_for_builtin(node);
|
||||||
Operand name = resolve_expr(expr, inherit_flag(flags, AST_CANT_BE_NULL));
|
Operand name = resolve_expr(expr, inherit_flag(flags, AST_CANT_BE_NULL));
|
||||||
node->kind = AST_ALIGN_OF;
|
node->kind = AST_ALIGN_OF;
|
||||||
if(!name.is_const) compiler_error(node->pos, "AlignOf requires a constant value");
|
if(!name.is_const) {
|
||||||
|
compiler_error(node->pos, "AlignOf requires a constant value");
|
||||||
|
}
|
||||||
|
|
||||||
Ast_Type *type = name.type == type_type ? name.type_val : name.type;
|
Ast_Type *type = name.type == type_type ? name.type_val : name.type;
|
||||||
|
type_complete(type);
|
||||||
|
if(type->size == 0){
|
||||||
|
compiler_error(node->pos, "Internal compiler error: calling SizeOf but the resulting size of type is obviously invalid suggesting that type was not completed properly");
|
||||||
|
}
|
||||||
|
|
||||||
Value v = value_int(type->align);
|
Value v = value_int(type->align);
|
||||||
rewrite_into_const(node, Ast_Builtin, v);
|
rewrite_into_const(node, Ast_Builtin, v);
|
||||||
return operand_const_rvalue(v);
|
return operand_const_rvalue(v);
|
||||||
|
|||||||
@@ -261,21 +261,33 @@ type_incomplete(Ast *ast){
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function void type_complete(Ast_Type *type);
|
||||||
function void
|
function void
|
||||||
type_struct_complete(Ast_Type *type, Ast_Decl *node){
|
type_struct_complete(Ast_Type *type, Ast_Decl *node){
|
||||||
assert(node->kind == AST_STRUCT);
|
assert(node->kind == AST_STRUCT);
|
||||||
// @todo: compute size, alignement, offset !!!
|
// @todo: compute size, alignement, offset !!!
|
||||||
// @note: resolve all the struct members first
|
// @note: resolve all the struct members first
|
||||||
type->kind = TYPE_COMPLETING;
|
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
Array<Ast_Resolved_Member> members = {scratch};
|
Array<Ast_Resolved_Member> members = {scratch};
|
||||||
|
type->kind = TYPE_COMPLETING;
|
||||||
|
size_t members_size = 0;
|
||||||
For(node->scope->decls){
|
For(node->scope->decls){
|
||||||
resolve_decl(it);
|
resolve_decl(it);
|
||||||
|
assert(it->type->kind != TYPE_INCOMPLETE);
|
||||||
|
assert(is_pow2(it->type->align));
|
||||||
|
|
||||||
Ast_Resolved_Member m = {};
|
Ast_Resolved_Member m = {};
|
||||||
|
m.offset = type->size;
|
||||||
|
members_size += it->type->size;
|
||||||
|
type->align = max(type->align, it->type->align);
|
||||||
|
type->size = it->type->size + align_up(type->size, it->type->align);
|
||||||
|
|
||||||
m.name = it->name;
|
m.name = it->name;
|
||||||
m.value = it->value;
|
m.value = it->value;
|
||||||
members.add(m);
|
members.add(m);
|
||||||
}
|
}
|
||||||
|
type->size = align_up(type->size, type->align);
|
||||||
|
type->padding = type->size - members_size;
|
||||||
type->agg.members = members.tight_copy(pctx->perm);
|
type->agg.members = members.tight_copy(pctx->perm);
|
||||||
type->kind = TYPE_STRUCT;
|
type->kind = TYPE_STRUCT;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ union{ \
|
|||||||
Ast_Type *type_val; \
|
Ast_Type *type_val; \
|
||||||
};
|
};
|
||||||
#define INLINE_VALUE_FIELDS union{Value value; struct{VALUE_FIELDS};}
|
#define INLINE_VALUE_FIELDS union{Value value; struct{VALUE_FIELDS};}
|
||||||
|
#define ARRAY_SIZE_SLICE (-1)
|
||||||
struct Value{VALUE_FIELDS};
|
struct Value{VALUE_FIELDS};
|
||||||
|
|
||||||
struct Ast;
|
struct Ast;
|
||||||
@@ -74,13 +75,13 @@ struct Ast_Resolved_Member{
|
|||||||
INLINE_VALUE_FIELDS;
|
INLINE_VALUE_FIELDS;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define ARRAY_SIZE_SLICE (-1)
|
|
||||||
struct Ast_Type{
|
struct Ast_Type{
|
||||||
Ast_Type_Kind kind;
|
Ast_Type_Kind kind;
|
||||||
S32 size;
|
S32 size;
|
||||||
S32 align;
|
S32 align;
|
||||||
S32 is_unsigned;
|
S32 is_unsigned;
|
||||||
S32 type_id;
|
S32 type_id;
|
||||||
|
S32 padding;
|
||||||
|
|
||||||
Ast *ast;
|
Ast *ast;
|
||||||
union{
|
union{
|
||||||
@@ -137,7 +138,7 @@ const SizeU pointer_align = __alignof(SizeU);
|
|||||||
global Ast_Type type__void = {TYPE_VOID};
|
global Ast_Type type__void = {TYPE_VOID};
|
||||||
global Ast_Type type__string = {TYPE_STRING, sizeof(String), __alignof(String)};
|
global Ast_Type type__string = {TYPE_STRING, sizeof(String), __alignof(String)};
|
||||||
global Ast_Type type__bool = {TYPE_BOOL, sizeof(bool), __alignof(bool)};
|
global Ast_Type type__bool = {TYPE_BOOL, sizeof(bool), __alignof(bool)};
|
||||||
global Ast_Type type__type = {TYPE_TYPE};
|
global Ast_Type type__type = {TYPE_TYPE, sizeof(U32), __alignof(U32)};
|
||||||
|
|
||||||
global Ast_Type type__f32 = {TYPE_F32, sizeof(F32), __alignof(F32)};
|
global Ast_Type type__f32 = {TYPE_F32, sizeof(F32), __alignof(F32)};
|
||||||
global Ast_Type type__f64 = {TYPE_F64, sizeof(F64), __alignof(F64)};
|
global Ast_Type type__f64 = {TYPE_F64, sizeof(F64), __alignof(F64)};
|
||||||
|
|||||||
@@ -24,9 +24,11 @@ CreateBitmap :: (size: Vec2I, bottom_up: Bool = true): Windows_Bitmap
|
|||||||
if bottom_up == false
|
if bottom_up == false
|
||||||
result.size.y = -result.size.y
|
result.size.y = -result.size.y
|
||||||
|
|
||||||
|
header_size: U32 = SizeOf(BITMAPINFOHEADER)
|
||||||
|
Assert(header_size == 40)
|
||||||
bminfo := BITMAPINFO{
|
bminfo := BITMAPINFO{
|
||||||
BITMAPINFOHEADER{
|
BITMAPINFOHEADER{
|
||||||
biSize = 40, // @todo!!! SizeOf(BITMAPINFOHEADER),
|
biSize = header_size,
|
||||||
biWidth = size.x->LONG,
|
biWidth = size.x->LONG,
|
||||||
biHeight = size.y->LONG,
|
biHeight = size.y->LONG,
|
||||||
biPlanes = 1,
|
biPlanes = 1,
|
||||||
|
|||||||
Reference in New Issue
Block a user