Make default calling convention code more correct to read

This commit is contained in:
gingerBill
2021-06-08 14:33:49 +01:00
parent 76bb82a726
commit f19bb0f4d4
5 changed files with 31 additions and 16 deletions

View File

@@ -648,7 +648,7 @@ void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) {
if (d->gen_proc_type != nullptr) {
proc_type = d->gen_proc_type;
} else {
proc_type = alloc_type_proc(e->scope, nullptr, 0, nullptr, 0, false, ProcCC_Odin);
proc_type = alloc_type_proc(e->scope, nullptr, 0, nullptr, 0, false, default_calling_convention());
}
e->type = proc_type;
ast_node(pl, ProcLit, d->proc_lit);
@@ -746,10 +746,10 @@ void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) {
error(e->token, "Procedure type of 'main' was expected to be 'proc()', got %s", str);
gb_string_free(str);
}
if (pt->calling_convention != ProcCC_Odin) {
if (pt->calling_convention != default_calling_convention()) {
error(e->token, "Procedure 'main' cannot have a custom calling convention");
}
pt->calling_convention = ProcCC_Odin;
pt->calling_convention = default_calling_convention();
if (e->pkg->kind == Package_Init) {
if (ctx->info->entry_point != nullptr) {
error(e->token, "Redeclaration of the entry pointer procedure 'main'");

View File

@@ -676,11 +676,17 @@ OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type) {
String calling_convention = {};
switch (type->Proc.calling_convention) {
case ProcCC_Invalid:
case ProcCC_Odin:
// no need
break;
case ProcCC_Odin:
if (default_calling_convention() != ProcCC_Odin) {
calling_convention = str_lit("odin");
}
break;
case ProcCC_Contextless:
calling_convention = str_lit("contextless");
if (default_calling_convention() != ProcCC_Contextless) {
calling_convention = str_lit("contextless");
}
break;
case ProcCC_CDecl:
calling_convention = str_lit("cdecl");

View File

@@ -3232,7 +3232,7 @@ Ast *parse_proc_type(AstFile *f, Token proc_token) {
if (f->in_foreign_block) {
cc = ProcCC_ForeignBlockDefault;
} else {
cc = ProcCC_Odin;
cc = default_calling_convention();
}
}

View File

@@ -208,18 +208,18 @@ enum ProcTag {
ProcTag_optional_second = 1<<6,
};
enum ProcCallingConvention {
ProcCC_Invalid = 0,
ProcCC_Odin = 1,
enum ProcCallingConvention : i32 {
ProcCC_Invalid = 0,
ProcCC_Odin = 1,
ProcCC_Contextless = 2,
ProcCC_CDecl = 3,
ProcCC_StdCall = 4,
ProcCC_FastCall = 5,
ProcCC_CDecl = 3,
ProcCC_StdCall = 4,
ProcCC_FastCall = 5,
ProcCC_None = 6,
ProcCC_Naked = 7,
ProcCC_None = 6,
ProcCC_Naked = 7,
ProcCC_InlineAsm = 8,
ProcCC_InlineAsm = 8,
ProcCC_MAX,
@@ -227,6 +227,10 @@ enum ProcCallingConvention {
ProcCC_ForeignBlockDefault = -1,
};
ProcCallingConvention default_calling_convention(void) {
return ProcCC_Odin;
}
enum StateFlag : u16 {
StateFlag_bounds_check = 1<<0,
StateFlag_no_bounds_check = 1<<1,

View File

@@ -3618,9 +3618,14 @@ gbString write_type_to_string(gbString str, Type *type) {
switch (type->Proc.calling_convention) {
case ProcCC_Odin:
if (default_calling_convention() != ProcCC_Odin) {
str = gb_string_appendc(str, " \"odin\" ");
}
break;
case ProcCC_Contextless:
str = gb_string_appendc(str, " \"contextless\" ");
if (default_calling_convention() != ProcCC_Contextless) {
str = gb_string_appendc(str, " \"contextless\" ");
}
break;
case ProcCC_CDecl:
str = gb_string_appendc(str, " \"cdecl\" ");