@@ -341,17 +341,11 @@ Compilation::visit (AST::Function &function)
341
341
scope.Push ();
342
342
printf (" INSIDE FUNCTION: %s\n " , function.function_name .c_str ());
343
343
344
- if (!function.has_function_return_type ())
345
- {
346
- // TODO
347
- // auto fntype = backend->function_type ();
344
+ Backend::Btyped_identifier receiver;
345
+ std::vector<Backend::Btyped_identifier> parameters;
346
+ std::vector<Backend::Btyped_identifier> results;
348
347
349
- auto mangled_asm_name = " " ; // TODO
350
- currentFndecl
351
- = backend->function (backend->void_type (), function.function_name ,
352
- mangled_asm_name, 0 , function.locus );
353
- }
354
- else
348
+ if (function.has_function_return_type ())
355
349
{
356
350
translatedType = NULL ;
357
351
function.return_type ->accept_vis (*this );
@@ -360,40 +354,42 @@ Compilation::visit (AST::Function &function)
360
354
rust_error_at (function.locus , " Unable to compile type" );
361
355
return ;
362
356
}
363
-
364
- auto mangled_asm_name = " " ; // TODO
365
- currentFndecl = backend->function (translatedType, function.function_name ,
366
- mangled_asm_name, 0 , function.locus );
367
357
}
368
358
369
- std::vector< ::Bvariable *> params;
370
359
for (auto ¶m : function.function_params )
371
360
{
372
361
printf (" FUNC PARAM: %s\n " , param.as_string ().c_str ());
373
362
// TODO
374
363
}
375
364
376
- if (params .size () == 0 && function.function_params .size () > 0 )
365
+ if (parameters .size () != function.function_params .size ())
377
366
{
378
- rust_error_at (function.locus , " Unable to compile parameters" );
367
+ rust_error_at (function.locus ,
368
+ " Unable to compile all function parameters" );
379
369
return ;
380
370
}
381
- else if (params.size () > 0 )
371
+
372
+ auto fntype = backend->function_type (receiver, parameters, results, NULL ,
373
+ function.locus );
374
+
375
+ auto mangled_asm_name = " " ; // TODO
376
+ auto fndecl = backend->function (fntype, function.function_name ,
377
+ mangled_asm_name, 0 , function.locus );
378
+
379
+ // walk the expression body
380
+ std::vector<Bvariable *> vars;
381
+ auto code_block
382
+ = backend->block (fndecl, NULL , vars, function.locus , Location ());
383
+ for (auto &stmt : function.function_body ->statements )
382
384
{
383
- backend-> function_set_parameters (currentFndecl, params );
385
+ stmt-> accept_vis (* this );
384
386
}
385
387
386
- /*
387
- // walk the expression body
388
- Bstatement *body;
389
- for (auto &stmt : function.function_body->statements)
390
- {
391
- stmt->accept_vis (*this);
392
- }
393
-
394
- backend->function_set_body (fndecl, body);*/
388
+ auto body = backend->block_statement (code_block);
389
+ if (!backend->function_set_body (fndecl, body))
390
+ rust_error_at (function.locus , " failed to set body to function" );
395
391
396
- func_decls.push_back (currentFndecl );
392
+ func_decls.push_back (fndecl );
397
393
currentFndecl = NULL ;
398
394
399
395
scope.Pop ();
0 commit comments