]> gitweb.factorcode.org Git - factor.git/blob - basis/bootstrap/stage2.factor
Squashed commit of the following:
[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     ! We time bootstrap
63     nano-count
64
65     default-image-name "output-image" set-global
66
67     "math compiler threads help io tools ui ui.tools unicode handbook" "include" set-global
68     "" "exclude" set-global
69
70     strip-encodings
71
72     (command-line) parse-command-line
73
74     ! Set dll paths
75     os windows? [ "windows" require ] when
76
77     "staging" get "deploy-vocab" get or [
78         "stage2: deployment mode" print
79     ] [
80         "debugger" require
81         "listener" require
82         "none" require
83     ] if
84
85     load-components
86
87     nano-count over - core-bootstrap-time set-global
88
89     run-bootstrap-init
90
91     f error set-global
92     f original-error set-global
93     f error-continuation set-global
94
95     nano-count swap - bootstrap-time set-global
96     print-report
97
98     "deploy-vocab" get [
99         "tools.deploy.shaker" run
100     ] [
101         "staging" get [
102             "vocab:bootstrap/finish-staging.factor" run-file
103         ] [
104             "vocab:bootstrap/finish-bootstrap.factor" run-file
105         ] if
106
107         "output-image" get save-image-and-exit
108     ] if
109 ] [
110     drop
111     [
112         load-help? off
113         [ "vocab:bootstrap/bootstrap-error.factor" parse-file ] save/restore-error
114         call
115     ] with-scope
116 ] recover