]> gitweb.factorcode.org Git - factor.git/blob - basis/bootstrap/stage2.factor
da4fbc444b8f0cad187d96b22d3de51a9a42f32c
[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: accessors init namespaces words words.symbol io
4 kernel.private math memory continuations kernel io.files
5 io.pathnames io.backend system parser vocabs sequences
6 vocabs.loader combinators splitting source-files strings
7 definitions assocs compiler.units math.parser
8 generic sets command-line ;
9 IN: bootstrap.stage2
10
11 SYMBOL: core-bootstrap-time
12
13 SYMBOL: bootstrap-time
14
15 : strip-encodings ( -- )
16     os unix? [
17         [
18             P" resource:core/io/encodings/utf16/utf16.factor" 
19             P" resource:core/io/encodings/utf16n/utf16n.factor" [ forget ] bi@
20             "io.encodings.utf16" 
21             "io.encodings.utf16n" [ child-vocabs [ forget-vocab ] each ] bi@
22         ] with-compilation-unit
23     ] when ;
24
25 : default-image-name ( -- string )
26     vm file-name os windows? [ "." split1-last drop ] when
27     ".image" append resource-path ;
28
29 : load-components ( -- )
30     "include" "exclude"
31     [ get-global " " split harvest ] bi@
32     diff
33     [ "bootstrap." prepend require ] each ;
34
35 : count-words ( pred -- )
36     all-words swap count number>string write ; inline
37
38 : print-time ( us -- )
39     1,000,000,000 /i
40     60 /mod swap
41     number>string write
42     " minutes and " write number>string write " seconds." print ;
43
44 : print-report ( -- )
45     "Core bootstrap completed in " write core-bootstrap-time get print-time
46     "Bootstrap completed in "      write bootstrap-time      get print-time
47
48     "Bootstrapping is complete." print
49     "Now, you can run Factor:" print
50     vm write " -i=" write "output-image" get print flush ;
51
52 : save/restore-error ( quot -- )
53     error get-global
54     original-error get-global
55     error-continuation get-global
56     [ call ] 3dip
57     error-continuation set-global
58     original-error set-global
59     error set-global ; inline
60
61
62 [
63     ! We time bootstrap
64     nano-count
65
66     default-image-name "output-image" set-global
67
68     "math compiler threads help io tools ui ui.tools unicode handbook" "include" set-global
69     "" "exclude" set-global
70
71     strip-encodings
72
73     (command-line) parse-command-line
74
75     ! Set dll paths
76     os wince? [ "windows.ce" require ] when
77     os winnt? [ "windows.nt" 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