summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2016-01-26 11:06:05 -0800
committerOri Bernstein <ori@eigenstate.org>2016-01-26 11:06:05 -0800
commitfe0bcf756016bd8cad54c1af77f054b94fc8d11b (patch)
tree550cd7812212cbcbabba3cef5980cbdc73662e1f
parent74b3aaed1a5a978a4d64ae4bdce9b0cdcf82860c (diff)
downloadmc-fe0bcf756016bd8cad54c1af77f054b94fc8d11b.tar.gz
Remove the '$' shorthand for end of array.
-rw-r--r--6/isel.c2
-rw-r--r--6/simp.c17
-rw-r--r--lib/inifile/parse.myr2
-rw-r--r--lib/std/slpop.myr2
-rw-r--r--parse/gram.y12
-rw-r--r--parse/infer.c6
-rw-r--r--parse/ops.def1
-rw-r--r--parse/tok.c5
-rw-r--r--test/idxlen.myr7
-rw-r--r--test/tests1
10 files changed, 11 insertions, 44 deletions
diff --git a/6/isel.c b/6/isel.c
index 74d605a..c47e96b 100644
--- a/6/isel.c
+++ b/6/isel.c
@@ -888,7 +888,7 @@ Loc *selexpr(Isel *s, Node *n)
case Obandeq: case Obxoreq: case Obsleq: case Obsreq: case Omemb:
case Oslbase: case Osllen: case Ocast: case Outag: case Oudata:
case Oucon: case Otup: case Oarr: case Ostruct:
- case Oslice: case Oidx: case Osize: case Otupget: case Oidxlen:
+ case Oslice: case Oidx: case Osize: case Otupget:
case Obreak: case Ocontinue:
case Numops:
dump(n, stdout);
diff --git a/6/simp.c b/6/simp.c
index a470d95..eed63de 100644
--- a/6/simp.c
+++ b/6/simp.c
@@ -35,10 +35,6 @@ struct Simp {
int hasenv;
int isbigret;
- /* the array we're indexing for context within [] */
- Node **idxctx;
- size_t nidxctx;
-
/* pre/postinc handling */
Node **incqueue;
size_t nqueue;
@@ -781,9 +777,7 @@ static Node *loadidx(Simp *s, Node *arr, Node *idx)
Node *v, *a;
a = rval(s, arr, NULL);
- lappend(&s->idxctx, &s->nidxctx, a);
v = deref(idxaddr(s, a, idx), NULL);
- lpop(&s->idxctx, &s->nidxctx);
return v;
}
@@ -956,8 +950,6 @@ static Node *simpslice(Simp *s, Node *n, Node *dst)
else
t = temp(s, n);
seq = rval(s, n->expr.args[0], NULL);
- if (tybase(exprtype(seq))->type != Typtr)
- lappend(&s->idxctx, &s->nidxctx, seq);
/* *(&slice) = (void*)base + off*sz */
base = slicebase(s, seq, n->expr.args[1]);
start = ptrsized(s, rval(s, n->expr.args[1], NULL));
@@ -975,8 +967,6 @@ static Node *simpslice(Simp *s, Node *n, Node *dst)
stbase = set(deref(addr(s, t, tyintptr), NULL), base);
sz = addk(addr(s, t, tyintptr), Ptrsz);
}
- if (tybase(exprtype(seq))->type != Typtr)
- lpop(&s->idxctx, &s->nidxctx);
/* *(&slice + ptrsz) = len */
stlen = set(deref(sz, NULL), len);
append(s, stbase);
@@ -1507,9 +1497,7 @@ static Node *rval(Simp *s, Node *n, Node *dst)
break;
case Oidx:
t = rval(s, n->expr.args[0], NULL);
- lappend(&s->idxctx, &s->nidxctx, t);
u = idxaddr(s, t, n->expr.args[1]);
- lpop(&s->idxctx, &s->nidxctx);
r = load(u);
break;
/* array.len slice.len are magic 'virtual' members.
@@ -1630,11 +1618,6 @@ static Node *rval(Simp *s, Node *n, Node *dst)
case Ovar:
r = loadvar(s, n, dst);
break;;
- case Oidxlen:
- if (s->nidxctx == 0)
- fatal(n, "'$' undefined outside of index or slice expression");
- return seqlen(s, s->idxctx[s->nidxctx - 1], exprtype(n));
- break;
case Ogap:
fatal(n, "'_' may not be an rvalue");
break;
diff --git a/lib/inifile/parse.myr b/lib/inifile/parse.myr
index 2ad4589..4b36ad0 100644
--- a/lib/inifile/parse.myr
+++ b/lib/inifile/parse.myr
@@ -108,7 +108,7 @@ const parsesection = {p, ini, ln
-> false
;;
std.slfree(p.sect)
- p.sect = std.sldup(std.strstrip(ln[1:$-1]))
+ p.sect = std.sldup(std.strstrip(ln[1:]))
| `std.None:
p.err = `std.Some (`Parseerr p.line)
-> false
diff --git a/lib/std/slpop.myr b/lib/std/slpop.myr
index 9c8f152..be4d8b4 100644
--- a/lib/std/slpop.myr
+++ b/lib/std/slpop.myr
@@ -8,7 +8,7 @@ pkg std =
generic slpop = {sl
var elt
- elt = sl[$ - 1]
+ elt = sl[sl.len - 1]
sl = slgrow(sl, sl.len - 1)
-> (elt, sl)
}
diff --git a/parse/gram.y b/parse/gram.y
index a07d235..732ad9b 100644
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -78,7 +78,6 @@ static void setupinit(Node *n);
%token<tok> Tat /* @ */
%token<tok> Ttick /* ` */
%token<tok> Tderef /* # */
-%token<tok> Tidxlen /* $ */
%token<tok> Ttype /* type */
%token<tok> Tfor /* for */
@@ -597,13 +596,14 @@ optexpr : expr {$$ = $1;}
| /* empty */ {$$ = NULL;}
;
-loopcond : exprln {$$ = $1;}
+loopcond: exprln {$$ = $1;}
| Tendln {$$ = mkboollit($1->loc, 1);}
;
-optexprln: exprln {$$ = $1;}
- | Tendln {$$ = NULL;}
- ;
+optexprln
+ : exprln {$$ = $1;}
+ | Tendln {$$ = NULL;}
+ ;
exprln : expr Tendln
;
@@ -737,8 +737,6 @@ atomicexpr
{$$ = mkexpr($1->loc, Ovar, mkname($1->loc, $1->id), NULL);}
| Tgap
{$$ = mkexpr($1->loc, Ogap, NULL);}
- | Tidxlen
- {$$ = mkexpr($1->loc, Oidxlen, NULL);}
| literal
| Toparen expr Tcparen
{$$ = $2;}
diff --git a/parse/infer.c b/parse/infer.c
index 84bbd46..a76d420 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -1583,12 +1583,6 @@ static void inferexpr(Inferstate *st, Node **np, Type *ret, int *sawret)
infersub(st, n, ret, sawret, &isconst);
settype(st, n, mktype(n->loc, Tyvoid));
break;
- case Oidxlen:
- t = mktyvar(n->loc);
- constrain(st, n, t, traittab[Tcnum]);
- constrain(st, n, t, traittab[Tcint]);
- settype(st, n, t);
- break;
case Odef:
case Odead: n->expr.type = mktype(n->loc, Tyvoid); break;
case Obad:
diff --git a/parse/ops.def b/parse/ops.def
index 2a8f64d..dd9447a 100644
--- a/parse/ops.def
+++ b/parse/ops.def
@@ -55,7 +55,6 @@ O(Oucon, 1, OTmisc, "`")
O(Otup, 1, OTmisc, NULL)
O(Ostruct, 1, OTmisc, NULL)
O(Oarr, 1, OTmisc, NULL)
-O(Oidxlen, 1, OTmisc, "$")
/* all below this point are backend-only */
O(Odead, 0, OTmisc, "DEAD") /* dead code */
diff --git a/parse/tok.c b/parse/tok.c
index cd3346d..17fef0f 100644
--- a/parse/tok.c
+++ b/parse/tok.c
@@ -77,7 +77,9 @@ static Tok *mktok(int tt)
return t;
}
-static int identchar(int c) { return isalnum(c) || c == '_' || c == '$'; }
+static int identchar(int c) {
+ return isalnum(c) || c == '_' || c == '$';
+}
static void eatcomment(void)
{
@@ -160,7 +162,6 @@ static int kwd(char *s)
char *kw;
int tt;
} kwmap[] = {
- {"$", Tidxlen},
{"$noret", Tattr},
{"_", Tgap},
{"break", Tbreak},
diff --git a/test/idxlen.myr b/test/idxlen.myr
deleted file mode 100644
index 842a2a2..0000000
--- a/test/idxlen.myr
+++ /dev/null
@@ -1,7 +0,0 @@
-use std
-
-const main = {
- var a = [1,2,3,4]
- std.put("{} ", a[$-1])
- std.put("{}\n", a[$-2:])
-}
diff --git a/test/tests b/test/tests
index 6222c6a..d7c10d9 100644
--- a/test/tests
+++ b/test/tests
@@ -60,7 +60,6 @@ B voidassign P ok
B callbig E 42
B nestfn E 42
B foldidx P 123,456
-B idxlen P '4 [3, 4]'
B closure P 111555333666
B fncast P ok
B loop P 0123401236789