shithub: mc

Download patch

ref: 7b59bf042653209380b3a722184be80d7e9d81f9
parent: 5608cdaf56ac1e842f6bae691d22ca6800e5b363
author: Ori Bernstein <[email protected]>
date: Mon Dec 16 16:55:02 EST 2013

Make bigint literals work.

--- a/6/simp.c
+++ b/6/simp.c
@@ -1256,8 +1256,16 @@
             break;
         case Olit:
             switch (args[0]->lit.littype) {
-                case Lchr: case Lbool: case Lint: case Llbl:
+                case Lchr: case Lbool: case Llbl:
                     r = n;
+                    break;
+                case Lint: 
+                    /* we can only have up to 4 byte immediates, but they
+                     * can be moved into 64 bit regs */
+                    if (args[0]->lit.intval < 0xffffffff)
+                        r = n;
+                    else
+                        r = simplit(s, n, &s->blobs, &s->nblobs);
                     break;
                 case Lstr: case Lflt:
                     r = simplit(s, n, &s->blobs, &s->nblobs);
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -1568,8 +1568,6 @@
         uval = n->lit.intval;
         if (uval < uvranges[t->type][0] || uval > uvranges[t->type][1])
             fatal(n->line, "Literal value %llu out of range for type \"%s\"", tystr(t));
-    } else {
-        fatal(n->line, "Literal type %s has no range\n", tystr(t));
     }
 }
 
@@ -1625,6 +1623,10 @@
         case Nexpr:
             settype(st, n, tyfix(st, n, type(st, n)));
             typesub(st, n->expr.idx);
+            if (exprop(n) == Ocast && exprop(n->expr.args[0]) == Olit && n->expr.args[0]->expr.args[0]->lit.littype == Lint) {
+                settype(st, n->expr.args[0], exprtype(n));
+                settype(st, n->expr.args[0]->expr.args[0], exprtype(n));
+            }
             for (i = 0; i < n->expr.nargs; i++)
                 typesub(st, n->expr.args[i]);
             break;
--- a/test/bigliteral.myr
+++ b/test/bigliteral.myr
@@ -1,5 +1,5 @@
 use std
 
 const main = {
-	std.put("%l\n", 34359738368)
+	std.put("%l\n", 34359738368 castto(int64))
 }