cgen: add callconv support for fns from ptr (#14151)

fleur 2022-04-25 07:51:03 +02:00 committed by Jef Roosens
parent cde15abc0a
commit 2134fb3e3e
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
1 changed files with 23 additions and 2 deletions

View File

@ -314,11 +314,32 @@ fn (mut g Gen) gen_assign_stmt(node_ ast.AssignStmt) {
} }
func := right_sym.info as ast.FnType func := right_sym.info as ast.FnType
ret_styp := g.typ(func.func.return_type) ret_styp := g.typ(func.func.return_type)
g.write('$ret_styp (*${g.get_ternary_name(ident.name)}) (')
mut call_conv := ''
mut msvc_call_conv := ''
for attr in func.func.attrs {
match attr.name {
'callconv' {
if g.is_cc_msvc {
msvc_call_conv = '__$attr.arg '
} else {
call_conv = '$attr.arg'
}
}
else {}
}
}
call_conv_attribute_suffix := if call_conv.len != 0 {
'__attribute__(($call_conv))'
} else {
''
}
g.write('$ret_styp ($msvc_call_conv*${g.get_ternary_name(ident.name)}) (')
def_pos := g.definitions.len def_pos := g.definitions.len
g.fn_decl_params(func.func.params, voidptr(0), false) g.fn_decl_params(func.func.params, voidptr(0), false)
g.definitions.go_back(g.definitions.len - def_pos) g.definitions.go_back(g.definitions.len - def_pos)
g.write(')') g.write(')$call_conv_attribute_suffix')
} else { } else {
if is_decl { if is_decl {
if is_inside_ternary { if is_inside_ternary {