aboutsummaryrefslogtreecommitdiff
path: root/sys/cmd/rc/code.c
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2021-10-19 13:28:01 -0700
committerNicholas Noll <nbnoll@eml.cc>2021-10-19 13:28:01 -0700
commit2b53bca326decd50012883f0cff3b5316a3e100d (patch)
tree570220ba22df388958e296f09add682720de6b51 /sys/cmd/rc/code.c
parentaf3fa90e8bb41c306c5fe2d2cf105db6bbabd1d9 (diff)
feat(rc): prototype of async jobs
Diffstat (limited to 'sys/cmd/rc/code.c')
-rw-r--r--sys/cmd/rc/code.c29
1 files changed, 12 insertions, 17 deletions
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;
}