Fix #strict regression, adding Any and Type_Info
This commit is contained in:
@@ -641,6 +641,7 @@ function void
|
|||||||
insert_builtin_into_scope(Ast_Scope *p, String name, Ast_Type *type){
|
insert_builtin_into_scope(Ast_Scope *p, String name, Ast_Type *type){
|
||||||
Intern_String string = pctx->intern(name);
|
Intern_String string = pctx->intern(name);
|
||||||
Ast_Decl *decl = ast_type(0, string, type);
|
Ast_Decl *decl = ast_type(0, string, type);
|
||||||
|
type->type_id = pctx->type_ids++;
|
||||||
decl->parent_scope = p;
|
decl->parent_scope = p;
|
||||||
decl->state = DECL_RESOLVED;
|
decl->state = DECL_RESOLVED;
|
||||||
insert_into_scope(p, decl);
|
insert_into_scope(p, decl);
|
||||||
@@ -663,6 +664,7 @@ insert_builtin_types_into_scope(Ast_Scope *p){
|
|||||||
insert_builtin_into_scope(p, "U64"_s, type_u64);
|
insert_builtin_into_scope(p, "U64"_s, type_u64);
|
||||||
insert_builtin_into_scope(p, "F32"_s, type_f32);
|
insert_builtin_into_scope(p, "F32"_s, type_f32);
|
||||||
insert_builtin_into_scope(p, "F64"_s, type_f64);
|
insert_builtin_into_scope(p, "F64"_s, type_f64);
|
||||||
|
insert_builtin_into_scope(p, "Any"_s, type_any);
|
||||||
}
|
}
|
||||||
|
|
||||||
global F64 parsing_time_begin;
|
global F64 parsing_time_begin;
|
||||||
|
|||||||
@@ -734,10 +734,10 @@ parse_decl(B32 is_global){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ast_Flag flags = 0;
|
||||||
Token *tname = token_get();
|
Token *tname = token_get();
|
||||||
if(token_match(TK_Identifier, TK_DoubleColon)){
|
if(token_match(TK_Identifier, TK_DoubleColon)){
|
||||||
|
|
||||||
Ast_Flag flags = 0;
|
|
||||||
if(token_match_pound(intern_foreign)){
|
if(token_match_pound(intern_foreign)){
|
||||||
set_flag(flags, AST_FOREIGN);
|
set_flag(flags, AST_FOREIGN);
|
||||||
} else if(token_match_pound(intern_strict)){
|
} else if(token_match_pound(intern_strict)){
|
||||||
@@ -794,6 +794,7 @@ parse_decl(B32 is_global){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(result){
|
if(result){
|
||||||
|
set_flag(result->flags, flags);
|
||||||
result->name = tname->intern_val;
|
result->name = tname->intern_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
Os :: #import "os_windows.kl"
|
Os :: #import "os_windows.kl"
|
||||||
SizeU :: #strict U64
|
SizeU :: U64
|
||||||
arena_di: U64
|
arena_di: U64
|
||||||
|
|
||||||
Arena :: struct
|
Arena :: struct
|
||||||
|
|||||||
@@ -14,6 +14,59 @@ Windows_Bitmap :: struct
|
|||||||
hdc: HDC
|
hdc: HDC
|
||||||
dib: HBITMAP
|
dib: HBITMAP
|
||||||
|
|
||||||
|
Type_ID :: U64
|
||||||
|
Type_Info_Kind :: enum
|
||||||
|
TYPE_NONE
|
||||||
|
TYPE_S64 // FIRST_NUMERIC
|
||||||
|
TYPE_S32
|
||||||
|
TYPE_S16
|
||||||
|
TYPE_S8
|
||||||
|
TYPE_INT
|
||||||
|
TYPE_CHAR
|
||||||
|
TYPE_U64
|
||||||
|
TYPE_U32
|
||||||
|
TYPE_U16
|
||||||
|
TYPE_U8
|
||||||
|
TYPE_F32
|
||||||
|
TYPE_F64
|
||||||
|
TYPE_POINTER
|
||||||
|
TYPE_BOOL // LAST_NUMERIC
|
||||||
|
TYPE_STRING
|
||||||
|
TYPE_VOID
|
||||||
|
TYPE_ARRAY
|
||||||
|
TYPE_LAMBDA
|
||||||
|
TYPE_STRUCT
|
||||||
|
TYPE_UNION
|
||||||
|
TYPE_ENUM
|
||||||
|
TYPE_TYPE
|
||||||
|
TYPE_SLICE
|
||||||
|
TYPE_TUPLE
|
||||||
|
TYPE_ANY
|
||||||
|
|
||||||
|
Any :: struct
|
||||||
|
data: *void
|
||||||
|
type: Type_ID
|
||||||
|
|
||||||
|
Type_Info_Struct_Field :: struct
|
||||||
|
name: String
|
||||||
|
type: Type_ID
|
||||||
|
offset: S32
|
||||||
|
|
||||||
|
Type_Info :: struct
|
||||||
|
kind: Type_Info_Kind
|
||||||
|
size: S32
|
||||||
|
align: S32
|
||||||
|
is_unsigned: Bool
|
||||||
|
type_id: Type_ID
|
||||||
|
|
||||||
|
base_type: Type_ID
|
||||||
|
array_size: S32
|
||||||
|
struct_member_count: S32
|
||||||
|
fields: *Type_Info_Struct_Field
|
||||||
|
|
||||||
|
type_infos: []*Type_Info
|
||||||
|
|
||||||
|
|
||||||
Bitmap :: struct
|
Bitmap :: struct
|
||||||
size: Vec2I
|
size: Vec2I
|
||||||
data: *U32
|
data: *U32
|
||||||
|
|||||||
43
types.h
43
types.h
@@ -33,6 +33,7 @@ enum Ast_Type_Kind{
|
|||||||
TYPE_TYPE,
|
TYPE_TYPE,
|
||||||
TYPE_SLICE,
|
TYPE_SLICE,
|
||||||
TYPE_TUPLE,
|
TYPE_TUPLE,
|
||||||
|
TYPE_ANY,
|
||||||
|
|
||||||
TYPE_UNTYPED_FIRST = TYPE_UNTYPED_BOOL,
|
TYPE_UNTYPED_FIRST = TYPE_UNTYPED_BOOL,
|
||||||
TYPE_UNTYPED_LAST = TYPE_UNTYPED_STRING,
|
TYPE_UNTYPED_LAST = TYPE_UNTYPED_STRING,
|
||||||
@@ -103,45 +104,6 @@ struct Ast_Type{
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
function const char *
|
|
||||||
docname(Ast_Type *type){
|
|
||||||
switch(type->kind){
|
|
||||||
case TYPE_NONE: return "[Invalid Ast_Type]";
|
|
||||||
case TYPE_COMPLETING: return "[Completing]";
|
|
||||||
case TYPE_INCOMPLETE: return "[Incomplete]";
|
|
||||||
case TYPE_UNTYPED_BOOL: return "[Untyped_Bool]";
|
|
||||||
case TYPE_UNTYPED_INT: return "[Untyped_Int]";
|
|
||||||
case TYPE_UNTYPED_FLOAT: return "[Untyped_Float]";
|
|
||||||
case TYPE_UNTYPED_STRING: return "[Untyped_String]";
|
|
||||||
case TYPE_S64: return "[S64]";
|
|
||||||
case TYPE_S32: return "[S32]";
|
|
||||||
case TYPE_S16: return "[S16]";
|
|
||||||
case TYPE_S8: return "[S8]";
|
|
||||||
case TYPE_U64: return "[U64]";
|
|
||||||
case TYPE_U32: return "[U32]";
|
|
||||||
case TYPE_U16: return "[U16]";
|
|
||||||
case TYPE_U8: return "[U8]";
|
|
||||||
case TYPE_F32: return "[Float32]";
|
|
||||||
case TYPE_F64: return "[Float64]";
|
|
||||||
case TYPE_BOOL: return "[Bool]";
|
|
||||||
case TYPE_STRING: return "[String]";
|
|
||||||
case TYPE_CHAR: return "[char]";
|
|
||||||
case TYPE_INT: return "[int]";
|
|
||||||
case TYPE_VOID: return "[void]";
|
|
||||||
case TYPE_POINTER: return "[Pointer]";
|
|
||||||
case TYPE_ARRAY: return "[Array]";
|
|
||||||
case TYPE_LAMBDA: return "[Lambda]";
|
|
||||||
case TYPE_STRUCT: return "[Struct]";
|
|
||||||
case TYPE_UNION: return "[Union]";
|
|
||||||
case TYPE_ENUM: return "[Enum]";
|
|
||||||
case TYPE_TYPE: return "[Type]";
|
|
||||||
case TYPE_SLICE: return "[Slice]";
|
|
||||||
case TYPE_TUPLE: return "[Tuple]";
|
|
||||||
invalid_default_case;
|
|
||||||
}
|
|
||||||
return "<Unknown_Type>";
|
|
||||||
}
|
|
||||||
|
|
||||||
function const char *
|
function const char *
|
||||||
name(Ast_Type *type){
|
name(Ast_Type *type){
|
||||||
switch(type->kind){
|
switch(type->kind){
|
||||||
@@ -174,6 +136,7 @@ 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};
|
||||||
|
global Ast_Type type__any = {TYPE_ANY};
|
||||||
|
|
||||||
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)};
|
||||||
@@ -201,6 +164,7 @@ global Ast_Type *type_pointer_to_char; // Needs to be inited at runtime
|
|||||||
global Ast_Type *type_void = &type__void;
|
global Ast_Type *type_void = &type__void;
|
||||||
global Ast_Type *type_pointer_to_void; // Needs to be inited at runtime
|
global Ast_Type *type_pointer_to_void; // Needs to be inited at runtime
|
||||||
|
|
||||||
|
global Ast_Type *type_any = &type__any;
|
||||||
global Ast_Type *type_type = &type__type;
|
global Ast_Type *type_type = &type__type;
|
||||||
global Ast_Type *type_string = &type__string;
|
global Ast_Type *type_string = &type__string;
|
||||||
global Ast_Type *type_bool = &type__bool;
|
global Ast_Type *type_bool = &type__bool;
|
||||||
@@ -226,6 +190,7 @@ global Ast_Type *untyped_float = &type__untyped_float;
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Type constructors and utillities
|
// Type constructors and utillities
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
force_inline B32 is_any(Ast_Type *a){return a->kind == TYPE_ANY;}
|
||||||
force_inline B32 is_struct(Ast_Type *a){return a->kind == TYPE_STRUCT;}
|
force_inline B32 is_struct(Ast_Type *a){return a->kind == TYPE_STRUCT;}
|
||||||
force_inline B32 is_lambda(Ast_Type *a){return a->kind == TYPE_LAMBDA;}
|
force_inline B32 is_lambda(Ast_Type *a){return a->kind == TYPE_LAMBDA;}
|
||||||
force_inline B32 is_array(Ast_Type *a){return a->kind == TYPE_ARRAY;}
|
force_inline B32 is_array(Ast_Type *a){return a->kind == TYPE_ARRAY;}
|
||||||
|
|||||||
Reference in New Issue
Block a user