ref: 5248ba5079d913bb416ebbb1eea4b8750acd819a
parent: 6d2283c60d81931945e78f068aa330d0146f10a5
author: Ori Bernstein <[email protected]>
date: Fri Jul 20 22:40:43 EDT 2012
Move strings to be byte[,], and char to be 32 bit. This brings us towards the brave new world of utf8 strings with codepoint manipulations.
--- a/8/simp.c
+++ b/8/simp.c
@@ -211,7 +211,7 @@
case Tyvoid:
die("void has no size");
return 1;
- case Tybool: case Tychar: case Tyint8:
+ case Tybool: case Tyint8:
case Tybyte: case Tyuint8:
return 1;
case Tyint16: case Tyuint16:
@@ -219,6 +219,7 @@
case Tyint: case Tyint32:
case Tyuint: case Tyuint32:
case Typtr: case Tyfunc:
+ case Tychar: /* utf32 */
return 4;
case Tyint64: case Tylong:
@@ -556,7 +557,7 @@
static Node *idxaddr(Simp *s, Node *n)
{
- Node *t, *u, *v; /* temps */
+ Node *a, *t, *u, *v; /* temps */
Node *r; /* result */
Node **args;
size_t sz;
@@ -563,10 +564,11 @@
assert(exprop(n) == Oidx);
args = n->expr.args;
+ a = rval(s, args[0], NULL);
if (exprtype(args[0])->type == Tyarray)
- t = addr(args[0], exprtype(n));
+ t = addr(a, exprtype(n));
else if (args[0]->expr.type->type == Tyslice)
- t = load(addr(args[0], mktyptr(n->line, exprtype(n))));
+ t = load(addr(a, mktyptr(n->line, exprtype(n))));
else
die("Can't index type %s\n", tystr(n->expr.type));
assert(t->expr.type->type == Typtr);
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -229,7 +229,7 @@
case Lbool: return mkty(n->line, Tybool); break;
case Lint: return tylike(mktyvar(n->line), Tyint); break;
case Lflt: return tylike(mktyvar(n->line), Tyfloat32); break;
- case Lstr: return mktyslice(n->line, mkty(n->line, Tychar)); break;
+ case Lstr: return mktyslice(n->line, mkty(n->line, Tybyte)); break;
case Lfunc: return n->lit.fnval->func.type; break;
case Lseq: return NULL; break;
};
--- a/test/gsizeof.myr
+++ b/test/gsizeof.myr
@@ -3,5 +3,5 @@
}
const main = {
- -> sz(123) + sz('a')
+ -> sz(123) + sz("asdf"[0])
}