]> gitweb.factorcode.org Git - factor.git/blob - basis/bootstrap/stage2.factor
Merge branch 'master' into startup
[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 ( ms -- )
39     1000 /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     error-continuation get-global
55     [ call ] 2dip
56     error-continuation set-global
57     error set-global ; inline
58
59
60 [
61     ! We time bootstrap
62     millis
63
64     default-image-name "output-image" set-global
65
66     "math compiler threads help io tools ui ui.tools unicode handbook" "include" set-global
67     "" "exclude" set-global
68
69     strip-encodings
70
71     (command-line) parse-command-line
72
73     ! Set dll paths
74     os wince? [ "windows.ce" require ] when
75     os winnt? [ "windows.nt" 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     millis over - core-bootstrap-time set-global
88
89     run-bootstrap-init
90
91     f error set-global
92     f error-continuation set-global
93
94     millis swap - bootstrap-time set-global
95     print-report
96
97     "deploy-vocab" get [
98         "tools.deploy.shaker" run
99     ] [
100         "staging" get [
101             "vocab:bootstrap/finish-staging.factor" run-file
102         ] [
103             "vocab:bootstrap/finish-bootstrap.factor" run-file
104         ] if
105
106         "output-image" get save-image-and-exit
107     ] if
108 ] [
109     drop
110     [
111         load-help? off
112         [ "vocab:bootstrap/bootstrap-error.factor" parse-file ] save/restore-error
113         call
114     ] with-scope
115 ] recover