]> gitweb.factorcode.org Git - factor.git/blob - basis/bootstrap/compiler/compiler.factor
scryfall: make decks better, import from moxfield
[factor.git] / basis / bootstrap / compiler / compiler.factor
1 ! Copyright (C) 2007, 2010 Slava Pestov.
2 ! See https://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
20 "cpu." cpu name>> append require
21
22 enable-cpu-features
23
24 enable-optimizer
25
26 ! Push all tuple layouts to tenured space to improve method caching
27 gc
28
29 : compile-unoptimized ( words -- )
30     [ [ subwords ] map ] keep suffix concat
31     [ word-optimized? ] reject compile ;
32
33 "debug-compiler" get [
34
35     nl
36     "Compiling..." write flush
37
38     ! Compile a set of words ahead of the full compile.
39     ! This set of words was determined semi-empirically
40     ! using the profiler. It improves bootstrap time
41     ! significantly, because frequently called words
42     ! which are also quick to compile are replaced by
43     ! compiled definitions as soon as possible.
44     {
45         not ?
46
47         2over
48
49         array? hashtable? vector?
50         tuple? sbuf? tombstone?
51         curried? composed? callable?
52         quotation?
53
54         curry compose uncurry
55
56         array-nth set-array-nth
57
58         wrap probe
59
60         (get-namestack)
61
62         layout-of
63     } compile-unoptimized
64
65     "." write flush
66
67     {
68         bitand bitor bitxor bitnot
69     } compile-unoptimized
70
71     "." write flush
72
73     {
74         + * 2/ < <= > >= shift
75     } compile-unoptimized
76
77     "." write flush
78
79     {
80         new-sequence nth push pop last flip
81     } compile-unoptimized
82
83     "." write flush
84
85     {
86         hashcode* = equal? assoc-stack assoc-stack-from get set
87     } compile-unoptimized
88
89     "." write flush
90
91     {
92         member-eq? split harvest sift cut cut-slice subseq-start subseq-index
93         index clone set-at reverse push-all class-of number>string string>number
94         like clone-like
95     } compile-unoptimized
96
97     "." write flush
98
99     {
100         read-lines prefix suffix unclip new-assoc assoc-union!
101         word-prop set-word-prop 1array 2array 3array ?nth
102     } compile-unoptimized
103
104     "." write flush
105
106     os windows? [
107         "GetLastError" "windows.kernel32" lookup-word
108         "FormatMessageW" "windows.kernel32" lookup-word
109         2array compile-unoptimized
110     ] when
111
112     os unix? [
113         "(dlerror)" "alien.libraries.unix" lookup-word
114         1array compile-unoptimized
115     ] when
116
117     {
118         malloc calloc free memcpy
119     } compile-unoptimized
120
121     "." write flush
122
123     loaded-vocab-names [ vocab-words compile-unoptimized "." write flush ] each
124
125     " done" print flush
126
127     "alien.syntax" require
128     "io.streams.byte-array.fast" require
129
130 ] unless