// 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) { 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