--- /dev/null
+#include "nith.main.0.h"
+struct nitni_global_ref_list_t *nitni_global_ref_list;
+void initialize_nitni_global_refs() {
+ nitni_global_ref_list = (struct nitni_global_ref_list_t*)nit_alloc(sizeof(struct nitni_global_ref_list_t));
+ nitni_global_ref_list->head = NULL;
+ nitni_global_ref_list->tail = NULL;
+}
+
+void nitni_global_ref_add( struct nitni_ref *ref ) {
+ if ( nitni_global_ref_list->head == NULL ) {
+ nitni_global_ref_list->head = ref;
+ ref->prev = NULL;
+ } else {
+ nitni_global_ref_list->tail->next = ref;
+ ref->prev = nitni_global_ref_list->tail;
+ }
+ nitni_global_ref_list->tail = ref;
+
+ ref->next = NULL;
+}
+
+void nitni_global_ref_remove( struct nitni_ref *ref ) {
+ if ( ref->prev == NULL ) {
+ nitni_global_ref_list->head = ref->next;
+ } else {
+ ref->prev->next = ref->next;
+ }
+
+ if ( ref->next == NULL ) {
+ nitni_global_ref_list->tail = ref->prev;
+ } else {
+ ref->next->prev = ref->prev;
+ }
+}
+
+extern void nitni_global_ref_incr( struct nitni_ref *ref ) {
+ if ( ref->count == 0 ) /* not registered */
+ {
+ /* add to list */
+ nitni_global_ref_add( ref );
+ }
+
+ ref->count ++;
+}
+
+extern void nitni_global_ref_decr( struct nitni_ref *ref ) {
+ if ( ref->count == 1 ) /* was last reference */
+ {
+ /* remove from list */
+ nitni_global_ref_remove( ref );
+ }
+
+ ref->count --;
+}
+
+#include <signal.h>
+#define UNW_LOCAL_ONLY
+#include <libunwind.h>
+#include "c_functions_hash.h"
+int glob_argc;
+char **glob_argv;
+val *glob_sys;
+void sig_handler(int signo){
+PRINT_ERROR("Caught signal : %s\n", strsignal(signo));
+show_backtrace(signo);
+}
+void show_backtrace (int signo) {
+char* opt = getenv("NIT_NO_STACK");
+unw_cursor_t cursor;
+if(opt==NULL){
+unw_context_t uc;
+unw_word_t ip;
+char* procname = malloc(sizeof(char) * 100);
+unw_getcontext(&uc);
+unw_init_local(&cursor, &uc);
+PRINT_ERROR("-------------------------------------------------\n");
+PRINT_ERROR("-- Stack Trace ------------------------------\n");
+PRINT_ERROR("-------------------------------------------------\n");
+while (unw_step(&cursor) > 0) {
+ unw_get_proc_name(&cursor, procname, 100, &ip);
+ const char* recv = get_nit_name(procname, strlen(procname));
+ if (recv != NULL){
+ PRINT_ERROR("` %s\n", recv);
+ }else{
+ PRINT_ERROR("` %s\n", procname);
+ }
+}
+PRINT_ERROR("-------------------------------------------------\n");
+free(procname);
+}
+exit(signo);
+}
+int main(int argc, char** argv) {
+val* var /* : Sys */;
+signal(SIGABRT, sig_handler);
+signal(SIGFPE, sig_handler);
+signal(SIGILL, sig_handler);
+signal(SIGINT, sig_handler);
+signal(SIGTERM, sig_handler);
+signal(SIGSEGV, sig_handler);
+signal(SIGPIPE, sig_handler);
+glob_argc = argc; glob_argv = argv;
+initialize_gc_option();
+initialize_nitni_global_refs();
+var = NEW_kernel__Sys(&type_kernel__Sys);
+glob_sys = var;
+{
+((void (*)(val*))(var->class->vft[COLOR_kernel__Sys__init]))(var) /* init on <var:Sys>*/;
+}
+{
+((void (*)(val*))(var->class->vft[COLOR_kernel__Sys__main]))(var) /* main on <var:Sys>*/;
+}
+return 0;
+}