shithub: riscv

Download patch

ref: b6251bff913972b5dfb421813fe97a5bfff3627f
parent: 196da4ec6f429683a351312d1f0bcb05847e7f89
author: cinap_lenrek <[email protected]>
date: Sat Nov 17 23:56:48 EST 2018

rc: implement $"x in terms of Xdol() and new Xqw() instruction

to get $"1 right, remove Xqdol() and instead implement it in
terms of Xdol() instruction and use the new Xqw() instruction
to quote the resulting list.

--- a/sys/src/cmd/rc/code.c
+++ b/sys/src/cmd/rc/code.c
@@ -96,8 +96,10 @@
 		break;
 	case '"':
 		emitf(Xmark);
+		emitf(Xmark);
 		outcode(c0, eflag);
-		emitf(Xqdol);
+		emitf(Xdol);
+		emitf(Xqw);
 		break;
 	case SUB:
 		emitf(Xmark);
--- a/sys/src/cmd/rc/exec.c
+++ b/sys/src/cmd/rc/exec.c
@@ -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(list)				quote list, push result
  * 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*
--- a/sys/src/cmd/rc/exec.h
+++ b/sys/src/cmd/rc/exec.h
@@ -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);
--- a/sys/src/cmd/rc/pfnc.c
+++ b/sys/src/cmd/rc/pfnc.c
@@ -50,7 +50,7 @@
 	Xglobs, "Xglobs",
 	Xrdfn, "Xrdfn",
 	Xsimple, "Xsimple",
-	Xqdol, "Xqdol",
+	Xqw, "Xqw",
 0};
 
 void