From 2b53bca326decd50012883f0cff3b5316a3e100d Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Tue, 19 Oct 2021 13:28:01 -0700 Subject: feat(rc): prototype of async jobs --- sys/cmd/rc/code.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'sys/cmd/rc/code.c') diff --git a/sys/cmd/rc/code.c b/sys/cmd/rc/code.c index c98cde2..719e63b 100644 --- a/sys/cmd/rc/code.c +++ b/sys/cmd/rc/code.c @@ -30,7 +30,7 @@ grow(void) static void -stashaddr(int a) +storepc(int a) { if(interpreter.i <= a || a < 0) fatal("bad address %d in interpreter", a); @@ -42,8 +42,8 @@ static void walk(Tree *node) { - int p; Tree *n; + int addr; if(!node) return; @@ -72,17 +72,6 @@ walk(Tree *node) emitf(Xflat); break; - case Tindex: - -#if 0 - case '&': - emitf(Xasync); - p = emiti(0); - emitf(Xexit); - stashaddr(p); - break; -#endif - case ';': walk(node->child[0]); walk(node->child[1]); @@ -113,6 +102,14 @@ walk(Tree *node) emitf(Xbasic); break; + case '&': + emitf(Xasync); + addr = emiti(0); + walk(node->child[0]); + emitf(Xexit); + storepc(addr); + break; + case Tword: emitf(Xword); emits(strdup(node->str)); @@ -173,18 +170,16 @@ int compile(Tree *node) { flush(shell.err); - //print(errio, "%t\n", node); interpreter.i = 0; interpreter.code = emalloc(100*sizeof(*interpreter.code)); - - emiti(1); // reference count + emiti(0); // reference count: no thread owns code yet walk(node); emitf(Xreturn); emitf(nil); - compiled = interpreter.code; + compiled = interpreter.code; return 0; } -- cgit v1.2.1