summaryrefslogtreecommitdiff
path: root/parse
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-11-06 23:07:35 -0800
committerOri Bernstein <ori@eigenstate.org>2015-11-06 23:07:35 -0800
commitc1c1c42c36717dea8dbca9e1bed8d794144ec6f1 (patch)
treeb19db09246b86fdc236d2f9771aea5f6294c9c53 /parse
parenteac5baa8515b5e6fe46ecf609d2cac94ffed5dc6 (diff)
downloadmc-c1c1c42c36717dea8dbca9e1bed8d794144ec6f1.tar.gz
Add support for '$' operator.
Diffstat (limited to 'parse')
-rw-r--r--parse/gram.y3
-rw-r--r--parse/infer.c6
-rw-r--r--parse/ops.def1
-rw-r--r--parse/tok.c1
4 files changed, 11 insertions, 0 deletions
diff --git a/parse/gram.y b/parse/gram.y
index 32794ce..f082be1 100644
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -78,6 +78,7 @@ 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 */
@@ -712,6 +713,8 @@ 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 ec21615..11b155a 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -1475,6 +1475,12 @@ 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);
diff --git a/parse/ops.def b/parse/ops.def
index dd9447a..2a8f64d 100644
--- a/parse/ops.def
+++ b/parse/ops.def
@@ -55,6 +55,7 @@ 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 a1df12f..9cb6716 100644
--- a/parse/tok.c
+++ b/parse/tok.c
@@ -162,6 +162,7 @@ static void eatspace(void)
static int kwd(char *s)
{
static const struct {char* kw; int tt;} kwmap[] = {
+ {"$", Tidxlen},
{"$noret", Tattr},
{"_", Tgap},
{"break", Tbreak},