diff options
author | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2015-09-22 16:52:48 -0400 |
---|---|---|
committer | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2015-09-22 16:52:48 -0400 |
commit | 98c5a405bb34d69d1d8188f704226d24267fead6 (patch) | |
tree | 83aa8903782be71ce1eeee5f91e10cdfcbd033f7 /lisc | |
parent | 9db3c3cf3ee2bf332e129fc878ecc5bf67ca5dfe (diff) | |
download | roux-98c5a405bb34d69d1d8188f704226d24267fead6.tar.gz |
parse return types of functions
Diffstat (limited to 'lisc')
-rw-r--r-- | lisc/emit.c | 2 | ||||
-rw-r--r-- | lisc/lisc.h | 6 | ||||
-rw-r--r-- | lisc/parse.c | 29 |
3 files changed, 32 insertions, 5 deletions
diff --git a/lisc/emit.c b/lisc/emit.c index 820e2c4..2e81862 100644 --- a/lisc/emit.c +++ b/lisc/emit.c @@ -332,7 +332,7 @@ emitfn(Fn *fn, FILE *f) for (i=b->ins; i-b->ins < b->nins; i++) eins(*i, fn, f); switch (b->jmp.type) { - case JRet: + case JRet0: for (r=&rclob[NRClob]; r>rclob;) if (fn->reg & BIT(*--r)) emitf(fn, f, "pop%w %R", 1, TMP(*r)); diff --git a/lisc/lisc.h b/lisc/lisc.h index 43713a5..0678b13 100644 --- a/lisc/lisc.h +++ b/lisc/lisc.h @@ -165,7 +165,10 @@ enum Op { enum Jmp { JXXX, - JRet, + JRet0, + JRetw, + JRetl, + JRetc, JJmp, JJnz, JXJc, @@ -201,6 +204,7 @@ struct Blk { struct { short type; Ref arg; + int rettyn; } jmp; Blk *s1; Blk *s2; diff --git a/lisc/parse.c b/lisc/parse.c index 10e1636..2e84249 100644 --- a/lisc/parse.c +++ b/lisc/parse.c @@ -116,6 +116,8 @@ static Blk *bmap[NBlk+1]; static Blk *curb; static Blk **blink; static int nblk; +static int rcls; +static int rtyn; void * @@ -508,7 +510,13 @@ parseline(PState ps) expect(TNL); return PPhi; case TRet: - curb->jmp.type = JRet; + curb->jmp.type = (int[]){ + JRetw, JRetl, + JRetc, JRet0 + }[rcls]; + curb->jmp.rettyn = rtyn; + if (rcls < 3) + curb->jmp.arg = parseref(); goto Close; case TJmp: curb->jmp.type = JJmp; @@ -611,6 +619,10 @@ parsefn() PState ps; Fn *fn; + if (peek() != TGlo) + rcls = parsecls(&rtyn); + else + rcls = 3; if (next() != TGlo) err("function name expected"); for (i=0; i<NBlk; i++) @@ -807,6 +819,10 @@ void printfn(Fn *fn, FILE *f) { static char *jtoa[NJmp] = { + [JRet0] = "ret", + [JRetw] = "retw", + [JRetl] = "retl", + [JRetc] = "retc", [JJnz] = "jnz", #define X(c) [JXJc+C##c] = "xj" #c, CMPS(X) @@ -865,8 +881,15 @@ printfn(Fn *fn, FILE *f) fprintf(f, "\n"); } switch (b->jmp.type) { - case JRet: - fprintf(f, "\tret\n"); + case JRet0: + case JRetw: + case JRetl: + case JRetc: + fprintf(f, "\t%s", jtoa[b->jmp.type]); + if (b->jmp.type != JRet0) { + fprintf(f, " "); + printref(b->jmp.arg, fn, f); + } break; case JJmp: if (b->s1 != b->link) |