-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.c
executable file
·83 lines (65 loc) · 1.41 KB
/
init.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* init.c:
*
* Contains the core initialization functions that must be executed
* both in order and prior to any of the other interpreter's code.
*
* Also responsible for calling the ``Init_{classname}'' functions that
* by convention bootstrap the various class/method info implemented by
* the interpreter's various source files.
*
*/
#include "toi.h"
/* global variable symbol table */
st_table *gv_tbl;
static int sigint_flag;
void
toi_set_argv(int argc, char **argv)
{
int i;
VALUE ary = ary_new();
for (i = 0; i < argc; i++)
ary_push(ary, string_new(argv[i]));
define_global_variable(intern("ARGV"), ary);
}
static void
handle_sigint()
{
if (sigint_flag)
{
signal(SIGINT, SIG_DFL);
raise(SIGINT);
}
else
{
fprintf(stderr, "\n%s\n", "caught SIGINT; send again to interrupt execution");
sigint_flag = 1;
}
}
void
toi_init(int argc, char **argv)
{
gv_tbl = st_init_numtable();
Init_thread();
THREAD(cur_thr)->recv = main_thread();
if (THREAD(main_thread())->env_tbl)
st_free_table(THREAD(main_thread())->env_tbl);
THREAD(main_thread())->env_tbl = gv_tbl;
Init_symbol();
Init_class();
/* have to call Init_thread() again */
Init_thread();
Init_kernel();
cself = cKernel;
Init_numeric();
Init_float();
Init_integer();
Init_array();
Init_hash();
Init_string();
Init_iostream();
Init_exception();
toi_set_argv(argc, argv);
Init_gc();
signal(SIGINT, handle_sigint);
}