Repository navigation
Expand file tree
/
Copy pathboot.scm
More file actions
83 lines (63 loc) · 2.91 KB
/
Copy pathboot.scm
File metadata and controls
83 lines (63 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
;; boot.scm - load all code, initialize module system, and compile everything in-place.
;; the toplevel value BOOT-STAGE can be used to stop at a certain point. used mainly for testing.
;; BOOT-STAGE 1: only load expander
;; BOOT-STAGE 2: load expander, syntax and types but not compiler
;; BOOT-STAGE 3: load compiler
;; BOOT-STAGE 4: bootstrap the whole system
;; order is important
;; Step 1) Load expander
(begin
(load "scheme/expand.scm")
;; Initial module system setup
(define *core-module* (module-make "arete"))
(table-set! (top-level-value 'module-table) "arete" *core-module*)
(table-set! *core-module* "module-export-all" #t)
(table-set! *core-module* "module-stage" 2)
(define *current-module* *core-module*)
;; populate core module with already-defined things
(top-level-for-each
(lambda (k v)
(if (or (procedure? v) (memq k '(unspecified)))
((lambda (name)
(set-top-level-value! name v)
(table-set! (table-ref *core-module* "module-exports") k k)
(table-set! *core-module* k k))
(module-qualify *core-module* k)))))
(define (make-empty-module name)
(define mod (module-make name))
(table-set! (top-level-value 'module-table) name mod)
(table-set! mod "module-export-all" #t)
(table-set! mod "module-stage" 2)
mod)
;; This just allows us to run some R7RS benchmarks.
(for-each1 make-empty-module '("scheme#base" "scheme#cxr" "scheme#file" "scheme#inexact" "scheme#write"
"scheme#time" "scheme#read" "scheme#char" "scheme#complex"))
;; User module is where toplevel code outside of libraries runs (REPL, random scripts)
(define *user-module* (module-make "user"))
(table-set! (top-level-value 'module-table) "user" *user-module*)
(table-set! *user-module* "module-export-all" #t)
(table-set! *user-module* "module-stage" 2)
(set-top-level-value! '*current-module* *core-module*)
; Install expander
(set-top-level-value! 'expander expand-toplevel))
;; Step 2) Load core syntax (things like let, record,s etc)
(if (>= (top-level-value 'BOOT-STAGE 10) 2)
(begin
(load "scheme/syntax.scm")
(load "scheme/types.scm")))
;; Step 3) Load compiler and bootstrap
(if (>= (top-level-value 'BOOT-STAGE 10) 3)
(begin
(load "scheme/optimizer.scm")
(load "scheme/compiler.scm")
;; Install compiler. All code loaded after this point (not including the currently executing file) will be compiled
;; and run on the virtual machine
(set-top-level-value! 'compiler compile-toplevel)
))
(if (>= (top-level-value 'BOOT-STAGE 10) 4) (pull-up-bootstraps))
;; Step 4) Load modules
(if (>= (top-level-value 'BOOT-STAGE 10) 5)
(load "scheme/library.scm"))
;; Finish bootstrapping by importing all functions defined in (arete) to the (user) module
(expand-import (top-level-value '*user-module*) '(arete))
(set-top-level-value! '*current-module* (top-level-value '*user-module*))