summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2013-02-20 02:15:01 -0500
committerOri Bernstein <ori@eigenstate.org>2013-02-20 02:15:01 -0500
commit3e92cda1745121a0545c581d9f135feed9e280bd (patch)
tree4a594c23003a52e5d66b2a79fbca5d5733631b11
parent543887f46d1d7796bd8f1e6d329401197b19ec56 (diff)
downloadmc-3e92cda1745121a0545c581d9f135feed9e280bd.tar.gz
'#' is now the postfix pointer deref operator.
This makes operator precedence less confusing.
-rw-r--r--libstd/alloc.myr56
-rw-r--r--libstd/chartype.myr2
-rw-r--r--libstd/fmt.myr2
-rw-r--r--libstd/optparse.myr6
-rw-r--r--libstd/rand.myr4
-rw-r--r--libstd/test.myr4
-rw-r--r--libstd/varargs.myr6
-rw-r--r--parse/gram.y15
-rw-r--r--parse/tok.c4
-rw-r--r--parse/util.c2
-rw-r--r--test/arrayaddr.myr2
-rw-r--r--test/derefassign.myr2
-rw-r--r--test/outparam-sl.myr2
-rw-r--r--test/outparam.myr2
-rw-r--r--test/ptrpreinc.myr2
-rwxr-xr-xtest/test.sh2
-rw-r--r--test/tyrec.myr2
17 files changed, 57 insertions, 58 deletions
diff --git a/libstd/alloc.myr b/libstd/alloc.myr
index ab7e383..7ab8a68 100644
--- a/libstd/alloc.myr
+++ b/libstd/alloc.myr
@@ -26,21 +26,21 @@ Large allocations are simply satisfied by mmap().
*/
pkg std =
- generic alloc : ( -> @a*)
- generic free : (v:@a* -> void)
+ generic alloc : ( -> @a#)
+ generic free : (v:@a# -> void)
generic slalloc : (len : size -> @a[:])
generic slgrow : (sl : @a[:], len : size -> @a[:])
generic slfree : (sl : @a[:] -> void)
- const bytealloc : (sz:size -> byte*)
- const bytefree : (m:byte*, sz:size -> void)
+ const bytealloc : (sz:size -> byte#)
+ const bytefree : (m:byte#, sz:size -> void)
;;
/* null pointers. only used internally. */
-const Zbyte = 0 castto(byte*)
-const Zslab = 0 castto(slab*)
-const Zchunk = 0 castto(chunk*)
+const Zbyte = 0 castto(byte#)
+const Zslab = 0 castto(slab#)
+const Zchunk = 0 castto(chunk#)
const Slabsz = 1048576 /* 1 meg slabs */
const Cachemax = 16 /* maximum number of slabs in the cache */
@@ -53,43 +53,43 @@ var initdone : int
type bucket = struct
sz : size /* aligned size */
nper : size /* max number of elements per slab */
- slabs : slab* /* partially filled or free slabs */
- cache : slab* /* cache of empty slabs, to prevent thrashing */
+ slabs : slab# /* partially filled or free slabs */
+ cache : slab# /* cache of empty slabs, to prevent thrashing */
ncache : size /* size of cache */
;;
type slab = struct
- head : byte* /* head of virtual addresses, so we don't leak address space */
- next : slab* /* the next slab on the chain */
- freehd : chunk* /* the nodes we're allocating */
+ head : byte# /* head of virtual addresses, so we don't leak address space */
+ next : slab# /* the next slab on the chain */
+ freehd : chunk# /* the nodes we're allocating */
nfree : size /* the number of free nodes */
;;
type chunk = struct /* NB: must be smaller than sizeof(slab) */
- next : chunk* /* the next chunk in the free list */
+ next : chunk# /* the next chunk in the free list */
;;
/* Allocates an object of type @a, returning a pointer to it. */
-generic alloc = {-> @a*
- -> bytealloc(sizeof(@a)) castto(@a*)
+generic alloc = {-> @a#
+ -> bytealloc(sizeof(@a)) castto(@a#)
}
/* Frees a value of type @a */
-generic free = {v:@a* -> void
- bytefree(v castto(byte*), sizeof(@a))
+generic free = {v:@a# -> void
+ bytefree(v castto(byte#), sizeof(@a))
}
/* allocates a slice of 'len' elements. */
generic slalloc = {len
var p
- p = bytealloc(len*sizeof(@a)) castto(@a*)
+ p = bytealloc(len*sizeof(@a)) castto(@a#)
-> p[0:len]
}
/* Frees a slice */
generic slfree = {sl
- bytefree(sl castto(byte*), sl.len * sizeof(@a))
+ bytefree(sl castto(byte#), sl.len * sizeof(@a))
}
/* Grows a slice */
@@ -140,7 +140,7 @@ const bytefree = {m, sz
}
/* Sets up a single empty bucket */
-const bktinit = {b : bucket*, sz
+const bktinit = {b, sz
b.sz = align(sz, Align)
b.nper = (Slabsz - sizeof(slab))/b.sz
b.slabs = Zslab
@@ -149,7 +149,7 @@ const bktinit = {b : bucket*, sz
}
/* Creates a slab for bucket 'bkt', and fills the chunk list */
-const mkslab = {bkt : bucket*
+const mkslab = {bkt
var i
var p
var s
@@ -173,12 +173,12 @@ const mkslab = {bkt : bucket*
die("Unable to mmap")
;;
- s = align(p castto(intptr), Slabsz) castto(slab*)
+ s = align(p castto(intptr), Slabsz) castto(slab#)
s.head = p
s.nfree = bkt.nper
/* skip past the slab header */
off = align(sizeof(slab), Align)
- bnext = nextchunk(s castto(chunk*), off)
+ bnext = nextchunk(s castto(chunk#), off)
s.freehd = bnext
for i = 0; i < bkt.nper; i++
b = bnext
@@ -217,7 +217,7 @@ const bktalloc = {bkt
s.next = Zslab
;;
- -> b castto(byte*)
+ -> b castto(byte#)
}
/*
@@ -230,8 +230,8 @@ const bktfree = {bkt, m
var s
var b
- s = mtrunc(m, Slabsz) castto(slab*)
- b = m castto(chunk*)
+ s = mtrunc(m, Slabsz) castto(slab#)
+ b = m castto(chunk#)
if s.nfree == 0
s.next = bkt.slabs
bkt.slabs = s
@@ -273,7 +273,7 @@ chunks are variable sizes, so we can't just
index to get to the next one
*/
const nextchunk = {b, sz
- -> ((b castto(intptr)) + sz) castto(chunk*)
+ -> ((b castto(intptr)) + sz) castto(chunk#)
}
/*
@@ -289,5 +289,5 @@ truncates a pointer to 'align'. 'align' must
be a power of two.
*/
const mtrunc = {m, align
- -> ((m castto(intptr)) & ~(align - 1)) castto(byte*)
+ -> ((m castto(intptr)) & ~(align - 1)) castto(byte#)
}
diff --git a/libstd/chartype.myr b/libstd/chartype.myr
index cf62aae..a8af597 100644
--- a/libstd/chartype.myr
+++ b/libstd/chartype.myr
@@ -1070,7 +1070,7 @@ const findc = {c, t, sz, nelt, ret
;;
if t.len != 0 && c >= t[0]
- *ret = t
+ ret# = t
-> true
else
-> false
diff --git a/libstd/fmt.myr b/libstd/fmt.myr
index d965163..ca77d28 100644
--- a/libstd/fmt.myr
+++ b/libstd/fmt.myr
@@ -49,7 +49,7 @@ const bfmtv = {buf, fmt, ap
var w_val : int16
var i_val : int32
var l_val : int64
- var p_val : byte*
+ var p_val : byte#
var c_val : char
n = 0
diff --git a/libstd/optparse.myr b/libstd/optparse.myr
index 6702514..0bd1cfa 100644
--- a/libstd/optparse.myr
+++ b/libstd/optparse.myr
@@ -15,9 +15,9 @@ pkg std =
arglist : byte[:][:]
;;
- const optinit : (opts : byte[:], args : byte[:][:] -> optctx*)
- const optnext : (ctx : optctx* -> char)
- const optarg : (ctx : optctx* -> byte[:])
+ const optinit : (opts : byte[:], args : byte[:][:] -> optctx#)
+ const optnext : (ctx : optctx# -> char)
+ const optarg : (ctx : optctx# -> byte[:])
;;
const optinit = {opts, args
diff --git a/libstd/rand.myr b/libstd/rand.myr
index 9d5c0f1..6da69d3 100644
--- a/libstd/rand.myr
+++ b/libstd/rand.myr
@@ -50,8 +50,8 @@ pkg std =
/* no mkrng() yet because we don't have anything to automatically
seed it with yet */
- const mksrng : (seed : uint32 -> rng*)
- const rand32 : (rng : rng* -> uint32)
+ const mksrng : (seed : uint32 -> rng#)
+ const rand32 : (rng : rng# -> uint32)
;;
type rng = struct
diff --git a/libstd/test.myr b/libstd/test.myr
index f59b77b..b0ad950 100644
--- a/libstd/test.myr
+++ b/libstd/test.myr
@@ -1,7 +1,7 @@
use std
const main = {args : byte[:][:]
- var x : byte*[1024]
+ var x : byte#[1024]
var sz
var i
var opt
@@ -75,7 +75,7 @@ const chartypes = {
}
const testrng = {
- var r : std.rng*
+ var r
var i
r = std.mksrng(10)
diff --git a/libstd/varargs.myr b/libstd/varargs.myr
index 96c7b38..f7b7ffb 100644
--- a/libstd/varargs.myr
+++ b/libstd/varargs.myr
@@ -3,11 +3,11 @@ use "types.use"
pkg std =
type valist
- const vastart : (args : ...* -> valist)
+ const vastart : (args : ...# -> valist)
generic vanext : (ap : valist -> [@a, valist])
;;
-type valist = byte*
+type valist = byte#
/*
* a valist is really just a pointer to the varargs.
@@ -44,7 +44,7 @@ generic vanext = {ap -> [@a, valist]
p = (p + align - 1) & ~(align - 1)
ap = p castto(valist)
- v = *(ap castto(@a*))
+ v = (ap castto(@a#))#
/* only move on after we read through the value */
ap = ((p castto(intptr)) + sizeof(@a)) castto(valist)
diff --git a/parse/gram.y b/parse/gram.y
index 9c047de..9c0874c 100644
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -28,7 +28,7 @@ static void constrainwith(Type *t, char *str);
%token<tok> Terror
%token<tok> Tplus /* + */
%token<tok> Tminus /* - */
-%token<tok> Tstar /* * */
+%token<tok> Tmul /* * */
%token<tok> Tdiv /* / */
%token<tok> Tinc /* ++ */
%token<tok> Tdec /* -- */
@@ -71,7 +71,7 @@ static void constrainwith(Type *t, char *str);
%token<tok> Tcsqbrac /* ] */
%token<tok> Tat /* @ */
%token<tok> Ttick /* ` */
-%token<tok> Thash /* # */
+%token<tok> Tderef /* # */
%token<tok> Ttype /* type */
%token<tok> Tfor /* for */
@@ -327,7 +327,7 @@ compoundtype
: functype {$$ = $1;}
| type Tosqbrac Tcolon Tcsqbrac {$$ = mktyslice($2->line, $1);}
| type Tosqbrac expr Tcsqbrac {$$ = mktyarray($2->line, $1, $3);}
- | type Tstar {$$ = mktyptr($2->line, $1);}
+ | type Tderef {$$ = mktyptr($2->line, $1);}
| Tat Tident {$$ = mktyparam($1->line, $2->str);}
| name {$$ = mktyunres($1->line, $1, NULL, 0);}
| name Toparen typelist Tcparen {$$ = mktyunres($1->line, $1, $3.types, $3.ntypes);}
@@ -510,7 +510,7 @@ mulexpr : mulexpr mulop shiftexpr
| shiftexpr
;
-mulop : Tstar | Tdiv | Tmod
+mulop : Tmul | Tdiv | Tmod
;
shiftexpr
@@ -524,7 +524,6 @@ shiftop : Tbsl | Tbsr;
prefixexpr
: Tinc prefixexpr {$$ = mkexpr($1->line, Opreinc, $2, NULL);}
| Tdec prefixexpr {$$ = mkexpr($1->line, Opredec, $2, NULL);}
- | Tstar prefixexpr {$$ = mkexpr($1->line, Oderef, $2, NULL);}
| Tband prefixexpr {$$ = mkexpr($1->line, Oaddr, $2, NULL);}
| Tlnot prefixexpr {$$ = mkexpr($1->line, Olnot, $2, NULL);}
| Tbnot prefixexpr {$$ = mkexpr($1->line, Obnot, $2, NULL);}
@@ -544,6 +543,8 @@ postfixexpr
{$$ = mkexpr($1->line, Oidx, $1, $3, NULL);}
| postfixexpr Tosqbrac optexpr Tcolon optexpr Tcsqbrac
{$$ = mksliceexpr($1->line, $1, $3, $5);}
+ | postfixexpr Tderef
+ {$$ = mkexpr($1->line, Oderef, $1, NULL);}
| postfixexpr Toparen arglist Tcparen
{$$ = mkcall($1->line, $1, $3.nl, $3.nn);}
| atomicexpr
@@ -625,8 +626,6 @@ seqbody : /* empty */ {$$.nl = NULL; $$.nn = 0;}
seqelt : Tdot Tident Tasn expr
{die("Unimplemented struct member init");}
- | Thash atomicexpr Tasn expr
- {die("Unimplmented array member init");}
| endlns expr endlns{$$ = $2;}
;
@@ -776,7 +775,7 @@ static Op binop(int tt)
switch (tt) {
case Tplus: o = Oadd; break;
case Tminus: o = Osub; break;
- case Tstar: o = Omul; break;
+ case Tmul: o = Omul; break;
case Tdiv: o = Odiv; break;
case Tmod: o = Omod; break;
case Tasn: o = Oasn; break;
diff --git a/parse/tok.c b/parse/tok.c
index 78f1108..0a1cd2e 100644
--- a/parse/tok.c
+++ b/parse/tok.c
@@ -375,7 +375,7 @@ static Tok *oper(void)
case ']': tt = Tcsqbrac; break;
case ',': tt = Tcomma; break;
case '`': tt = Ttick; break;
- case '#': tt = Thash; break;
+ case '#': tt = Tderef; break;
case ':':
if (match(':'))
tt = Twith;
@@ -423,7 +423,7 @@ static Tok *oper(void)
if (match('='))
tt = Tmuleq;
else
- tt = Tstar;
+ tt = Tmul;
break;
case '/':
if (match('='))
diff --git a/parse/util.c b/parse/util.c
index f5bbbec..46ef852 100644
--- a/parse/util.c
+++ b/parse/util.c
@@ -68,7 +68,7 @@ void fatal(int line, char *msg, ...)
va_list ap;
va_start(ap, msg);
- fprintf(stdout, "%s:%d: ", filename, line);
+ fprintf(stdout, "%s:%d: ", file->file.name, line);
vfprintf(stdout, msg, ap);
fprintf(stdout, "\n");
va_end(ap);
diff --git a/test/arrayaddr.myr b/test/arrayaddr.myr
index ec325f5..06035d4 100644
--- a/test/arrayaddr.myr
+++ b/test/arrayaddr.myr
@@ -6,6 +6,6 @@ const main = {
v[1] = 42
p = &v[1]
- -> *p
+ -> p#
}
diff --git a/test/derefassign.myr b/test/derefassign.myr
index 1250ac6..0fc5c85 100644
--- a/test/derefassign.myr
+++ b/test/derefassign.myr
@@ -5,6 +5,6 @@ const main = {
var v
p = &v
- *p = 123
+ p# = 123
-> v
}
diff --git a/test/outparam-sl.myr b/test/outparam-sl.myr
index c6da11e..78d7963 100644
--- a/test/outparam-sl.myr
+++ b/test/outparam-sl.myr
@@ -2,7 +2,7 @@ use std
/* should assign a slice through an out param, returning exiting with 2 */
const arr = [1,2,3,4]
const f = {out
- *out = arr[1:3]
+ out# = arr[1:3]
}
const main = {
diff --git a/test/outparam.myr b/test/outparam.myr
index 167fa48..8d9e790 100644
--- a/test/outparam.myr
+++ b/test/outparam.myr
@@ -1,7 +1,7 @@
use std
/* should assign through an out pointer parameter, exiting with status 42 */
const f = {out
- *out = 42
+ out# = 42
}
const main = {
diff --git a/test/ptrpreinc.myr b/test/ptrpreinc.myr
index 22a0706..ac4fe1e 100644
--- a/test/ptrpreinc.myr
+++ b/test/ptrpreinc.myr
@@ -1,7 +1,7 @@
use std
/* should preincrement through a pointer, exiting with status 9 */
const ppreinc = {p
- -> ++*p
+ -> ++p#
}
const main = {
diff --git a/test/test.sh b/test/test.sh
index c38d8d2..07757c3 100755
--- a/test/test.sh
+++ b/test/test.sh
@@ -14,7 +14,7 @@ function use {
function build {
rm -f $1 $1.o $1.s $1.use
- ../myrbuild/myrbuild -b $1 $1.myr -C../6/6m -I../libstd
+ ../myrbuild/myrbuild -b $1 $1.myr -C../6/6m -M../muse/muse -I../libstd
}
function prints {
diff --git a/test/tyrec.myr b/test/tyrec.myr
index b69466a..2b29ae6 100644
--- a/test/tyrec.myr
+++ b/test/tyrec.myr
@@ -1,7 +1,7 @@
use std
/* we just want to see if this file compiles */
type foo = struct
- v : foo*
+ v : foo#
;;
const main = {