]> gitweb.factorcode.org Git - factor.git/blob - basis/bootstrap/stage2.factor
3ec202482745c14525492288846fa7382dff574e
[factor.git] / basis / bootstrap / stage2.factor
1 ! Copyright (C) 2004, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: command-line compiler.units continuations definitions io
4 io.pathnames kernel math math.parser memory namespaces parser
5 parser.notes sequences sets splitting system
6 vocabs vocabs.loader ;
7 IN: bootstrap.stage2
8
9 SYMBOL: core-bootstrap-time
10
11 SYMBOL: bootstrap-time
12
13 : strip-encodings ( -- )
14     os unix? [
15         [
16             P" resource:core/io/encodings/utf16/utf16.factor"
17             P" resource:core/io/encodings/utf16n/utf16n.factor" [ forget ] bi@
18             "io.encodings.utf16"
19             "io.encodings.utf16n" [ loaded-child-vocab-names [ forget-vocab ] each ] bi@
20         ] with-compilation-unit
21     ] when ;
22
23 : default-image-name ( -- string )
24     vm-path file-name os windows? [ "." split1-last drop ] when
25     ".image" append resource-path ;
26
27 : load-component ( name -- )
28     dup "* Loading the " write write " component" print
29     "bootstrap." prepend require ;
30
31 : load-components ( -- )
32     "include" "exclude" [ get-global " " split harvest ] bi@ diff
33     [ load-component ] each ;
34
35 : print-time ( us -- )
36     1,000,000,000 /i
37     60 /mod swap
38     number>string write
39     " minutes and " write number>string write " seconds." print ;
40
41 : print-report ( -- )
42     "Core bootstrap completed in " write core-bootstrap-time get print-time
43     "Bootstrap completed in "      write bootstrap-time      get print-time
44
45     "Bootstrapping is complete." print
46     "Now, you can run Factor:" print
47     vm-path write " -i=" write "output-image" get print flush ;
48
49 : save/restore-error ( quot -- )
50     error get-global
51     original-error get-global
52     error-continuation get-global
53     [ call ] 3dip
54     error-continuation set-global
55     original-error set-global
56     error set-global ; inline
57
58 CONSTANT: default-components
59     "math compiler threads io tools ui ui.tools unicode help handbook"
60
61 [
62     ! We time bootstrap
63     nano-count
64
65     ! parser.notes sets this to t in the global namespace.
66     ! We have to change it back in finish-bootstrap.factor
67     f parser-quiet? set-global
68
69     default-image-name "output-image" set-global
70
71     default-components "include" set-global
72     "" "exclude" set-global
73
74     strip-encodings
75
76     (command-line) parse-command-line
77
78     ! Set dll paths
79     os windows? [ "windows" require ] when
80
81     "staging" get [
82         "stage2: deployment mode" print
83     ] [
84         "debugger" require
85         "listener" require
86     ] if
87
88     load-components
89
90     nano-count over - core-bootstrap-time set-global
91
92     run-bootstrap-init
93
94     nano-count swap - bootstrap-time set-global
95     print-report
96
97     "staging" get [
98         "vocab:bootstrap/finish-staging.factor" run-file
99     ] [
100         "vocab:bootstrap/finish-bootstrap.factor" run-file
101     ] if
102
103     f error set-global
104     f original-error set-global
105     f error-continuation set-global
106     "output-image" get save-image-and-exit
107 ] [
108     drop
109     [
110         load-help? off
111         [ "vocab:bootstrap/bootstrap-error.factor" parse-file ] save/restore-error
112         call
113     ] with-scope
114 ] recover