From 98c5a405bb34d69d1d8188f704226d24267fead6 Mon Sep 17 00:00:00 2001 From: Quentin Carbonneaux Date: Tue, 22 Sep 2015 16:52:48 -0400 Subject: parse return types of functions --- lisc/emit.c | 2 +- lisc/lisc.h | 6 +++++- lisc/parse.c | 29 ++++++++++++++++++++++++++--- 3 files changed, 32 insertions(+), 5 deletions(-) (limited to 'lisc') 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; ijmp.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) -- cgit 1.4.1