Renamed pre/post bootstrap actions sources.
[cslatevm.git] / src / mobius / bootstrap-post-to-load.slate
blob2a4cb54db3cb16dc37e5615f0e77ee1aba21a210
1 "What to do after all code bootstrapping library code is evaluated.
2 This code is compiled in to the bootstrapped seed image and then run when it
3 starts, so changes to this source require an image bootstrap to take full
4 effect."
6 ns@(Namespace traits) inform: message &target: target
7 "A simple way to print a message onto an ExternalResource (by default the
8 Console)."
9 [| *rest |
10   target `defaultsTo: DebugConsole.
11   target writer ; (rest isEmpty ifTrue: [message] ifFalse: [#sprintf* sendTo: {message} ; rest]) ; '\n'.
12   target writer flush.
15 inform: 'Performing post-bootstrap actions...'.
17 "These exist just for bootstrapping purposes, to be replaced by Module code:"
19 Syntax import: #nodes from: lobby.
20 Syntax import: #tokens from: lobby.
21 Syntax import: #Lexer from: lobby.
22 Syntax import: #Parser from: lobby.
24 "TODO: Simplify these load: stubs to avoid maintenance costs."
26 ns@(Namespace traits) load: fileName &in: namespace &verbose: verbose &showLoadMessage: showLoadMessage &imports: imports
27 "A command to open a file with the name, load, and compile/evaluate the
28 contents within the argument namespace or an optional override."
29 [| src retry |
30   src: (File newNamed: fileName &mode: File Read).
31   src exists ifTrue: [retry: Retry clone.
32                       _@(retry) describeOn: console [ console ; 'Retry loading ' ; fileName printString ;'\n' ].
33                       [ns load: src &in: namespace &verbose: verbose &showLoadMessage: showLoadMessage &imports: imports]
34                         handlingCases: {retry -> [|:_| ^ (ns load: fileName &in: namespace &verbose: verbose)]}]
35              ifFalse: [warn: 'Called load: on something that didn\'t describe a file. Returning the input: ' ; fileName printString. fileName]
38 ns@(Namespace traits) load: file@(File traits) &in: namespace &verbose: verbose &showLoadMessage: showLoadMessage &imports: imports
39 "A command to open the file, load, and compile/evaluate the
40 contents within the argument namespace or an optional override."
41 [| defaultPaths |
42   verbose `defaultsTo: False.
43   namespace `defaultsTo: ns.
44   (imports `defaultsTo: #{})
45     do: [| :import | namespace import: import value from: import key].
46   (showLoadMessage `defaultsTo: True)
47     ifTrue: [inform: 'Loading %r', file locator].
48   defaultPaths: {Directory current}.
49   (file locator isSameAs: file RelativeLocator)
50     ifTrue:
51       [[file exists] whileFalse:
52         [(globals defaultPaths before: file locator basePath)
53           ifNil: [error: 'Could not find the file relative to any of the default directories.'. ^ Nil]
54           ifNotNilDo: [| :newL | file locator basePath: newL]]].
55   file ASCIIReader sessionDo:
56     [| :input aParser |
57      "Ignore an initial she-bang line."
58      (input peek: 2) = '#!' ifTrue: [input upTo: $\n].
59      (aParser: (Syntax Parser newOn: input)) do:
60        [| :each |
61         verbose ifTrue:
62           [inform: 'Parsed to line %s', aParser lexer lineNumber].
63         each evaluateIn: namespace]] &mode: file Read
66 ns@(Namespace traits) use: file
68   ((result ::= ns new load: file) hasSlotNamed: #exports)
69     ifTrue: [result exports] ifFalse: [result]
72 ns@(Namespace traits) reload: file
73 [[ns load: file] on: RebindError do: [| :x | x return: Nil]].
76 This is defined on == but we expect this to use = for comparing strings like:
77 StartupArguments includes: '--image-help'
79 #includes: removeMethodFrom: {Array traits. NoRole} &ifNotFound: [].
81 "Load macro support libraries, which aren't needed in the bootstrap as macros
82 are expanded by the bootstrap generator."
83 load: 'src/core/stream-terminals.slate'.
84 load: 'src/syntax/quote.slate'.
85 load: 'src/syntax/cascade.slate'.
86 load: 'src/syntax/assignment.slate'.
87 load: 'src/syntax/binding.slate'.
88 load: 'src/lib/macro.slate'.
89 load: 'src/syntax/case.slate'.
91 "recompile everything with the new compiler so that we have line number info, etc."
92 load: 'src/mobius/rebootstrap.slate'.
94 "Load the prelude, customizable separately from the bootstrap image, which
95 loads non-optional but useful libraries."
96 load: 'src/mobius/bootstrap-final-loadable.slate'.
98 "Invoke the method defined by the prelude as the image startup."
99 "lobby start"
101 "Drop the old bootstrap stack which takes up a lot of space."
102 (lobby globals specialOops at: 17) initializeThreadOn: [[lobby start] ensure: [lobby exit: 0]].