1 /* This file is part of NIT ( http://www.nitlanguage.org ).
3 * Copyright 2006-2009 Jean Privat <jean@pryen.org>
5 * This file is free software, which comes along with NIT. This software is
6 * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
7 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
8 * PARTICULAR PURPOSE. You can modify it is you want, provided this header
9 * is kept unaltered, and a notification of the changes is added.
10 * You are allowed to redistribute it and sell it, alone or is a part of
14 #include "nit_common.h"
18 bigint object_id_counter
= 1000000;
19 enum gc_option
{ large
, boehm
} gc_option
;
26 void *raw_alloc(size_t s0
)
31 void register_static_object(val_t
*o
)
36 void *large_alloc(size_t s0
)
38 static char * alloc_pos
= NULL
;
39 static size_t alloc_size
= 0;
41 size_t s
= ((s0
+3)/4)*4;
43 alloc_size
= s
+ 1024*1024;
44 alloc_pos
= (char *)calloc(alloc_size
, 1);
52 void * alloc(size_t s0
)
56 case boehm
: return GC_MALLOC(s0
);
59 default: return large_alloc(s0
);
67 void exithandler(int s
) {
68 fprintf(stderr
, "Recieved signal %d\n", s
);
71 void initialize_gc_option(void) {
79 /* Process GC runtime selection */
80 if (getenv("NIT_GC_OPTION") != NULL
) {
81 char *opt
=getenv("NIT_GC_OPTION");
82 if (strcmp(opt
, "boehm")==0) {
86 fprintf(stderr
, "Compiled without Boehm GC support. Using default.\n");
88 } else if (strcmp(opt
, "large")==0) {
91 fprintf(stderr
, "Invalid GC option in NIT_GC_OPTION environment variable. Using default.\n");
95 /* Initialize GC (if needed) */
98 case boehm
: GC_INIT(); break;
100 default: break; /* Nothing */
103 void prepare_signals(void) {
104 initialize_gc_option();
106 signal(SIGINT
,exithandler
);
107 signal(SIGABRT
,exithandler
);
108 signal(SIGSEGV
,exithandler
);
109 signal(SIGILL
, exithandler
);
110 signal(SIGFPE
, exithandler
);
111 signal(SIGTERM
,exithandler
);
112 signal(SIGBUS
, exithandler
);
114 struct trace_t
*tracehead
= NULL
;
115 void nit_exit(int i
) {
116 fprintf(stderr
, ",---- Stack trace -- - - -\n");
117 while(tracehead
!= NULL
) {
118 fprintf(stderr
, "| %s (%s:%d)\n", tracehead
->meth
, tracehead
->file
, tracehead
->line
);
119 if (tracehead
== tracehead
->prev
) break;
120 tracehead
= tracehead
->prev
;
122 fprintf(stderr
, "`------------------- - - -\n");