]> gitweb.factorcode.org Git - factor.git/blob - basis/bootstrap/stage2.factor
core/basis: trim down using lists
[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" [ child-vocabs [ forget-vocab ] each ] bi@
20         ] with-compilation-unit
21     ] when ;
22
23 : default-image-name ( -- string )
24     vm file-name os windows? [ "." split1-last drop ] when
25     ".image" append resource-path ;
26
27 : load-components ( -- )
28     "include" "exclude"
29     [ get-global " " split harvest ] bi@
30     diff
31     [ "bootstrap." prepend require ] each ;
32
33 : count-words ( pred -- )
34     all-words swap count number>string write ; inline
35
36 : print-time ( us -- )
37     1,000,000,000 /i
38     60 /mod swap
39     number>string write
40     " minutes and " write number>string write " seconds." print ;
41
42 : print-report ( -- )
43     "Core bootstrap completed in " write core-bootstrap-time get print-time
44     "Bootstrap completed in "      write bootstrap-time      get print-time
45
46     "Bootstrapping is complete." print
47     "Now, you can run Factor:" print
48     vm write " -i=" write "output-image" get print flush ;
49
50 : save/restore-error ( quot -- )
51     error get-global
52     original-error get-global
53     error-continuation get-global
54     [ call ] 3dip
55     error-continuation set-global
56     original-error set-global
57     error set-global ; inline
58
59 [
60     ! We time bootstrap
61     nano-count
62
63     ! parser.notes sets this to t in the global namespace.
64     ! We have to change it back in finish-bootstrap.factor
65     f parser-quiet? set-global
66
67     default-image-name "output-image" set-global
68
69     "math compiler threads help io tools ui ui.tools unicode handbook" "include" set-global
70     "" "exclude" set-global
71
72     strip-encodings
73
74     (command-line) parse-command-line
75
76     ! Set dll paths
77     os windows? [ "windows" require ] when
78
79     "staging" get "deploy-vocab" get or [
80         "stage2: deployment mode" print
81     ] [
82         "debugger" require
83         "listener" require
84         "none" require
85     ] if
86
87     load-components
88
89     nano-count over - core-bootstrap-time set-global
90
91     run-bootstrap-init
92
93     f error set-global
94     f original-error set-global
95     f error-continuation set-global
96
97     nano-count swap - bootstrap-time set-global
98     print-report
99
100     "deploy-vocab" get [
101         "tools.deploy.shaker" run
102     ] [
103         "staging" get [
104             "vocab:bootstrap/finish-staging.factor" run-file
105         ] [
106             "vocab:bootstrap/finish-bootstrap.factor" run-file
107         ] if
108
109         "output-image" get save-image-and-exit
110     ] if
111 ] [
112     drop
113     [
114         load-help? off
115         [ "vocab:bootstrap/bootstrap-error.factor" parse-file ] save/restore-error
116         call
117     ] with-scope
118 ] recover