@@ -5,6 +5,7 @@ use std::{collections::HashSet, io::Write, num::NonZero, path::Path};
55
66use crate :: {
77 asm:: LINKER_RECOVER ,
8+ cilnode:: MethodKind ,
89 config, typecheck,
910 utilis:: { assert_unique, encode} ,
1011 BiMap , IString , MethodImpl ,
@@ -88,13 +89,16 @@ impl CExporter {
8889 return Ok ( ( ) ) ;
8990 }
9091 let output = c_tpe ( mref. output ( asm) , asm) ;
91- let inputs = mref
92+ let mut inputs = mref
9293 . stack_inputs ( asm)
9394 . iter ( )
9495 . map ( |i| nonvoid_c_type ( * i, asm) )
9596 . intersperse ( "," . into ( ) )
9697 . collect :: < String > ( ) ;
97-
98+ if mref. kind ( ) == MethodKind :: Constructor {
99+ let owner = nonvoid_c_type ( Type :: ClassRef ( mref. class ( ) ) , asm) ;
100+ inputs = format ! ( "{owner},{inputs}" )
101+ }
98102 writeln ! ( method_decls, "{output} {method_name}({inputs});" )
99103 }
100104 #[ allow( clippy:: too_many_arguments) ]
@@ -820,7 +824,7 @@ impl CExporter {
820824 CILRoot :: Branch ( binfo) => {
821825 let ( target, sub_target, cond) = binfo. as_ref ( ) ;
822826 //let target = if *sub_target != 0 { sub_target } else { target };
823- let label = branch_cond_to_name ( * target, * sub_target, is_handler , has_handler ) ;
827+ let label = branch_cond_to_name ( * target, * sub_target, has_handler , is_handler ) ;
824828 let Some ( cond) = cond else {
825829 if next == Some ( * target) && * sub_target == 0 {
826830 return Ok ( "" . into ( ) ) ;
@@ -908,7 +912,7 @@ impl CExporter {
908912 CILRoot :: Call ( info) => {
909913 let ( method, args, _is_pure) = info. as_ref ( ) ;
910914 let method = asm[ * method] . clone ( ) ;
911- let call_args = args
915+ let mut call_args = args
912916 . iter ( )
913917 . map ( |arg| {
914918 format ! (
@@ -925,6 +929,10 @@ impl CExporter {
925929 } )
926930 . intersperse ( "," . into ( ) )
927931 . collect :: < String > ( ) ;
932+ if method. kind ( ) == MethodKind :: Constructor {
933+ let owner = nonvoid_c_type ( Type :: ClassRef ( method. class ( ) ) , asm) ;
934+ call_args = format ! ( "*({owner}*)malloc(sizeof({owner})),{call_args}" ) ;
935+ }
928936 let method_name = mref_to_name ( & method, asm) ;
929937 format ! ( "{method_name}({call_args});" )
930938 }
0 commit comments