-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitialize.es
More file actions
159 lines (149 loc) · 3.86 KB
/
initialize.es
File metadata and controls
159 lines (149 loc) · 3.86 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env es
noexport += __es_initialize_esrc __es_loginshell __es_readesrc __es_different_esrc
noexport += __es_esrcfile __es_extra_esrc __es_extra_esrcfile __es_interactive_start
let (
fn __es_esrc_check {
if {$es_enable_loginshell} {
result <={$__es_initialize_esrc && $__es_readesrc && $__es_loginshell}
} {
result <={$__es_initialize_esrc && $__es_readesrc}
}
}
) {
fn %interactive-shell { return $__es_interactive_start }
fn %initialize {
# run any setup functions that need to be run in es land, but before the
# .esrc is run.
local(set-ppid=){
ppid = $__ppid
}
# tune max-eval-depth based on the systems stacksize
# stacksize/1024 seems to be a reasonable number
if {~ <=$&primitives limit} { # limit is available on all supported platforms
max-eval-depth = <={let (new-eval-depth = <={limit -r stacksize |> @{div $1 1024}}){
if {lt $new-eval-depth 680} { new-eval-depth = 680 }
result $new-eval-depth
}}
}
__es_initgc
__es_complete_initialize
__es_libraries_initialize
__es_iosub_init
__es_define_iosub_settor
%unhidevar es_internal_symcount
# run $home/.esrc if applicable
if {__es_esrc_check} {
catch @ el {
errmatch <={makeerror $el} (
exit { exit $type }
error { echo >[1=2] 'esrc:' $err^':' $type^':' $msg }
signal {
if {! ~ $type 'sigint' 'sigwinch'} {
echo >[1=2] 'esrc: uncaught signal:' $err $type $msg
}
}
{ echo >[1=2] 'esrc: uncaught exception:' $err $type $msg }
)
} {
local(esrc_found = false){
if {! $__es_different_esrc} {
if {! ~ $#libraries 0} {
for (l = $libraries) {
if {access -r $l/init.es} {
__es_esrcfile = $l/init.es
esrc_found = true
break
}
}
}
if {! $esrc_found} {
__es_esrcfile = $home/.esrc
}
}
}
if {access -r $__es_esrcfile} {
. $__es_esrcfile
}
if {$__es_extra_esrc} {
if {access -r $__es_extra_esrcfile} {
. $__es_extra_esrcfile
} {
echo 'warning: '^$__es_extra_esrcfile^' not found!'
}
}
}
}
# run %user-init hook if available
if {! ~ $#fn-%user-init 0} {
let (e=) {
(e _) = <={try %user-init}
if {! $e} { return <=true }
errmatch $e (
continue { return <=true }
eof { return <=true }
exit { exit $type }
error {
echo >[1=2] '%user-init: error:' $type^':' $msg
return <=false
}
assert {
echo >[1=2] '%user-init: assert:' $type $msg
return <=false
}
usage {
if {~ $#msg 0} {
echo >[1=2] '%user-init:' $type
} {
echo >[1=2] '%user-init:' $msg
}
return <=false
}
signal {
if {!~ $type sigint sigterm sigquit sigwinch} {
echo >[1=2] '%user-init: caught unexpected signal:' $type
}
return <=false
}
{ echo >[1=2] '%user-init: uncaught exception:' $err $type $msg }
)
}
}
if {$__es_interactive_start} {
if {! ~ $#fn-%interactive-start 0} {
let (e=) {
(e _) = <={try %interactive-start}
if {! $e} { return <=true }
errmatch $e (
continue { return <=true }
eof { return <=true }
exit { exit $type }
error {
echo >[1=2] '%interactive-start: error:' $type^':' $msg
return <=false
}
assert {
echo >[1=2] '%interactive-start: assert:' $type $msg
return <=false
}
usage {
if {~ $#msg 0} {
echo >[1=2] '%interactive-start:' $type
} {
echo >[1=2] '%interactive-start:' $msg
}
return <=false
}
signal {
if {!~ $type sigint sigterm sigquit sigwinch} {
echo >[1=2] '%interactive-start: caught unexpected signal:' $type
}
return <=false
}
{ echo >[1=2] '%interactive-start: uncaught exception:' $err $type $msg }
)
}
}
}
return <=true
}
}