Commit fa40c856 authored by Russ Cox's avatar Russ Cox

convert string runtime to use cgo.

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
parent 88e7fd54
...@@ -47,11 +47,9 @@ OFILES=\ ...@@ -47,11 +47,9 @@ OFILES=\
closure.$O\ closure.$O\
extern.$O\ extern.$O\
float.$O\ float.$O\
float_go.$O\
hashmap.$O\ hashmap.$O\
iface.$O\ iface.$O\
malloc.$O\ malloc.$O\
malloc_go.$O\
mcache.$O\ mcache.$O\
mcentral.$O\ mcentral.$O\
mem.$O\ mem.$O\
...@@ -66,7 +64,6 @@ OFILES=\ ...@@ -66,7 +64,6 @@ OFILES=\
runtime.$O\ runtime.$O\
rt0.$O\ rt0.$O\
sema.$O\ sema.$O\
sema_go.$O\
signal.$O\ signal.$O\
string.$O\ string.$O\
symtab.$O\ symtab.$O\
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package math
#include "runtime.h" #include "runtime.h"
static uint64 uvnan = 0x7FF0000000000001ULL; static uint64 uvnan = 0x7FF0000000000001ULL;
...@@ -171,3 +172,47 @@ modf(float64 d, float64 *ip) ...@@ -171,3 +172,47 @@ modf(float64 d, float64 *ip)
return d - dd; 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);
}
// 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);
}
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
// TODO(rsc): double-check stats. // TODO(rsc): double-check stats.
// TODO(rsc): solve "stack overflow during malloc" problem. // TODO(rsc): solve "stack overflow during malloc" problem.
package malloc
#include "runtime.h" #include "runtime.h"
#include "malloc.h" #include "malloc.h"
#include "defs.h" #include "defs.h"
...@@ -306,3 +307,23 @@ stackfree(void *v) ...@@ -306,3 +307,23 @@ stackfree(void *v)
} }
free(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);
}
// 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);
}
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
// See Mullender and Cox, ``Semaphores in Plan 9,'' // See Mullender and Cox, ``Semaphores in Plan 9,''
// http://swtch.com/semaphore.pdf // http://swtch.com/semaphore.pdf
package sync
#include "runtime.h" #include "runtime.h"
typedef struct Sema Sema; typedef struct Sema Sema;
...@@ -174,3 +175,11 @@ semrelease(uint32 *addr) ...@@ -174,3 +175,11 @@ semrelease(uint32 *addr)
} }
semwakeup(addr); semwakeup(addr);
} }
func semacquire(addr *uint32) {
semacquire(addr);
}
func semrelease(addr *uint32) {
semrelease(addr);
}
// 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);
}
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package sys
#include "runtime.h" #include "runtime.h"
String emptystring; String emptystring;
...@@ -46,9 +47,7 @@ gostring(byte *str) ...@@ -46,9 +47,7 @@ gostring(byte *str)
return s; return s;
} }
void func catstring(s1 String, s2 String) (s3 String) {
sys·catstring(String s1, String s2, String s3)
{
if(s1.len == 0) { if(s1.len == 0) {
s3 = s2; s3 = s2;
goto out; goto out;
...@@ -61,9 +60,7 @@ sys·catstring(String s1, String s2, String s3) ...@@ -61,9 +60,7 @@ sys·catstring(String s1, String s2, String s3)
s3 = gostringsize(s1.len + s2.len); s3 = gostringsize(s1.len + s2.len);
mcpy(s3.str, s1.str, s1.len); mcpy(s3.str, s1.str, s1.len);
mcpy(s3.str+s1.len, s2.str, s2.len); mcpy(s3.str+s1.len, s2.str, s2.len);
out: out:
FLUSH(&s3);
} }
static void static void
...@@ -104,11 +101,8 @@ cmpstring(String s1, String s2) ...@@ -104,11 +101,8 @@ cmpstring(String s1, String s2)
return 0; return 0;
} }
void func cmpstring(s1 String, s2 String) (v int32) {
sys·cmpstring(String s1, String s2, int32 v)
{
v = cmpstring(s1, s2); v = cmpstring(s1, s2);
FLUSH(&v);
} }
int32 int32
...@@ -129,9 +123,7 @@ strcmp(byte *s1, byte *s2) ...@@ -129,9 +123,7 @@ strcmp(byte *s1, byte *s2)
} }
} }
void func slicestring(si String, lindex int32, hindex int32) (so String) {
sys·slicestring(String si, int32 lindex, int32 hindex, String so)
{
int32 l; int32 l;
if(lindex < 0 || lindex > si.len || if(lindex < 0 || lindex > si.len ||
...@@ -148,13 +140,9 @@ sys·slicestring(String si, int32 lindex, int32 hindex, String so) ...@@ -148,13 +140,9 @@ sys·slicestring(String si, int32 lindex, int32 hindex, String so)
// alternate to create a new string // alternate to create a new string
// so = gostringsize(l); // so = gostringsize(l);
// mcpy(so.str, si.str+lindex, l); // mcpy(so.str, si.str+lindex, l);
FLUSH(&so);
} }
void func indexstring(s String, i int32) (b byte) {
sys·indexstring(String s, int32 i, byte b)
{
if(i < 0 || i >= s.len) { if(i < 0 || i >= s.len) {
sys·printpc(&s); sys·printpc(&s);
prints(" "); prints(" ");
...@@ -162,28 +150,20 @@ sys·indexstring(String s, int32 i, byte b) ...@@ -162,28 +150,20 @@ sys·indexstring(String s, int32 i, byte b)
} }
b = s.str[i]; b = s.str[i];
FLUSH(&b);
} }
void func intstring(v int64) (s String) {
sys·intstring(int64 v, String s)
{
s = gostringsize(8); s = gostringsize(8);
s.len = runetochar(s.str, v); s.len = runetochar(s.str, v);
FLUSH(&s);
} }
void func arraystring(b Array) (s String) {
sys·arraystring(Array b, String s)
{
s = gostringsize(b.nel); s = gostringsize(b.nel);
mcpy(s.str, b.array, s.len); 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 siz1, siz2, i;
int32 *a; int32 *a;
byte dum[8]; byte dum[8];
...@@ -203,8 +183,6 @@ sys·arraystringi(Array b, String s) ...@@ -203,8 +183,6 @@ sys·arraystringi(Array b, String s)
siz2 += runetochar(s.str+siz2, a[i]); siz2 += runetochar(s.str+siz2, a[i]);
} }
s.len = siz2; s.len = siz2;
FLUSH(&s);
} }
enum enum
...@@ -212,10 +190,7 @@ enum ...@@ -212,10 +190,7 @@ enum
Runeself = 0x80, Runeself = 0x80,
}; };
// func stringiter(string, int) (retk int); func stringiter(s String, k int32) (retk int32) {
void
sys·stringiter(String s, int32 k, int32 retk)
{
int32 l; int32 l;
if(k >= s.len) { if(k >= s.len) {
...@@ -234,13 +209,9 @@ sys·stringiter(String s, int32 k, int32 retk) ...@@ -234,13 +209,9 @@ sys·stringiter(String s, int32 k, int32 retk)
retk = k + charntorune(&l, s.str+k, s.len-k); retk = k + charntorune(&l, s.str+k, s.len-k);
out: out:
FLUSH(&retk);
} }
// func stringiter2(string, int) (retk int, retv any); func stringiter2(s String, k int32) (retk int32, retv int32) {
void
sys·stringiter2(String s, int32 k, int32 retk, int32 retv)
{
if(k >= s.len) { if(k >= s.len) {
// retk=0 is end of iteration // retk=0 is end of iteration
retk = 0; retk = 0;
...@@ -258,6 +229,4 @@ sys·stringiter2(String s, int32 k, int32 retk, int32 retv) ...@@ -258,6 +229,4 @@ sys·stringiter2(String s, int32 k, int32 retk, int32 retv)
retk = k + charntorune(&retv, s.str+k, s.len-k); retk = k + charntorune(&retv, s.str+k, s.len-k);
out: out:
FLUSH(&retk);
FLUSH(&retv);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment