shithub: mc

Download patch

ref: b0625d73a94310205e64d3b153ddb6844921b09f
parent: 938c3a42a7fb23c70b01e0fa0cdbc8b819b1e55b
author: Ori Bernstein <[email protected]>
date: Sun Jun 17 02:48:55 EDT 2012

Make vararg calls work.

    The final ABI has yet to be selected, but the type checking
    and code generation seems to work.

--- a/8/isel.c
+++ b/8/isel.c
@@ -340,7 +340,7 @@
         arg = inri(s, arg);
         dst = locmem(argoff, esp, NULL, arg->mode);
         stor(s, arg, dst);
-        argsz += size(n->expr.args[i]);
+        argoff += size(n->expr.args[i]);
     }
     fn = selexpr(s, n->expr.args[0]);
     g(s, Icall, fn, NULL);
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -543,7 +543,9 @@
         ;
 
 blockbody
-        : stmt
+        : /* empty */
+            {$$ = mkblock(line, mkstab());}
+        | stmt
             {$$ = mkblock(line, mkstab());
              if ($1)
                 lappend(&$$->block.stmts, &$$->block.nstmts, $1);
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -229,6 +229,8 @@
         unify(n, type(n->expr.args[0]), ft);
     }
     for (i = 1; i < n->expr.nargs; i++) {
+        if (ft->sub[i]->type == Tyvalist)
+            break;
         inferexpr(n->expr.args[i], NULL, NULL);
         unify(n, ft->sub[i], type(n->expr.args[i]));
     }