From 04f9470ee130b6877edcaa202c0a143c9a48fced Mon Sep 17 00:00:00 2001 From: "Charles.Forsyth" Date: Fri, 1 Feb 2008 18:46:35 +0000 Subject: 20080201-1852 --- appl/cmd/limbo/com.b | 8 ++++++-- appl/cmd/limbo/gen.b | 2 -- dis/limbo.dis | Bin 343192 -> 343278 bytes limbo/com.c | 12 +++++++++--- limbo/gen.c | 2 -- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/appl/cmd/limbo/com.b b/appl/cmd/limbo/com.b index c14cd923..320d209c 100644 --- a/appl/cmd/limbo/com.b +++ b/appl/cmd/limbo/com.b @@ -388,10 +388,14 @@ fncom(decl: ref Decl) scom(n.left); } pushblock(); - in := genrawop(src, IRET, nil, nil, nil); + valued := decl.ty.tof != tnone; + if(valued) + in := genrawop(src, IRAISE, nil, nil, nil); + else + in = genrawop(src, IRET, nil, nil, nil); popblock(); reach(decl.pc); - if(in.reach != byte 0 && decl.ty.tof != tnone) + if(valued && in.reach != byte 0) error(src.start, "no return at end of function " + dotconv(decl)); # decl.endpc = lastinst; if(labdep != 0) diff --git a/appl/cmd/limbo/gen.b b/appl/cmd/limbo/gen.b index 10988f48..ab4bb6af 100644 --- a/appl/cmd/limbo/gen.b +++ b/appl/cmd/limbo/gen.b @@ -562,8 +562,6 @@ foldbranch(in: ref Inst) next := in.next; *in = *b; in.next = next; - if(b.op == IRET) - b.reach = byte 1; # might be default return (TO DO) continue; } foldbranch(in.branch); diff --git a/dis/limbo.dis b/dis/limbo.dis index 445c1d3a..e455128c 100644 Binary files a/dis/limbo.dis and b/dis/limbo.dis differ diff --git a/limbo/com.c b/limbo/com.c index 1bc070a4..967d17b0 100644 --- a/limbo/com.c +++ b/limbo/com.c @@ -368,6 +368,7 @@ fncom(Decl *decl) Node *n; Decl *loc, *last; Inst *in; + int valued; curfn = decl; if(ispoly(decl)) @@ -410,10 +411,11 @@ fncom(Decl *decl) scom(n->left); } pushblock(); - in = genrawop(&src, IRET, nil, nil, nil); + valued = decl->ty->tof != tnone; + in = genrawop(&src, valued? IRAISE: IRET, nil, nil, nil); popblock(); reach(decl->pc); - if(in->reach && decl->ty->tof != tnone) + if(valued && in->reach) error(src.start, "no return at end of function %D", decl); /* decl->endpc = lastinst; */ if(labdep != 0) @@ -1435,6 +1437,9 @@ ret(Node *n, int nilret) return n->op == Oret && n->left == nil; } +/* + * tail-recursive call + */ static int trcom(Node *e, Node *ne, int nilret) { @@ -1442,7 +1447,8 @@ trcom(Node *e, Node *ne, int nilret) Node *as, *a, *f, *n; Inst *p; -return 0; // TBS + if(1) + return 0; /* TO DO: should we enable this? */ if(e->op != Ocall || e->left->op != Oname) return 0; d = e->left->decl; diff --git a/limbo/gen.c b/limbo/gen.c index 64dce6e5..fe77dc80 100644 --- a/limbo/gen.c +++ b/limbo/gen.c @@ -590,8 +590,6 @@ foldbranch(Inst *in) next = in->next; *in = *b; in->next = next; - if(b->op == IRET) - b->reach = 1; /* might be default return (TO DO) */ continue; } foldbranch(b); -- cgit v1.2.3