From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from duke.felloff.net ([216.126.196.34]) by ewsd; Thu Nov 15 14:17:37 EST 2018 Message-ID: <208E79E7184B1585DBEC2E7B5BB422B7@felloff.net> Date: Thu, 15 Nov 2018 20:17:30 +0100 From: cinap_lenrek@felloff.net To: 9front@9front.org Subject: Re: [9front] man rc patch In-Reply-To: BF76DDEC3ABAB8EB078F0BDE14A1B4FD@felloff.net MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: SVG full-stack STM frontend consider this approach: we remove the Xqdol() instruction and instead add a Xqw() instruction that pops a word list and then pushes the quoted string. $"x is handled as Xmark, Xmark, ...x..., Xdol, Xqw one optimization is that we just exchange pointers when the wordlist consists of just one item, avoiding the string copy/free/alloc. does this make sense? diff -r f1e9a71d650a sys/src/cmd/rc/code.c --- a/sys/src/cmd/rc/code.c Wed Nov 14 09:12:34 2018 +0100 +++ b/sys/src/cmd/rc/code.c Thu Nov 15 20:10:15 2018 +0100 @@ -96,8 +96,10 @@ break; case '"': emitf(Xmark); + emitf(Xmark); outcode(c0, eflag); - emitf(Xqdol); + emitf(Xdol); + emitf(Xqw); break; case SUB: emitf(Xmark); diff -r f1e9a71d650a sys/src/cmd/rc/exec.c --- a/sys/src/cmd/rc/exec.c Wed Nov 14 09:12:34 2018 +0100 +++ b/sys/src/cmd/rc/exec.c Thu Nov 15 20:10:15 2018 +0100 @@ -233,7 +233,7 @@ * Xdelfn(name) delete function definition * Xdeltraps(names) delete named traps * Xdol(name) get variable value - * Xqdol(name) concatenate variable components + * Xqw(words) quote word list * Xdup[i j] dup file descriptor * Xexit rc exits with status * Xfalse{...} execute {} if false @@ -697,18 +697,22 @@ } void -Xqdol(void) +Xqw(void) { char *s; word *a; - if(count(runq->argv->words)!=1){ - Xerror1("variable name not singleton!"); + + a = runq->argv->words; + if(a && a->next == 0){ + runq->argv->words = 0; + poplist(); + a->next = runq->argv->words; + runq->argv->words = a; return; } - s = Str(runq->argv->words); - a = vlook(s)->val; + s = list2str(a); poplist(); - Pushword(list2str(a)); + Pushword(s); } word* diff -r f1e9a71d650a sys/src/cmd/rc/exec.h --- a/sys/src/cmd/rc/exec.h Wed Nov 14 09:12:34 2018 +0100 +++ b/sys/src/cmd/rc/exec.h Thu Nov 15 20:10:15 2018 +0100 @@ -2,7 +2,7 @@ * Definitions used in the interpreter */ extern void Xappend(void), Xasync(void), Xbackq(void), Xbang(void), Xclose(void); -extern void Xconc(void), Xcount(void), Xdelfn(void), Xdol(void), Xqdol(void), Xdup(void); +extern void Xconc(void), Xcount(void), Xdelfn(void), Xdol(void), Xqw(void), Xdup(void); extern void Xexit(void), Xfalse(void), Xfn(void), Xfor(void), Xglob(void); extern void Xjump(void), Xmark(void), Xmatch(void), Xpipe(void), Xread(void); extern void Xrdwr(void); diff -r f1e9a71d650a sys/src/cmd/rc/pfnc.c --- a/sys/src/cmd/rc/pfnc.c Wed Nov 14 09:12:34 2018 +0100 +++ b/sys/src/cmd/rc/pfnc.c Thu Nov 15 20:10:15 2018 +0100 @@ -50,7 +50,7 @@ Xglobs, "Xglobs", Xrdfn, "Xrdfn", Xsimple, "Xsimple", - Xqdol, "Xqdol", + Xqw, "Xqw", 0}; void -- cinap