mescc: Support void functions.

* module/language/c99/compiler.mes (function->info): Add return if
  missing.  Fixes calling void functions (and functions where return
  is missing).
* scaffold/t.c (void_func): Test it.
This commit is contained in:
Jan Nieuwenhuizen 2017-05-06 09:11:42 +02:00
parent 6dc19bd040
commit 68528219cb
2 changed files with 16 additions and 4 deletions

View file

@ -1945,6 +1945,10 @@
(define (function->info info)
(lambda (o)
(define (assert-return text)
(let ((return (wrap-as (i386:ret))))
(if (equal? (list-tail text (- (length text) (length return))) return) text
(append text (wrap-as (i386:ret))))))
(let* ((name (.name o))
(formals (.formals o))
(text (formals->text formals))
@ -1952,9 +1956,9 @@
(format (current-error-port) "compiling: ~a\n" name)
(let loop ((statements (.statements o))
(info (clone info #:locals locals #:function (.name o) #:text text)))
(if (null? statements) (clone info
(if (null? statements) (assert-return (clone info
#:function #f
#:functions (append (.functions info) (list (cons name (.text info)))))
#:functions (append (.functions info) (list (cons name (assert-return (.text info)))))))
(let* ((statement (car statements)))
(loop (cdr statements)
((ast->info info) (car statements)))))))))

View file

@ -539,6 +539,11 @@ struct_test ()
return make_tmps_test (g_cells);
}
void
void_func ()
{
}
int
test (char *p)
{
@ -910,6 +915,9 @@ test (char *p)
puts ("strcmp (itoa (1), \"1\")\n");
if (strcmp (itoa (1), "1")) return 1;
puts ("void_func ()\n");
void_func ();
return struct_test ();
}
#endif