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
6 ns@(Namespace traits) inform: message &target: target
7 "A simple way to print a message onto an ExternalResource (by default the
10 target `defaultsTo: DebugConsole.
11 target writer ; (rest isEmpty ifTrue: [message] ifFalse: [#sprintf* sendTo: {message} ; rest]) ; '\n'.
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."
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."
42 verbose `defaultsTo: False.
43 namespace `defaultsTo: ns.
44 imports do: [| :import | namespace import: import value from: import key].
45 (showLoadMessage `defaultsTo: True)
46 ifTrue: [inform: 'Loading %r', file locator].
47 defaultPaths: {Directory current}.
48 (file locator isSameAs: file RelativeLocator)
50 [[file exists] whileFalse:
51 [(globals defaultPaths before: file locator basePath)
52 ifNil: [error: 'Could not find the file relative to any of the default directories.'. ^ Nil]
53 ifNotNilDo: [| :newL | file locator basePath: newL]]].
54 file ASCIIReader sessionDo:
56 "Ignore an initial she-bang line."
57 (input peek: 2) = '#!' ifTrue: [input upTo: $\n].
58 (aParser: (Syntax Parser newOn: input)) do:
61 [inform: 'Parsed to line %s', aParser lexer lineNumber].
62 each evaluateIn: namespace]] &mode: file Read
65 ns@(Namespace traits) use: file
67 ((result := ns new load: file) hasSlotNamed: #exports)
68 ifTrue: [result exports] ifFalse: [result]
72 This is defined on == but we expect this to use = for comparing strings like:
73 StartupArguments includes: '--image-help'
75 #includes: removeMethodFrom: {Array traits. NoRole} &ifNotFound: [].
77 "Load macro support libraries, which aren't needed in the bootstrap as macros
78 are expanded by the bootstrap generator."
79 load: 'src/core/stream-terminals.slate'.
80 load: 'src/syntax/quote.slate'.
81 load: 'src/syntax/cascade.slate'.
82 load: 'src/lib/macro.slate'.
84 "recompile everything with the new compiler so that we have line number info, etc."
85 load: 'src/mobius/rebootstrap.slate'.
87 "Load the prelude, customizable separately from the bootstrap image, which
88 loads non-optional but useful libraries."
89 load: 'src/mobius/prelude.slate'.
91 "Invoke the method defined by the prelude as the image startup."
94 "Drop the old bootstrap stack which takes up a lot of space."
95 (lobby globals specialOops at: 17) initializeThreadOn: [[lobby start] ensure: [lobby exit: 0]].