]> gitweb.factorcode.org Git - factor.git/blob - basis/bootstrap/stage2.factor
Merge branch 'master' into irc
[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 : default-image-name ( -- string )
16     vm file-name os windows? [ "." split1-last drop ] when
17     ".image" append resource-path ;
18
19 : load-components ( -- )
20     "include" "exclude"
21     [ get-global " " split harvest ] bi@
22     diff
23     [ "bootstrap." prepend require ] each ;
24
25 : count-words ( pred -- )
26     all-words swap count number>string write ; inline
27
28 : print-time ( ms -- )
29     1000 /i
30     60 /mod swap
31     number>string write
32     " minutes and " write number>string write " seconds." print ;
33
34 : print-report ( -- )
35     "Core bootstrap completed in " write core-bootstrap-time get print-time
36     "Bootstrap completed in "      write bootstrap-time      get print-time
37
38     [ optimized>> ] count-words " compiled words" print
39     [ symbol? ] count-words " symbol words" print
40     [ ] count-words " words total" print
41     
42     "Bootstrapping is complete." print
43     "Now, you can run Factor:" print
44     vm write " -i=" write "output-image" get print flush ;
45
46 : save/restore-error ( quot -- )
47     error get-global
48     error-continuation get-global
49     [ call ] 2dip
50     error-continuation set-global
51     error set-global ; inline
52
53 [
54     ! We time bootstrap
55     millis
56
57     default-image-name "output-image" set-global
58
59     "math compiler threads help io tools ui ui.tools unicode handbook" "include" set-global
60     "" "exclude" set-global
61
62     (command-line) parse-command-line
63
64     ! Set dll paths
65     os wince? [ "windows.ce" require ] when
66     os winnt? [ "windows.nt" require ] when
67
68     "staging" get "deploy-vocab" get or [
69         "stage2: deployment mode" print
70     ] [
71         "debugger" require
72         "alien.prettyprint" require
73         "inspector" require
74         "tools.errors" require
75         "listener" require
76         "none" require
77     ] if
78
79     load-components
80
81     millis over - core-bootstrap-time set-global
82
83     run-bootstrap-init
84
85     f error set-global
86     f error-continuation set-global
87
88     millis swap - bootstrap-time set-global
89     print-report
90
91     "deploy-vocab" get [
92         "tools.deploy.shaker" run
93     ] [
94         "staging" get [
95             "vocab:bootstrap/finish-staging.factor" run-file
96         ] [
97             "vocab:bootstrap/finish-bootstrap.factor" run-file
98         ] if
99
100         "output-image" get save-image-and-exit
101     ] if
102 ] [
103     drop
104     [
105         load-help? off
106         [ "vocab:bootstrap/bootstrap-error.factor" parse-file ] save/restore-error
107         call
108     ] with-scope
109 ] recover