]> gitweb.factorcode.org Git - factor.git/blob - basis/bootstrap/compiler/compiler.factor
factor: more top level forms.
[factor.git] / basis / bootstrap / compiler / compiler.factor
1 ! Copyright (C) 2007, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays assocs assocs.private classes
4 classes.tuple.private compiler.units cpu.architecture hashtables
5 hashtables.private io kernel libc math math.parser memory
6 namespaces namespaces.private quotations quotations.private
7 sbufs sequences sequences.private splitting system vectors
8 vocabs vocabs.loader words ;
9 FROM: compiler => enable-optimizer ;
10 IN: bootstrap.compiler
11
12 ! Don't bring this in when deploying, since it will store a
13 ! reference to 'eval' in a global variable
14 "staging" get [
15     "alien.remote-control" require
16 ] unless
17
18 { "boostrap.compiler" "prettyprint" } "alien.prettyprint" require-when
19 ! USE-WHEN-LOADED: alien.prettyprint { "boostrap.compiler" "prettyprint" }
20
21 "cpu." cpu name>> append require
22
23 enable-cpu-features
24
25 enable-optimizer
26
27 ! Push all tuple layouts to tenured space to improve method caching
28 gc
29
30 : compile-unoptimized ( words -- )
31     [ [ subwords ] map ] keep suffix concat
32     [ word-optimized? ] reject compile ;
33
34 "debug-compiler" get [
35
36     nl
37     "Compiling..." write flush
38
39     ! Compile a set of words ahead of the full compile.
40     ! This set of words was determined semi-empirically
41     ! using the profiler. It improves bootstrap time
42     ! significantly, because frequently called words
43     ! which are also quick to compile are replaced by
44     ! compiled definitions as soon as possible.
45     {
46         not ?
47
48         2over
49
50         array? hashtable? vector?
51         tuple? sbuf? tombstone?
52         curried? composed? callable?
53         quotation?
54
55         curry compose uncurry
56
57         array-nth set-array-nth
58
59         wrap probe
60
61         (get-namestack)
62
63         layout-of
64     } compile-unoptimized
65
66     "." write flush
67
68     {
69         bitand bitor bitxor bitnot
70     } compile-unoptimized
71
72     "." write flush
73
74     {
75         + * 2/ < <= > >= shift
76     } compile-unoptimized
77
78     "." write flush
79
80     {
81         new-sequence nth push pop last flip
82     } compile-unoptimized
83
84     "." write flush
85
86     {
87         hashcode* = equal? assoc-stack (assoc-stack) get set
88     } compile-unoptimized
89
90     "." write flush
91
92     {
93         member-eq? split harvest sift cut cut-slice subseq-start index clone
94         set-at reverse push-all class-of number>string string>number
95         like clone-like
96     } compile-unoptimized
97
98     "." write flush
99
100     {
101         read-lines prefix suffix unclip new-assoc assoc-union!
102         word-prop set-word-prop 1array 2array 3array ?nth
103     } compile-unoptimized
104
105     "." write flush
106
107     os windows? [
108         "GetLastError" "windows.kernel32" lookup-word
109         "FormatMessageW" "windows.kernel32" lookup-word
110         2array compile-unoptimized
111     ] when
112
113     os unix? [
114         "(dlerror)" "alien.libraries.unix" lookup-word
115         1array compile-unoptimized
116     ] when
117
118     {
119         malloc calloc free memcpy
120     } compile-unoptimized
121
122     "." write flush
123
124     loaded-vocab-names [ vocab-words compile-unoptimized "." write flush ] each
125
126     " done" print flush
127
128     "alien.syntax" require
129     "io.streams.byte-array.fast" require
130
131 ] unless