mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-02 04:38:16 +00:00
Make default calling convention code more correct to read
This commit is contained in:
+3
-3
@@ -648,7 +648,7 @@ void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) {
|
|||||||
if (d->gen_proc_type != nullptr) {
|
if (d->gen_proc_type != nullptr) {
|
||||||
proc_type = d->gen_proc_type;
|
proc_type = d->gen_proc_type;
|
||||||
} else {
|
} 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;
|
e->type = proc_type;
|
||||||
ast_node(pl, ProcLit, d->proc_lit);
|
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);
|
error(e->token, "Procedure type of 'main' was expected to be 'proc()', got %s", str);
|
||||||
gb_string_free(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");
|
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 (e->pkg->kind == Package_Init) {
|
||||||
if (ctx->info->entry_point != nullptr) {
|
if (ctx->info->entry_point != nullptr) {
|
||||||
error(e->token, "Redeclaration of the entry pointer procedure 'main'");
|
error(e->token, "Redeclaration of the entry pointer procedure 'main'");
|
||||||
|
|||||||
+8
-2
@@ -676,11 +676,17 @@ OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type) {
|
|||||||
String calling_convention = {};
|
String calling_convention = {};
|
||||||
switch (type->Proc.calling_convention) {
|
switch (type->Proc.calling_convention) {
|
||||||
case ProcCC_Invalid:
|
case ProcCC_Invalid:
|
||||||
case ProcCC_Odin:
|
|
||||||
// no need
|
// no need
|
||||||
break;
|
break;
|
||||||
|
case ProcCC_Odin:
|
||||||
|
if (default_calling_convention() != ProcCC_Odin) {
|
||||||
|
calling_convention = str_lit("odin");
|
||||||
|
}
|
||||||
|
break;
|
||||||
case ProcCC_Contextless:
|
case ProcCC_Contextless:
|
||||||
calling_convention = str_lit("contextless");
|
if (default_calling_convention() != ProcCC_Contextless) {
|
||||||
|
calling_convention = str_lit("contextless");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case ProcCC_CDecl:
|
case ProcCC_CDecl:
|
||||||
calling_convention = str_lit("cdecl");
|
calling_convention = str_lit("cdecl");
|
||||||
|
|||||||
+1
-1
@@ -3232,7 +3232,7 @@ Ast *parse_proc_type(AstFile *f, Token proc_token) {
|
|||||||
if (f->in_foreign_block) {
|
if (f->in_foreign_block) {
|
||||||
cc = ProcCC_ForeignBlockDefault;
|
cc = ProcCC_ForeignBlockDefault;
|
||||||
} else {
|
} else {
|
||||||
cc = ProcCC_Odin;
|
cc = default_calling_convention();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
-9
@@ -208,18 +208,18 @@ enum ProcTag {
|
|||||||
ProcTag_optional_second = 1<<6,
|
ProcTag_optional_second = 1<<6,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ProcCallingConvention {
|
enum ProcCallingConvention : i32 {
|
||||||
ProcCC_Invalid = 0,
|
ProcCC_Invalid = 0,
|
||||||
ProcCC_Odin = 1,
|
ProcCC_Odin = 1,
|
||||||
ProcCC_Contextless = 2,
|
ProcCC_Contextless = 2,
|
||||||
ProcCC_CDecl = 3,
|
ProcCC_CDecl = 3,
|
||||||
ProcCC_StdCall = 4,
|
ProcCC_StdCall = 4,
|
||||||
ProcCC_FastCall = 5,
|
ProcCC_FastCall = 5,
|
||||||
|
|
||||||
ProcCC_None = 6,
|
ProcCC_None = 6,
|
||||||
ProcCC_Naked = 7,
|
ProcCC_Naked = 7,
|
||||||
|
|
||||||
ProcCC_InlineAsm = 8,
|
ProcCC_InlineAsm = 8,
|
||||||
|
|
||||||
ProcCC_MAX,
|
ProcCC_MAX,
|
||||||
|
|
||||||
@@ -227,6 +227,10 @@ enum ProcCallingConvention {
|
|||||||
ProcCC_ForeignBlockDefault = -1,
|
ProcCC_ForeignBlockDefault = -1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ProcCallingConvention default_calling_convention(void) {
|
||||||
|
return ProcCC_Odin;
|
||||||
|
}
|
||||||
|
|
||||||
enum StateFlag : u16 {
|
enum StateFlag : u16 {
|
||||||
StateFlag_bounds_check = 1<<0,
|
StateFlag_bounds_check = 1<<0,
|
||||||
StateFlag_no_bounds_check = 1<<1,
|
StateFlag_no_bounds_check = 1<<1,
|
||||||
|
|||||||
+6
-1
@@ -3618,9 +3618,14 @@ gbString write_type_to_string(gbString str, Type *type) {
|
|||||||
|
|
||||||
switch (type->Proc.calling_convention) {
|
switch (type->Proc.calling_convention) {
|
||||||
case ProcCC_Odin:
|
case ProcCC_Odin:
|
||||||
|
if (default_calling_convention() != ProcCC_Odin) {
|
||||||
|
str = gb_string_appendc(str, " \"odin\" ");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case ProcCC_Contextless:
|
case ProcCC_Contextless:
|
||||||
str = gb_string_appendc(str, " \"contextless\" ");
|
if (default_calling_convention() != ProcCC_Contextless) {
|
||||||
|
str = gb_string_appendc(str, " \"contextless\" ");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case ProcCC_CDecl:
|
case ProcCC_CDecl:
|
||||||
str = gb_string_appendc(str, " \"cdecl\" ");
|
str = gb_string_appendc(str, " \"cdecl\" ");
|
||||||
|
|||||||
Reference in New Issue
Block a user