From: cinap_lenrek@felloff.net
To: 9front@9front.org
Subject: Re: [9front] man rc patch
Date: Thu, 15 Nov 2018 20:17:30 +0100 [thread overview]
Message-ID: <208E79E7184B1585DBEC2E7B5BB422B7@felloff.net> (raw)
In-Reply-To: BF76DDEC3ABAB8EB078F0BDE14A1B4FD@felloff.net
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
next reply other threads:[~2018-11-15 19:17 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-15 19:17 cinap_lenrek [this message]
-- strict thread matches above, loose matches on Subject: below --
2018-11-16 7:32 cinap_lenrek
2018-11-16 0:47 Alex Musolino
2018-11-15 18:00 cinap_lenrek
2018-11-11 6:59 Alex Musolino
2018-11-11 11:32 ` Ethan Gardener
2018-11-11 17:14 ` Joe M
2018-11-11 17:16 ` Joe M
2018-11-14 15:56 ` Ethan Gardener
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=208E79E7184B1585DBEC2E7B5BB422B7@felloff.net \
--to=cinap_lenrek@felloff.net \
--cc=9front@9front.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).