aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKen Thompson <ken@golang.org>2009-05-27 15:38:02 -0700
committerKen Thompson <ken@golang.org>2009-05-27 15:38:02 -0700
commit64c3fe05bf16ea9107be5a7e4257db86addb6d08 (patch)
tree53679547ef5d85a5c4f7302329f7e0817efcd87c /src
parent18890eebbf27fec3b004478fc23443bbd349ba6d (diff)
downloadgo-64c3fe05bf16ea9107be5a7e4257db86addb6d08.tar.xz
string([]int) conversion
R=r OCL=29466 CL=29466
Diffstat (limited to 'src')
-rw-r--r--src/cmd/gc/builtin.c.boot1
-rw-r--r--src/cmd/gc/sys.go1
-rw-r--r--src/cmd/gc/walk.c20
-rw-r--r--src/runtime/string.c22
4 files changed, 43 insertions, 1 deletions
diff --git a/src/cmd/gc/builtin.c.boot b/src/cmd/gc/builtin.c.boot
index 97574f7103..6ee50e035e 100644
--- a/src/cmd/gc/builtin.c.boot
+++ b/src/cmd/gc/builtin.c.boot
@@ -20,6 +20,7 @@ char *sysimport =
"func sys.indexstring (? string, ? int) (? uint8)\n"
"func sys.intstring (? int64) (? string)\n"
"func sys.arraystring (? []uint8) (? string)\n"
+ "func sys.arraystringi (? []int) (? string)\n"
"func sys.stringiter (? string, ? int) (? int)\n"
"func sys.stringiter2 (? string, ? int) (retk int, retv int)\n"
"func sys.ifaceI2E (iface any) (ret any)\n"
diff --git a/src/cmd/gc/sys.go b/src/cmd/gc/sys.go
index 270ca04da4..3a278d9ff9 100644
--- a/src/cmd/gc/sys.go
+++ b/src/cmd/gc/sys.go
@@ -29,6 +29,7 @@ func slicestring(string, int, int) string;
func indexstring(string, int) byte;
func intstring(int64) string;
func arraystring([]byte) string;
+func arraystringi([]int) string;
func stringiter(string, int) int;
func stringiter2(string, int) (retk int, retv int);
diff --git a/src/cmd/gc/walk.c b/src/cmd/gc/walk.c
index e47be30ff4..96cd400541 100644
--- a/src/cmd/gc/walk.c
+++ b/src/cmd/gc/walk.c
@@ -1293,6 +1293,7 @@ walkconv(Node *n)
indir(n, stringop(n, Erv));
return;
}
+
// can convert []byte and *[10]byte
if((isptr[et] && isfixedarray(l->type->type) && istype(l->type->type->type, TUINT8))
|| (isslice(l->type) && istype(l->type->type, TUINT8))) {
@@ -1300,6 +1301,14 @@ walkconv(Node *n)
indir(n, stringop(n, Erv));
return;
}
+
+ // can convert []int and *[10]int
+ if((isptr[et] && isfixedarray(l->type->type) && istype(l->type->type->type, TINT))
+ || (isslice(l->type) && istype(l->type->type, TINT))) {
+ n->op = OARRAY;
+ indir(n, stringop(n, Erv));
+ return;
+ }
}
// convert dynamic to static generated by ONEW/OMAKE
@@ -2450,8 +2459,17 @@ stringop(Node *n, int top)
break;
case OARRAY:
- // arraystring([]byte) string;
r = n->left;
+ if(r->type != T && r->type->type != T) {
+ if(istype(r->type->type, TINT) || istype(r->type->type->type, TINT)) {
+ // arraystring([]byte) string;
+ on = syslook("arraystringi", 0);
+ r = nod(OCALL, on, r);
+ break;
+ }
+ }
+
+ // arraystring([]byte) string;
on = syslook("arraystring", 0);
r = nod(OCALL, on, r);
break;
diff --git a/src/runtime/string.c b/src/runtime/string.c
index d7393ef6ed..04cf06bc3c 100644
--- a/src/runtime/string.c
+++ b/src/runtime/string.c
@@ -181,6 +181,28 @@ sys·arraystring(Array b, String s)
FLUSH(&s);
}
+void
+sys·arraystringi(Array b, String s)
+{
+ int32 siz, i;
+ int32 *a;
+ byte dum[8];
+
+ a = (int32*)b.array;
+ siz = 0;
+ for(i=0; i<b.nel; i++) {
+ siz += runetochar(dum, a[i]);
+ }
+
+ s = gostringsize(siz);
+ siz = 0;
+ for(i=0; i<b.nel; i++) {
+ siz += runetochar(s.str+siz, a[i]);
+ }
+
+ FLUSH(&s);
+}
+
enum
{
Runeself = 0x80,