]> Cypherpunks repositories - gostls13.git/commitdiff
convert string runtime to use cgo.
authorRuss Cox <rsc@golang.org>
Wed, 1 Jul 2009 03:01:50 +0000 (20:01 -0700)
committerRuss Cox <rsc@golang.org>
Wed, 1 Jul 2009 03:01:50 +0000 (20:01 -0700)
now that cgo2c can handle it,
merge x.c and x_go.cgo into
a single x.cgo, for x=float,malloc,sema.

R=r
DELTA=1950  (954 added, 996 deleted, 0 changed)
OCL=30951
CL=30964

src/pkg/runtime/Makefile
src/pkg/runtime/float.cgo [moved from src/pkg/runtime/float.c with 78% similarity]
src/pkg/runtime/float_go.cgo [deleted file]
src/pkg/runtime/malloc.cgo [moved from src/pkg/runtime/malloc.c with 95% similarity]
src/pkg/runtime/malloc_go.cgo [deleted file]
src/pkg/runtime/sema.cgo [moved from src/pkg/runtime/sema.c with 96% similarity]
src/pkg/runtime/sema_go.cgo [deleted file]
src/pkg/runtime/string.cgo [moved from src/pkg/runtime/string.c with 80% similarity]

index e1c320ca81057d97f0e4006b5af173a24fcf822d..4e932b0525e90dcb2bfe2874932cb5533c654960 100644 (file)
@@ -47,11 +47,9 @@ OFILES=\
        closure.$O\
        extern.$O\
        float.$O\
-       float_go.$O\
        hashmap.$O\
        iface.$O\
        malloc.$O\
-       malloc_go.$O\
        mcache.$O\
        mcentral.$O\
        mem.$O\
@@ -66,7 +64,6 @@ OFILES=\
        runtime.$O\
        rt0.$O\
        sema.$O\
-       sema_go.$O\
        signal.$O\
        string.$O\
        symtab.$O\
similarity index 78%
rename from src/pkg/runtime/float.c
rename to src/pkg/runtime/float.cgo
index 5122f359a7bff5a10b21c7304189f2ef2099fd1a..38114aa85444d6614a72d13851d7c1ec21372d65 100644 (file)
@@ -2,6 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+package math
 #include "runtime.h"
 
 static uint64  uvnan           = 0x7FF0000000000001ULL;
@@ -171,3 +172,47 @@ modf(float64 d, float64 *ip)
        return d - dd;
 }
 
+func Frexp(f float64) (frac float64, exp int32) {
+       frac = frexp(f, &exp);
+}
+
+func Ldexp(frac float64, exp int32) (f float64) {
+       f = ldexp(frac, exp);
+}
+
+func Modf(f float64) (integer float64, frac float64) {
+       frac = modf(f, &integer);
+}
+
+func IsInf(f float64, sign int32) (is bool) {
+       is = isInf(f, sign);
+}
+
+func IsNaN(f float64) (is bool) {
+       is = isNaN(f);
+}
+
+func Inf(sign int32) (f float64) {
+       f = Inf(sign);
+}
+
+func NaN() (f float64) {
+       f = NaN();
+}
+
+func Float32bits(f float32) (b uint32) {
+       b = float32tobits(f);
+}
+
+func Float64bits(f float64) (b uint64) {
+       b = float64tobits(f);
+}
+
+func Float32frombits(b uint32) (f float32) {
+       f = float32frombits(b);
+}
+
+func Float64frombits(b uint64) (f float64) {
+       f = float64frombits(b);
+}
+
diff --git a/src/pkg/runtime/float_go.cgo b/src/pkg/runtime/float_go.cgo
deleted file mode 100644 (file)
index 518d559..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2009 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package math
-
-#include "runtime.h"
-
-func Frexp(f float64) (frac float64, exp int32) {
-       frac = frexp(f, &exp);
-}
-
-func Ldexp(frac float64, exp int32) (f float64) {
-       f = ldexp(frac, exp);
-}
-
-func Modf(f float64) (integer float64, frac float64) {
-       frac = modf(f, &integer);
-}
-
-func IsInf(f float64, sign int32) (is bool) {
-       is = isInf(f, sign);
-}
-
-func IsNaN(f float64) (is bool) {
-       is = isNaN(f);
-}
-
-func Inf(sign int32) (f float64) {
-       f = Inf(sign);
-}
-
-func NaN() (f float64) {
-       f = NaN();
-}
-
-func Float32bits(f float32) (b uint32) {
-       b = float32tobits(f);
-}
-
-func Float64bits(f float64) (b uint64) {
-       b = float64tobits(f);
-}
-
-func Float32frombits(b uint32) (f float32) {
-       f = float32frombits(b);
-}
-
-func Float64frombits(b uint64) (f float64) {
-       f = float64frombits(b);
-}
-
similarity index 95%
rename from src/pkg/runtime/malloc.c
rename to src/pkg/runtime/malloc.cgo
index 84c802f94a98a8464ec207d26eb61b70da2f5378..0fdb13d95aed01358442687607a52ffeb354e664 100644 (file)
@@ -7,6 +7,7 @@
 // TODO(rsc): double-check stats.
 // TODO(rsc): solve "stack overflow during malloc" problem.
 
+package malloc
 #include "runtime.h"
 #include "malloc.h"
 #include "defs.h"
@@ -306,3 +307,23 @@ stackfree(void *v)
        }
        free(v);
 }
+
+func Alloc(n uintptr) (p *byte) {
+       p = malloc(n);
+}
+
+func Free(p *byte) {
+       free(p);
+}
+
+func Lookup(p *byte) (base *byte, size uintptr) {
+       mlookup(p, &base, &size, nil);
+}
+
+func GetStats() (s *MStats) {
+       s = &mstats;
+}
+
+func GC() {
+       gc(1);
+}
diff --git a/src/pkg/runtime/malloc_go.cgo b/src/pkg/runtime/malloc_go.cgo
deleted file mode 100644 (file)
index 6dcdaec..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright 2009 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package malloc
-#include "runtime.h"
-#include "malloc.h"
-
-func Alloc(n uintptr) (p *byte) {
-       p = malloc(n);
-}
-
-func Free(p *byte) {
-       free(p);
-}
-
-func Lookup(p *byte) (base *byte, size uintptr) {
-       mlookup(p, &base, &size, nil);
-}
-
-func GetStats() (s *MStats) {
-       s = &mstats;
-}
-
-func GC() {
-       gc(1);
-}
-
similarity index 96%
rename from src/pkg/runtime/sema.c
rename to src/pkg/runtime/sema.cgo
index 5e5b07aa6ff5952c1cf500864cf4242e2e42704c..81834ae6dc20950339dd59db9d591a71dc4c4bb4 100644 (file)
@@ -17,6 +17,7 @@
 // See Mullender and Cox, ``Semaphores in Plan 9,''
 // http://swtch.com/semaphore.pdf
 
+package sync
 #include "runtime.h"
 
 typedef struct Sema Sema;
@@ -174,3 +175,11 @@ semrelease(uint32 *addr)
        }
        semwakeup(addr);
 }
+
+func semacquire(addr *uint32) {
+       semacquire(addr);
+}
+
+func semrelease(addr *uint32) {
+       semrelease(addr);
+}
diff --git a/src/pkg/runtime/sema_go.cgo b/src/pkg/runtime/sema_go.cgo
deleted file mode 100644 (file)
index eb4082a..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright 2009 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package sync
-#include "runtime.h"
-
-func semacquire(addr *uint32) {
-       semacquire(addr);
-}
-
-func semrelease(addr *uint32) {
-       semrelease(addr);
-}
-
similarity index 80%
rename from src/pkg/runtime/string.c
rename to src/pkg/runtime/string.cgo
index 5bfe8196f75e88262a3924250fdff0a682f69557..c91a7507e6491277bf368e79884393cdc735b48e 100644 (file)
@@ -2,6 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+package sys
 #include "runtime.h"
 
 String emptystring;
@@ -46,9 +47,7 @@ gostring(byte *str)
        return s;
 }
 
-void
-sys·catstring(String s1, String s2, String s3)
-{
+func catstring(s1 String, s2 String) (s3 String) {
        if(s1.len == 0) {
                s3 = s2;
                goto out;
@@ -61,9 +60,7 @@ sys·catstring(String s1, String s2, String s3)
        s3 = gostringsize(s1.len + s2.len);
        mcpy(s3.str, s1.str, s1.len);
        mcpy(s3.str+s1.len, s2.str, s2.len);
-
 out:
-       FLUSH(&s3);
 }
 
 static void
@@ -104,11 +101,8 @@ cmpstring(String s1, String s2)
        return 0;
 }
 
-void
-sys·cmpstring(String s1, String s2, int32 v)
-{
+func cmpstring(s1 String, s2 String) (v int32) {
        v = cmpstring(s1, s2);
-       FLUSH(&v);
 }
 
 int32
@@ -129,9 +123,7 @@ strcmp(byte *s1, byte *s2)
        }
 }
 
-void
-sys·slicestring(String si, int32 lindex, int32 hindex, String so)
-{
+func slicestring(si String, lindex int32, hindex int32) (so String) {
        int32 l;
 
        if(lindex < 0 || lindex > si.len ||
@@ -148,13 +140,9 @@ sys·slicestring(String si, int32 lindex, int32 hindex, String so)
 //     alternate to create a new string
 //     so = gostringsize(l);
 //     mcpy(so.str, si.str+lindex, l);
-
-       FLUSH(&so);
 }
 
-void
-sys·indexstring(String s, int32 i, byte b)
-{
+func indexstring(s String, i int32) (b byte) {
        if(i < 0 || i >= s.len) {
                sys·printpc(&s);
                prints(" ");
@@ -162,28 +150,20 @@ sys·indexstring(String s, int32 i, byte b)
        }
 
        b = s.str[i];
-       FLUSH(&b);
 }
 
-void
-sys·intstring(int64 v, String s)
-{
+func intstring(v int64) (s String) {
        s = gostringsize(8);
        s.len = runetochar(s.str, v);
-       FLUSH(&s);
 }
 
-void
-sys·arraystring(Array b, String s)
-{
+func arraystring(b Array) (s String) {
        s = gostringsize(b.nel);
        mcpy(s.str, b.array, s.len);
-       FLUSH(&s);
 }
 
-void
-sys·arraystringi(Array b, String s)
-{
+
+func arraystringi(b Array) (s String) {
        int32 siz1, siz2, i;
        int32 *a;
        byte dum[8];
@@ -203,8 +183,6 @@ sys·arraystringi(Array b, String s)
                siz2 += runetochar(s.str+siz2, a[i]);
        }
        s.len = siz2;
-
-       FLUSH(&s);
 }
 
 enum
@@ -212,10 +190,7 @@ enum
        Runeself        = 0x80,
 };
 
-// func        stringiter(string, int) (retk int);
-void
-sys·stringiter(String s, int32 k, int32 retk)
-{
+func stringiter(s String, k int32) (retk int32) {
        int32 l;
 
        if(k >= s.len) {
@@ -234,13 +209,9 @@ sys·stringiter(String s, int32 k, int32 retk)
        retk = k + charntorune(&l, s.str+k, s.len-k);
 
 out:
-       FLUSH(&retk);
 }
 
-// func        stringiter2(string, int) (retk int, retv any);
-void
-sys·stringiter2(String s, int32 k, int32 retk, int32 retv)
-{
+func stringiter2(s String, k int32) (retk int32, retv int32) {
        if(k >= s.len) {
                // retk=0 is end of iteration
                retk = 0;
@@ -258,6 +229,4 @@ sys·stringiter2(String s, int32 k, int32 retk, int32 retv)
        retk = k + charntorune(&retv, s.str+k, s.len-k);
 
 out:
-       FLUSH(&retk);
-       FLUSH(&retv);
 }