2008-06-05 20:38:39 -06:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
#include "runtime.h"
|
|
|
|
|
2008-11-05 22:50:28 -07:00
|
|
|
int32 panicking = 0;
|
|
|
|
int32 maxround = 8;
|
2008-06-05 20:38:39 -06:00
|
|
|
|
2008-09-22 14:47:53 -06:00
|
|
|
int32
|
|
|
|
gotraceback(void)
|
|
|
|
{
|
|
|
|
byte *p;
|
|
|
|
|
|
|
|
p = getenv("GOTRACEBACK");
|
|
|
|
if(p == nil || p[0] == '\0')
|
|
|
|
return 1; // default is on
|
|
|
|
return atoi(p);
|
|
|
|
}
|
|
|
|
|
2008-06-16 18:04:30 -06:00
|
|
|
void
|
2008-06-24 18:16:06 -06:00
|
|
|
sys·panicl(int32 lno)
|
2008-06-16 18:04:30 -06:00
|
|
|
{
|
2008-06-19 00:17:39 -06:00
|
|
|
uint8 *sp;
|
|
|
|
|
2008-11-21 00:16:31 -07:00
|
|
|
prints("\npanic ");
|
2008-06-24 18:16:06 -06:00
|
|
|
sys·printpc(&lno);
|
2008-06-16 18:04:30 -06:00
|
|
|
prints("\n");
|
2008-06-19 00:17:39 -06:00
|
|
|
sp = (uint8*)&lno;
|
2008-09-22 14:47:53 -06:00
|
|
|
if(gotraceback()){
|
|
|
|
traceback(sys·getcallerpc(&lno), sp, g);
|
|
|
|
tracebackothers(g);
|
|
|
|
}
|
2008-09-12 10:44:41 -06:00
|
|
|
panicking = 1;
|
|
|
|
sys·breakpoint(); // so we can grab it in a debugger
|
2008-06-24 18:16:06 -06:00
|
|
|
sys·exit(2);
|
2008-06-16 18:04:30 -06:00
|
|
|
}
|
|
|
|
|
2008-09-12 17:48:35 -06:00
|
|
|
void
|
|
|
|
sys·throwindex(void)
|
|
|
|
{
|
|
|
|
throw("index out of range");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sys·throwreturn(void)
|
|
|
|
{
|
|
|
|
throw("no return at end of a typed function");
|
|
|
|
}
|
|
|
|
|
2008-06-16 23:34:50 -06:00
|
|
|
void
|
2008-06-05 20:38:39 -06:00
|
|
|
throw(int8 *s)
|
|
|
|
{
|
|
|
|
prints("throw: ");
|
|
|
|
prints(s);
|
|
|
|
prints("\n");
|
2008-06-24 18:16:06 -06:00
|
|
|
*(int32*)0 = 0;
|
|
|
|
sys·exit(1);
|
2008-06-05 20:38:39 -06:00
|
|
|
}
|
|
|
|
|
2008-06-15 21:24:30 -06:00
|
|
|
void
|
2008-06-05 20:38:39 -06:00
|
|
|
mcpy(byte *t, byte *f, uint32 n)
|
|
|
|
{
|
|
|
|
while(n > 0) {
|
|
|
|
*t = *f;
|
|
|
|
t++;
|
|
|
|
f++;
|
|
|
|
n--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-13 11:35:44 -07:00
|
|
|
void
|
|
|
|
mmov(byte *t, byte *f, uint32 n)
|
|
|
|
{
|
|
|
|
if(t < f) {
|
|
|
|
while(n > 0) {
|
|
|
|
*t = *f;
|
|
|
|
t++;
|
|
|
|
f++;
|
|
|
|
n--;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
t += n;
|
|
|
|
f += n;
|
|
|
|
while(n > 0) {
|
|
|
|
t--;
|
|
|
|
f--;
|
|
|
|
*t = *f;
|
|
|
|
n--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-23 18:08:55 -07:00
|
|
|
byte*
|
|
|
|
mchr(byte *p, byte c, byte *ep)
|
|
|
|
{
|
|
|
|
for(; p < ep; p++)
|
|
|
|
if(*p == c)
|
|
|
|
return p;
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2008-07-13 15:29:46 -06:00
|
|
|
uint32
|
|
|
|
rnd(uint32 n, uint32 m)
|
|
|
|
{
|
|
|
|
uint32 r;
|
|
|
|
|
2008-11-05 22:50:28 -07:00
|
|
|
if(m > maxround)
|
|
|
|
m = maxround;
|
2008-07-13 15:29:46 -06:00
|
|
|
r = n % m;
|
|
|
|
if(r)
|
|
|
|
n += m-r;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2008-08-05 15:18:47 -06:00
|
|
|
static uint64 uvnan = 0x7FF0000000000001ULL;
|
|
|
|
static uint64 uvinf = 0x7FF0000000000000ULL;
|
|
|
|
static uint64 uvneginf = 0xFFF0000000000000ULL;
|
2008-06-30 16:30:47 -06:00
|
|
|
|
2008-11-10 16:17:56 -07:00
|
|
|
static uint32
|
|
|
|
float32tobits(float32 f)
|
|
|
|
{
|
|
|
|
// The obvious cast-and-pointer code is technically
|
|
|
|
// not valid, and gcc miscompiles it. Use a union instead.
|
|
|
|
union {
|
|
|
|
float32 f;
|
|
|
|
uint32 i;
|
|
|
|
} u;
|
|
|
|
u.f = f;
|
|
|
|
return u.i;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint64
|
|
|
|
float64tobits(float64 f)
|
|
|
|
{
|
|
|
|
// The obvious cast-and-pointer code is technically
|
|
|
|
// not valid, and gcc miscompiles it. Use a union instead.
|
|
|
|
union {
|
|
|
|
float64 f;
|
|
|
|
uint64 i;
|
|
|
|
} u;
|
|
|
|
u.f = f;
|
|
|
|
return u.i;
|
|
|
|
}
|
|
|
|
|
|
|
|
static float64
|
|
|
|
float64frombits(uint64 i)
|
|
|
|
{
|
|
|
|
// The obvious cast-and-pointer code is technically
|
|
|
|
// not valid, and gcc miscompiles it. Use a union instead.
|
|
|
|
union {
|
|
|
|
float64 f;
|
|
|
|
uint64 i;
|
|
|
|
} u;
|
|
|
|
u.i = i;
|
|
|
|
return u.f;
|
|
|
|
}
|
|
|
|
|
2008-11-12 12:51:34 -07:00
|
|
|
static float32
|
|
|
|
float32frombits(uint32 i)
|
|
|
|
{
|
|
|
|
// The obvious cast-and-pointer code is technically
|
|
|
|
// not valid, and gcc miscompiles it. Use a union instead.
|
|
|
|
union {
|
|
|
|
float32 f;
|
|
|
|
uint32 i;
|
|
|
|
} u;
|
|
|
|
u.i = i;
|
|
|
|
return u.f;
|
|
|
|
}
|
|
|
|
|
2008-11-10 15:54:10 -07:00
|
|
|
bool
|
2008-11-10 16:17:56 -07:00
|
|
|
isInf(float64 f, int32 sign)
|
2008-06-30 16:30:47 -06:00
|
|
|
{
|
|
|
|
uint64 x;
|
|
|
|
|
2008-11-10 16:17:56 -07:00
|
|
|
x = float64tobits(f);
|
|
|
|
if(sign == 0)
|
|
|
|
return x == uvinf || x == uvneginf;
|
|
|
|
if(sign > 0)
|
|
|
|
return x == uvinf;
|
|
|
|
return x == uvneginf;
|
2008-06-30 16:30:47 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static float64
|
|
|
|
NaN(void)
|
|
|
|
{
|
2008-11-10 16:17:56 -07:00
|
|
|
return float64frombits(uvnan);
|
2008-06-30 16:30:47 -06:00
|
|
|
}
|
|
|
|
|
2008-11-10 15:54:10 -07:00
|
|
|
bool
|
2008-11-10 16:17:56 -07:00
|
|
|
isNaN(float64 f)
|
2008-06-30 16:30:47 -06:00
|
|
|
{
|
|
|
|
uint64 x;
|
|
|
|
|
2008-11-10 16:17:56 -07:00
|
|
|
x = float64tobits(f);
|
|
|
|
return ((uint32)(x>>52) & 0x7FF) == 0x7FF && !isInf(f, 0);
|
2008-06-30 16:30:47 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static float64
|
|
|
|
Inf(int32 sign)
|
|
|
|
{
|
2008-08-11 16:04:54 -06:00
|
|
|
if(sign >= 0)
|
2008-11-10 16:17:56 -07:00
|
|
|
return float64frombits(uvinf);
|
2008-06-30 16:30:47 -06:00
|
|
|
else
|
2008-11-10 16:17:56 -07:00
|
|
|
return float64frombits(uvneginf);
|
2008-06-30 16:30:47 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
MASK = 0x7ffL,
|
|
|
|
SHIFT = 64-11-1,
|
|
|
|
BIAS = 1022L,
|
|
|
|
};
|
|
|
|
|
|
|
|
static float64
|
|
|
|
frexp(float64 d, int32 *ep)
|
|
|
|
{
|
|
|
|
uint64 x;
|
|
|
|
|
|
|
|
if(d == 0) {
|
|
|
|
*ep = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
2008-11-10 16:17:56 -07:00
|
|
|
x = float64tobits(d);
|
2008-06-30 16:30:47 -06:00
|
|
|
*ep = (int32)((x >> SHIFT) & MASK) - BIAS;
|
|
|
|
x &= ~((uint64)MASK << SHIFT);
|
|
|
|
x |= (uint64)BIAS << SHIFT;
|
2008-11-10 16:17:56 -07:00
|
|
|
return float64frombits(x);
|
2008-06-30 16:30:47 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static float64
|
|
|
|
ldexp(float64 d, int32 e)
|
|
|
|
{
|
|
|
|
uint64 x;
|
|
|
|
|
|
|
|
if(d == 0)
|
|
|
|
return 0;
|
2008-11-10 16:17:56 -07:00
|
|
|
x = float64tobits(d);
|
2008-06-30 16:30:47 -06:00
|
|
|
e += (int32)(x >> SHIFT) & MASK;
|
|
|
|
if(e <= 0)
|
|
|
|
return 0; /* underflow */
|
|
|
|
if(e >= MASK){ /* overflow */
|
|
|
|
if(d < 0)
|
|
|
|
return Inf(-1);
|
|
|
|
return Inf(1);
|
|
|
|
}
|
|
|
|
x &= ~((uint64)MASK << SHIFT);
|
|
|
|
x |= (uint64)e << SHIFT;
|
2008-11-10 16:17:56 -07:00
|
|
|
return float64frombits(x);
|
2008-06-30 16:30:47 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static float64
|
|
|
|
modf(float64 d, float64 *ip)
|
|
|
|
{
|
|
|
|
float64 dd;
|
|
|
|
uint64 x;
|
|
|
|
int32 e;
|
|
|
|
|
|
|
|
if(d < 1) {
|
|
|
|
if(d < 0) {
|
|
|
|
d = modf(-d, ip);
|
|
|
|
*ip = -*ip;
|
|
|
|
return -d;
|
|
|
|
}
|
|
|
|
*ip = 0;
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2008-11-10 16:17:56 -07:00
|
|
|
x = float64tobits(d);
|
2008-06-30 16:30:47 -06:00
|
|
|
e = (int32)((x >> SHIFT) & MASK) - BIAS;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Keep the top 11+e bits; clear the rest.
|
|
|
|
*/
|
|
|
|
if(e <= 64-11)
|
2008-07-08 18:26:10 -06:00
|
|
|
x &= ~(((uint64)1 << (64LL-11LL-e))-1);
|
2008-11-10 16:17:56 -07:00
|
|
|
dd = float64frombits(x);
|
2008-06-30 16:30:47 -06:00
|
|
|
*ip = dd;
|
|
|
|
return d - dd;
|
|
|
|
}
|
|
|
|
|
2008-08-05 15:18:47 -06:00
|
|
|
// func frexp(float64) (float64, int32); // break fp into exp,frac
|
2008-06-30 16:30:47 -06:00
|
|
|
void
|
2008-07-08 18:26:10 -06:00
|
|
|
sys·frexp(float64 din, float64 dou, int32 iou)
|
2008-06-30 16:30:47 -06:00
|
|
|
{
|
|
|
|
dou = frexp(din, &iou);
|
|
|
|
FLUSH(&dou);
|
|
|
|
}
|
|
|
|
|
2008-08-05 15:18:47 -06:00
|
|
|
//func ldexp(int32, float64) float64; // make fp from exp,frac
|
2008-06-30 16:30:47 -06:00
|
|
|
void
|
|
|
|
sys·ldexp(float64 din, int32 ein, float64 dou)
|
|
|
|
{
|
|
|
|
dou = ldexp(din, ein);
|
|
|
|
FLUSH(&dou);
|
|
|
|
}
|
|
|
|
|
|
|
|
//func modf(float64) (float64, float64); // break fp into double+double
|
2008-08-05 15:18:47 -06:00
|
|
|
void
|
2008-07-08 18:26:10 -06:00
|
|
|
sys·modf(float64 din, float64 integer, float64 fraction)
|
2008-06-30 16:30:47 -06:00
|
|
|
{
|
2008-07-08 18:26:10 -06:00
|
|
|
fraction = modf(din, &integer);
|
|
|
|
FLUSH(&fraction);
|
2008-06-30 16:30:47 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//func isinf(float64, int32 sign) bool; // test for infinity
|
|
|
|
void
|
|
|
|
sys·isInf(float64 din, int32 signin, bool out)
|
|
|
|
{
|
|
|
|
out = isInf(din, signin);
|
|
|
|
FLUSH(&out);
|
|
|
|
}
|
|
|
|
|
|
|
|
//func isnan(float64) bool; // test for NaN
|
|
|
|
void
|
|
|
|
sys·isNaN(float64 din, bool out)
|
|
|
|
{
|
|
|
|
out = isNaN(din);
|
|
|
|
FLUSH(&out);
|
|
|
|
}
|
|
|
|
|
|
|
|
//func inf(int32 sign) float64; // signed infinity
|
|
|
|
void
|
|
|
|
sys·Inf(int32 signin, float64 out)
|
|
|
|
{
|
|
|
|
out = Inf(signin);
|
|
|
|
FLUSH(&out);
|
|
|
|
}
|
|
|
|
|
|
|
|
//func nan() float64; // NaN
|
|
|
|
void
|
|
|
|
sys·NaN(float64 out)
|
|
|
|
{
|
|
|
|
out = NaN();
|
|
|
|
FLUSH(&out);
|
|
|
|
}
|
|
|
|
|
2008-11-06 16:48:36 -07:00
|
|
|
// func float32bits(float32) uint32; // raw bits of float32
|
|
|
|
void
|
|
|
|
sys·float32bits(float32 din, uint32 iou)
|
|
|
|
{
|
2008-11-10 16:17:56 -07:00
|
|
|
iou = float32tobits(din);
|
2008-11-06 16:48:36 -07:00
|
|
|
FLUSH(&iou);
|
|
|
|
}
|
|
|
|
|
|
|
|
// func float64bits(float64) uint64; // raw bits of float64
|
|
|
|
void
|
|
|
|
sys·float64bits(float64 din, uint64 iou)
|
|
|
|
{
|
2008-11-10 16:17:56 -07:00
|
|
|
iou = float64tobits(din);
|
2008-11-06 16:48:36 -07:00
|
|
|
FLUSH(&iou);
|
|
|
|
}
|
|
|
|
|
2008-11-12 12:51:34 -07:00
|
|
|
// func float32frombits(uint32) float32; // raw bits to float32
|
|
|
|
void
|
|
|
|
sys·float32frombits(uint32 uin, float32 dou)
|
|
|
|
{
|
|
|
|
dou = float32frombits(uin);
|
|
|
|
FLUSH(&dou);
|
|
|
|
}
|
|
|
|
|
|
|
|
// func float64frombits(uint64) float64; // raw bits to float64
|
|
|
|
void
|
|
|
|
sys·float64frombits(uint64 uin, float64 dou)
|
|
|
|
{
|
|
|
|
dou = float64frombits(uin);
|
|
|
|
FLUSH(&dou);
|
|
|
|
}
|
2008-11-06 16:48:36 -07:00
|
|
|
|
2008-06-30 16:30:47 -06:00
|
|
|
static int32 argc;
|
|
|
|
static uint8** argv;
|
|
|
|
static int32 envc;
|
|
|
|
static uint8** envv;
|
|
|
|
|
|
|
|
void
|
|
|
|
args(int32 c, uint8 **v)
|
|
|
|
{
|
|
|
|
argc = c;
|
|
|
|
argv = v;
|
|
|
|
envv = v + argc + 1; // skip 0 at end of argv
|
|
|
|
for (envc = 0; envv[envc] != 0; envc++)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2008-08-04 17:43:49 -06:00
|
|
|
int32
|
|
|
|
getenvc(void)
|
|
|
|
{
|
|
|
|
return envc;
|
|
|
|
}
|
|
|
|
|
|
|
|
byte*
|
|
|
|
getenv(int8 *s)
|
|
|
|
{
|
|
|
|
int32 i, j, len;
|
|
|
|
byte *v, *bs;
|
2008-08-05 15:21:42 -06:00
|
|
|
|
2008-08-04 17:43:49 -06:00
|
|
|
bs = (byte*)s;
|
2008-11-23 18:08:55 -07:00
|
|
|
len = findnull(bs);
|
2008-08-04 17:43:49 -06:00
|
|
|
for(i=0; i<envc; i++){
|
|
|
|
v = envv[i];
|
|
|
|
for(j=0; j<len; j++)
|
|
|
|
if(bs[j] != v[j])
|
|
|
|
goto nomatch;
|
|
|
|
if(v[len] != '=')
|
|
|
|
goto nomatch;
|
|
|
|
return v+len+1;
|
|
|
|
nomatch:;
|
|
|
|
}
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32
|
|
|
|
atoi(byte *p)
|
|
|
|
{
|
|
|
|
int32 n;
|
2008-08-05 15:21:42 -06:00
|
|
|
|
2008-08-04 17:43:49 -06:00
|
|
|
n = 0;
|
|
|
|
while('0' <= *p && *p <= '9')
|
|
|
|
n = n*10 + *p++ - '0';
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2008-06-30 16:30:47 -06:00
|
|
|
//func argc() int32; // return number of arguments
|
|
|
|
void
|
|
|
|
sys·argc(int32 v)
|
|
|
|
{
|
|
|
|
v = argc;
|
|
|
|
FLUSH(&v);
|
|
|
|
}
|
|
|
|
|
|
|
|
//func envc() int32; // return number of environment variables
|
|
|
|
void
|
|
|
|
sys·envc(int32 v)
|
|
|
|
{
|
|
|
|
v = envc;
|
|
|
|
FLUSH(&v);
|
|
|
|
}
|
|
|
|
|
|
|
|
//func argv(i) string; // return argument i
|
|
|
|
void
|
|
|
|
sys·argv(int32 i, string s)
|
|
|
|
{
|
2008-11-23 18:08:55 -07:00
|
|
|
if(i >= 0 && i < argc)
|
|
|
|
s = gostring(argv[i]);
|
|
|
|
else
|
2008-06-30 16:30:47 -06:00
|
|
|
s = emptystring;
|
|
|
|
FLUSH(&s);
|
|
|
|
}
|
|
|
|
|
2008-06-30 17:30:53 -06:00
|
|
|
//func envv(i) string; // return environment variable i
|
2008-06-30 16:30:47 -06:00
|
|
|
void
|
|
|
|
sys·envv(int32 i, string s)
|
|
|
|
{
|
2008-11-23 18:08:55 -07:00
|
|
|
if(i >= 0 && i < envc)
|
|
|
|
s = gostring(envv[i]);
|
|
|
|
else
|
2008-06-30 16:30:47 -06:00
|
|
|
s = emptystring;
|
|
|
|
FLUSH(&s);
|
|
|
|
}
|
|
|
|
|
2008-08-05 15:18:47 -06:00
|
|
|
void
|
2008-06-30 16:30:47 -06:00
|
|
|
check(void)
|
|
|
|
{
|
|
|
|
int8 a;
|
|
|
|
uint8 b;
|
|
|
|
int16 c;
|
|
|
|
uint16 d;
|
|
|
|
int32 e;
|
|
|
|
uint32 f;
|
|
|
|
int64 g;
|
|
|
|
uint64 h;
|
|
|
|
float32 i;
|
|
|
|
float64 j;
|
|
|
|
void* k;
|
|
|
|
uint16* l;
|
|
|
|
|
|
|
|
if(sizeof(a) != 1) throw("bad a");
|
|
|
|
if(sizeof(b) != 1) throw("bad b");
|
|
|
|
if(sizeof(c) != 2) throw("bad c");
|
|
|
|
if(sizeof(d) != 2) throw("bad d");
|
|
|
|
if(sizeof(e) != 4) throw("bad e");
|
|
|
|
if(sizeof(f) != 4) throw("bad f");
|
|
|
|
if(sizeof(g) != 8) throw("bad g");
|
|
|
|
if(sizeof(h) != 8) throw("bad h");
|
|
|
|
if(sizeof(i) != 4) throw("bad i");
|
|
|
|
if(sizeof(j) != 8) throw("bad j");
|
|
|
|
if(sizeof(k) != 8) throw("bad k");
|
|
|
|
if(sizeof(l) != 8) throw("bad l");
|
|
|
|
// prints(1"check ok\n");
|
2008-08-04 17:43:49 -06:00
|
|
|
|
|
|
|
uint32 z;
|
|
|
|
z = 1;
|
|
|
|
if(!cas(&z, 1, 2))
|
|
|
|
throw("cas1");
|
|
|
|
if(z != 2)
|
|
|
|
throw("cas2");
|
2008-08-05 15:21:42 -06:00
|
|
|
|
2008-08-04 17:43:49 -06:00
|
|
|
z = 4;
|
|
|
|
if(cas(&z, 5, 6))
|
|
|
|
throw("cas3");
|
|
|
|
if(z != 4)
|
|
|
|
throw("cas4");
|
|
|
|
|
2008-06-30 16:30:47 -06:00
|
|
|
initsig();
|
|
|
|
}
|
2008-07-08 18:19:17 -06:00
|
|
|
|
2008-07-13 15:29:46 -06:00
|
|
|
/*
|
|
|
|
* map and chan helpers for
|
|
|
|
* dealing with unknown types
|
|
|
|
*/
|
|
|
|
static uint64
|
|
|
|
memhash(uint32 s, void *a)
|
|
|
|
{
|
2008-11-13 11:35:44 -07:00
|
|
|
byte *b;
|
|
|
|
uint64 hash;
|
|
|
|
|
|
|
|
b = a;
|
|
|
|
hash = 33054211828000289ULL;
|
|
|
|
while(s > 0) {
|
|
|
|
hash = (hash ^ *b) * 23344194077549503ULL;
|
|
|
|
b++;
|
|
|
|
s--;
|
|
|
|
}
|
|
|
|
return hash;
|
2008-07-13 15:29:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static uint32
|
|
|
|
memequal(uint32 s, void *a, void *b)
|
|
|
|
{
|
|
|
|
byte *ba, *bb;
|
|
|
|
uint32 i;
|
|
|
|
|
|
|
|
ba = a;
|
|
|
|
bb = b;
|
|
|
|
for(i=0; i<s; i++)
|
|
|
|
if(ba[i] != bb[i])
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
memprint(uint32 s, void *a)
|
|
|
|
{
|
|
|
|
uint64 v;
|
|
|
|
|
|
|
|
v = 0xbadb00b;
|
|
|
|
switch(s) {
|
|
|
|
case 1:
|
|
|
|
v = *(uint8*)a;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
v = *(uint16*)a;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
v = *(uint32*)a;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
v = *(uint64*)a;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sys·printint(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
memcopy(uint32 s, void *a, void *b)
|
|
|
|
{
|
|
|
|
byte *ba, *bb;
|
|
|
|
uint32 i;
|
|
|
|
|
|
|
|
ba = a;
|
|
|
|
bb = b;
|
|
|
|
if(bb == nil) {
|
|
|
|
for(i=0; i<s; i++)
|
|
|
|
ba[i] = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for(i=0; i<s; i++)
|
|
|
|
ba[i] = bb[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint64
|
2008-12-19 13:05:22 -07:00
|
|
|
strhash(uint32 s, string *a)
|
2008-07-13 15:29:46 -06:00
|
|
|
{
|
2008-11-14 11:57:48 -07:00
|
|
|
USED(s);
|
2008-12-10 14:28:46 -07:00
|
|
|
if(*a == nil)
|
|
|
|
return memhash(emptystring->len, emptystring->str);
|
2008-11-13 11:35:44 -07:00
|
|
|
return memhash((*a)->len, (*a)->str);
|
2008-07-13 15:29:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static uint32
|
2008-12-19 13:05:22 -07:00
|
|
|
strequal(uint32 s, string *a, string *b)
|
2008-07-13 15:29:46 -06:00
|
|
|
{
|
2008-08-05 15:18:47 -06:00
|
|
|
USED(s);
|
2008-07-13 15:29:46 -06:00
|
|
|
return cmpstring(*a, *b) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-12-19 13:05:22 -07:00
|
|
|
strprint(uint32 s, string *a)
|
2008-07-13 15:29:46 -06:00
|
|
|
{
|
2008-08-05 15:18:47 -06:00
|
|
|
USED(s);
|
2008-07-13 15:29:46 -06:00
|
|
|
sys·printstring(*a);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-12-19 13:05:22 -07:00
|
|
|
strcopy(uint32 s, string *a, string *b)
|
2008-07-13 15:29:46 -06:00
|
|
|
{
|
2008-08-05 15:18:47 -06:00
|
|
|
USED(s);
|
2008-07-13 15:29:46 -06:00
|
|
|
if(b == nil) {
|
|
|
|
*a = nil;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
*a = *b;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint64
|
2008-12-19 13:05:22 -07:00
|
|
|
ptrhash(uint32 s, void **a)
|
2008-07-13 15:29:46 -06:00
|
|
|
{
|
2008-11-13 11:35:44 -07:00
|
|
|
return memhash(s, *a);
|
2008-07-13 15:29:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static uint32
|
2008-12-19 13:05:22 -07:00
|
|
|
ptrequal(uint32 s, void **a, void **b)
|
2008-07-13 15:29:46 -06:00
|
|
|
{
|
2008-08-05 15:18:47 -06:00
|
|
|
USED(s, a, b);
|
2008-12-19 13:05:22 -07:00
|
|
|
prints("ptrequal\n");
|
2008-07-13 15:29:46 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-12-19 13:05:22 -07:00
|
|
|
ptrprint(uint32 s, void **a)
|
2008-07-13 15:29:46 -06:00
|
|
|
{
|
2008-08-05 15:18:47 -06:00
|
|
|
USED(s, a);
|
2008-12-19 13:05:22 -07:00
|
|
|
prints("ptrprint\n");
|
2008-07-13 15:29:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-12-19 13:05:22 -07:00
|
|
|
ptrcopy(uint32 s, void **a, void **b)
|
2008-07-13 15:29:46 -06:00
|
|
|
{
|
2008-08-05 15:18:47 -06:00
|
|
|
USED(s);
|
2008-07-13 15:29:46 -06:00
|
|
|
if(b == nil) {
|
|
|
|
*a = nil;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
*a = *b;
|
|
|
|
}
|
|
|
|
|
|
|
|
Alg
|
2008-12-19 13:05:22 -07:00
|
|
|
algarray[] =
|
|
|
|
{
|
|
|
|
[ASIMP] { memhash, memequal, memprint, memcopy },
|
|
|
|
[ASTRING] { strhash, strequal, strprint, strcopy },
|
|
|
|
[APTR] { memhash, memequal, memprint, memcopy }, // TODO: ptr routines
|
|
|
|
[AINTER] { memhash, memequal, memprint, memcopy }, // TODO: interface routines
|
|
|
|
[ASTRUCT] { memhash, memequal, memprint, memcopy }, // TODO: what goes here?
|
|
|
|
[AARRAY] { memhash, memequal, memprint, memcopy }, // TODO: what goes here?
|
2008-07-13 15:29:46 -06:00
|
|
|
};
|
2008-11-20 18:32:18 -07:00
|
|
|
|