aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/rc/exec.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/rc/exec.c')
-rw-r--r--src/cmd/rc/exec.c42
1 files changed, 39 insertions, 3 deletions
diff --git a/src/cmd/rc/exec.c b/src/cmd/rc/exec.c
index 2bdaebd..71f5359 100644
--- a/src/cmd/rc/exec.c
+++ b/src/cmd/rc/exec.c
@@ -336,9 +336,26 @@ run(Code *c, int pc, Var *local, int inherit)
runner = new;
}
+
// -----------------------------------------------------------------------
// exported builtins
+void
+xfunc(Var *v)
+{
+ Word *star;
+ popword(); // "func"
+ star = runner->args->word;
+ runner->args->word = nil;
+ poplist(); // args
+
+ run(v->func.code, v->func.start, runner->local, 1);
+
+ runner->local = makevar(strdup("*"), runner->local);
+ runner->local->val = star;
+ runner->local->new = 1;
+}
+
// XXX: find a better place for these
Word*
makeword(char *str, Word *link)
@@ -1062,6 +1079,26 @@ Xunlocal(void)
}
void
+Xfunc(void)
+{
+ Var *v;
+ Word *arg;
+ int end;
+
+ end = runner->code.exe[runner->code.i].i;
+ for(arg=runner->args->word; arg; arg=arg->link){
+ v = var(arg->str);
+ if(v->func.code)
+ freecode(v->func.code);
+ v->func.code = copycode(runner->code.exe);
+ v->func.start = runner->code.i+2;
+ v->newfunc = 1;
+ }
+ runner->code.i = end;
+ poplist();
+}
+
+void
Xasync(void)
{
int pid;
@@ -1193,9 +1230,8 @@ Xbasic(void)
}
v = var(arg->str);
- if(v->func){
- return;
- }
+ if(v->func.code)
+ return xfunc(v);
// see if it matches a builtin
for(b = builtin; b->name; b++){