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
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: [#formatting 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 &showLoadMessage &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 &showLoadMessage &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 `defaultsTo: #{})
45 do: [| :import | namespace import: import value from: import key].
46 (showLoadMessage `defaultsTo: True)
47 ifTrue: [inform: 'Loading ' ; file locator printString].
48 defaultPaths: {Directory current}.
49 (file locator isSameAs: file RelativeLocator)
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:
57 "Ignore an initial she-bang line."
58 (input peek: 2) = '#!' ifTrue: [input upTo: $\n].
59 (aParser: (Syntax Parser newOn: input)) do:
62 [inform: 'Parsed to line ' ; aParser lexer lineNumber printString].
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/format.slate'.
89 load: 'src/lib/macro.slate'.
90 load: 'src/syntax/case.slate'.
92 "recompile everything with the new compiler so that we have line number info, etc."
93 load: 'src/mobius/rebootstrap.slate'.
95 "Load the prelude, customizable separately from the bootstrap image, which
96 loads non-optional but useful libraries."
97 load: 'src/mobius/bootstrap-final-loadable.slate'.
99 "Invoke the method defined by the prelude as the image startup."
102 "Drop the old bootstrap stack which takes up a lot of space."
103 (lobby globals specialOops at: 17) initializeThreadOn: [[lobby start] ensure: [lobby exit: 0]].