ref: cc8d65b2d48716971a2bd060c7e55351137f638f
parent: 8c2fb645b95fa69e53e910102c601f3a80007251
author: Ori Bernstein <[email protected]>
date: Tue Jun 18 09:51:00 EDT 2013
Attempt to build arrays and structs correctly.
--- a/6/simp.c
+++ b/6/simp.c
@@ -933,7 +933,6 @@
off = 0;
for (i = 0; i < n->expr.nargs; i++) {
- off = align(off, size(args[i]));
val = rval(s, args[i], NULL);
pdst = add(r, disp(n->line, off));
@@ -1003,6 +1002,26 @@
die("No uget simplification yet");
}
+static Node *assignat(Simp *s, Node *r, size_t off, Node *val)
+{
+ Node *pval, *pdst;
+ Node *sz;
+ Node *st;
+
+ val = rval(s, val, NULL);
+ pdst = add(r, disp(val->line, off));
+
+ if (stacknode(val)) {
+ sz = disp(val->line, size(val));
+ pval = addr(s, val, exprtype(val));
+ st = mkexpr(val->line, Oblit, pdst, pval, sz, NULL);
+ } else {
+ st = set(deref(pdst), val);
+ }
+ append(s, st);
+ return r;
+}
+
/* simplifies
* a || b
* to
@@ -1110,6 +1129,24 @@
case Otup:
r = simptup(s, n, dst);
break;
+ case Oarr:
+ if (dst)
+ r = dst;
+ else
+ r = temp(s, n);
+ t = addr(s, dst, exprtype(dst));
+ for (i = 0; i < n->expr.nargs; i++)
+ assignat(s, t, size(n->expr.args[i])*i, n->expr.args[i]);
+ break;
+ case Ostruct:
+ if (dst)
+ r = dst;
+ else
+ r = temp(s, n);
+ t = addr(s, dst, exprtype(dst));
+ for (i = 0; i < n->expr.nargs; i++)
+ assignat(s, t, offset(n, n->expr.args[i]->expr.idx), n->expr.args[i]);
+ break;
case Ocast:
r = simpcast(s, args[0], exprtype(n));
break;
@@ -1204,20 +1241,6 @@
r = addr(s, t, exprtype(t));
else
r = t->expr.args[0];
- break;
- case Oarr:
- if (dst)
- r = dst;
- else
- r = temp(s, n);
- die("No initialization done yet");
- break;
- case Ostruct:
- if (dst)
- r = dst;
- else
- r = temp(s, n);
- die("No initialization done yet");
break;
default:
r = visit(s, n);
--- a/libstd/fmt.myr
+++ b/libstd/fmt.myr
@@ -153,10 +153,11 @@
-> i
}
+const digitchars = [
+'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'
+]
+
const intfmt = {buf, val, base
- const digits = [
- '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'
- ]
var isneg
var b : char[32]
var i
@@ -176,7 +177,7 @@
i++
;;
while val != 0
- b[i] = digits[val % base]
+ b[i] = digitchars[val % base]
val /= base
i++
;;