From d90e7cbac65c5792ce312ee82fbe03a5dfc98c6f Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Tue, 9 Jun 2009 09:53:44 -0700 Subject: mv src/lib to src/pkg tests: all.bash passes, gobuild still works, godoc still works. R=rsc OCL=30096 CL=30102 --- src/pkg/runtime/runtime.c | 462 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 462 insertions(+) create mode 100644 src/pkg/runtime/runtime.c (limited to 'src/pkg/runtime/runtime.c') diff --git a/src/pkg/runtime/runtime.c b/src/pkg/runtime/runtime.c new file mode 100644 index 0000000000..c5ba3e6a5e --- /dev/null +++ b/src/pkg/runtime/runtime.c @@ -0,0 +1,462 @@ +// 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" + +int32 panicking = 0; +int32 maxround = sizeof(uintptr); + +int32 +gotraceback(void) +{ + byte *p; + + p = getenv("GOTRACEBACK"); + if(p == nil || p[0] == '\0') + return 1; // default is on + return atoi(p); +} + +void +sys·panicl(int32 lno) +{ + uint8 *sp; + + if(panicking) { + printf("double panic\n"); + exit(3); + } + panicking++; + + printf("\npanic PC=%X\n", (uint64)(uintptr)&lno); + sp = (uint8*)&lno; + if(gotraceback()){ + traceback(sys·getcallerpc(&lno), sp, g); + tracebackothers(g); + } + breakpoint(); // so we can grab it in a debugger + exit(2); +} + +void +sys·throwindex(void) +{ + throw("index out of range"); +} + +void +sys·throwreturn(void) +{ + throw("no return at end of a typed function"); +} + +void +sys·throwinit(void) +{ + throw("recursive call during initialization"); +} + +void +throw(int8 *s) +{ + printf("throw: %s\n", s); + sys·panicl(-1); + *(int32*)0 = 0; // not reached + exit(1); // even more not reached +} + +void +mcpy(byte *t, byte *f, uint32 n) +{ + while(n > 0) { + *t = *f; + t++; + f++; + n--; + } +} + +int32 +mcmp(byte *s1, byte *s2, uint32 n) +{ + uint32 i; + byte c1, c2; + + for(i=0; i c2) + return +1; + } + return 0; +} + + +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--; + } + } +} + +byte* +mchr(byte *p, byte c, byte *ep) +{ + for(; p < ep; p++) + if(*p == c) + return p; + return nil; +} + +uint32 +rnd(uint32 n, uint32 m) +{ + uint32 r; + + if(m > maxround) + m = maxround; + r = n % m; + if(r) + n += m-r; + return n; +} + +static int32 argc; +static uint8** argv; + +Array os·Args; +Array os·Envs; + +void +args(int32 c, uint8 **v) +{ + argc = c; + argv = v; +} + +void +goargs(void) +{ + String *gargv; + String *genvv; + int32 i, envc; + + for(envc=0; argv[argc+1+envc] != 0; envc++) + ; + + gargv = malloc(argc*sizeof gargv[0]); + genvv = malloc(envc*sizeof genvv[0]); + + for(i=0; i 0) { + if(sizeof(hash) == 4) + hash = (hash ^ *b) * 3267000013UL; + else + hash = (hash ^ *b) * 23344194077549503ULL; + b++; + s--; + } + return hash; +} + +static uint32 +memequal(uint32 s, void *a, void *b) +{ + byte *ba, *bb; + uint32 i; + + ba = a; + bb = b; + for(i=0; i