1 Image define: #Definition &parents: {Cloneable} &slots:
2 {#bootstrapFilenames ->
3 "The names of the sources used to build the kernel REPL image, in necessary
5 ({'mobius/pre-bootstrap'.
28 'core/stack'. "Used by the conditionStack."
29 'core/condition'. "Essential error-handling logic."
30 'core/condition-epilogue'. "Error types for previous libraries."
31 'core/stream'. "Basic Streams, only depends on condition.slate."
32 'core/stream-collections'. "Streams over previous collection libraries."
33 'core/stream-transforms'. "Stream operation types."
34 'core/external'. "Abstract type for external resources and streams."
35 'core/console'. "Console I/O."
36 'core/file'. "File I/O."
37 'core/print'. "Print methods, pretty-printing (of objects, not source)."
38 'core/types'. "The object-based type system."
49 'mobius/post-bootstrap'.
50 } collect: [| :name | 'src/' ; name ; '.slate']).
51 #filename -> Nil. "The filename for the image."
52 #wordSize -> Platform Current bytesPerWord * 8. "The size of a word in bits of the image"
53 #primitives -> ExtensibleArray new.
54 #littleEndian -> True. "Whether to have a little-endian byte-word format."
55 #bootstrapDirectory -> '.' "Where the source filename paths relate to."
58 Image Definition primitives clear.
60 "here are the primitives"
62 inform: 'Adding primitive ' ; each printString.
63 Image Definition primitives add:
64 each key key -> (Syntax MethodDefinition new `>>
65 [selector: each key value.
66 roles: (each value collect: [| :val | val = #NoRoleObject ifFalse: [Syntax UnaryMessage sending: val]]). ]).
68 0 -> #asMethod:on: -> #(MethodTraits SymbolTraits ArrayTraits).
69 1 -> #asAccessor:for:on: -> #(MethodTraits SymbolTraits NoRoleObject ArrayTraits).
70 2 -> #_map -> #(RootTraits).
71 3 -> #_map: -> #(RootTraits MapTraits).
72 4 -> #addRolesFrom: -> #(RootTraits RootTraits).
73 5 -> #removeFrom: -> #(MethodTraits ArrayTraits).
74 6 -> #clone -> #(CloneableTraits).
75 7 -> #cloneSettingSlots:to: -> #(RootTraits ArrayTraits ArrayTraits).
76 8 -> #cloneWithSlot:valued: -> #(RootTraits SymbolTraits NoRoleObject).
77 9 -> #cloneWithDelegate:valued: -> #(RootTraits SymbolTraits NoRoleObject).
78 10 -> #cloneWithDelegate:before:valued: -> #(RootTraits SymbolTraits NoRoleObject NoRoleObject).
79 11 -> #cloneWithDelegate:after:valued: -> #(RootTraits SymbolTraits NoRoleObject NoRoleObject).
80 12 -> #cloneWithoutSlot: -> #(RootTraits SymbolTraits).
81 13 -> #atSlotNamed: -> #(RootTraits SymbolTraits).
82 14 -> #atSlotNamed: -> #(SmallIntegerProto SymbolTraits).
83 15 -> #atSlotNamed:put: -> #(RootTraits SymbolTraits NoRoleObject).
84 16 -> #forwardTo: -> #(RootTraits NoRoleObject).
85 17 -> #newSize: -> #(ByteArrayTraits NoRoleObject).
86 18 -> #size -> #(ByteArrayTraits).
87 19 -> #byteAt: -> #(ByteArrayTraits NoRoleObject).
88 20 -> #byteAt:put: -> #(ByteArrayTraits NoRoleObject NoRoleObject).
89 21 -> #newSize: -> #(ArrayTraits NoRoleObject).
90 22 -> #size -> #(ArrayTraits).
91 23 -> #at: -> #(ArrayTraits NoRoleObject).
92 24 -> #at:put: -> #(ArrayTraits NoRoleObject NoRoleObject).
93 25 -> #ensure: -> #(MethodTraits MethodTraits).
94 26 -> #applyTo: -> #(MethodTraits ArrayTraits).
95 27 -> #sendTo: -> #(SymbolTraits ArrayTraits).
96 28 -> #sendTo:through: -> #(SymbolTraits ArrayTraits ArrayTraits).
97 29 -> #findOn: -> #(SymbolTraits ArrayTraits).
98 30 -> #findOn:after: -> #(SymbolTraits ArrayTraits NoRoleObject).
99 31 -> #runArgsInto: -> #(LobbyObject ByteArrayTraits).
100 32 -> #exit: -> #(LobbyObject SmallIntegerTraits).
101 33 -> #'==' -> #(RootTraits RootTraits).
102 34 -> #identityHash -> #(RootTraits).
103 35 -> #identityHash -> #(SmallIntegerTraits).
104 36 -> #'=' -> #(SmallIntegerTraits SmallIntegerTraits).
105 37 -> #'<' -> #(SmallIntegerTraits SmallIntegerTraits).
106 38 -> #bitOr: -> #(SmallIntegerTraits SmallIntegerTraits).
107 39 -> #bitAnd: -> #(SmallIntegerTraits SmallIntegerTraits).
108 40 -> #bitXor: -> #(SmallIntegerTraits SmallIntegerTraits).
109 41 -> #bitNot -> #(SmallIntegerTraits).
110 42 -> #bitShift: -> #(SmallIntegerTraits SmallIntegerTraits).
111 43 -> #'+' -> #(SmallIntegerTraits SmallIntegerTraits).
112 44 -> #'-' -> #(SmallIntegerTraits SmallIntegerTraits).
113 45 -> #'*' -> #(SmallIntegerTraits SmallIntegerTraits).
114 46 -> #quo: -> #(SmallIntegerTraits SmallIntegerTraits).
115 47 -> #interrupt -> #(InterpreterTraits).
116 48 -> #initializeThreadOn: -> #(InterpreterTraits NoRoleObject).
117 49 -> #framePointerOf: -> #(InterpreterTraits NoRoleObject).
118 50 -> #stackPointer -> #(InterpreterTraits).
119 51 -> #framePointer -> #(InterpreterTraits).
120 52 -> #codePointer -> #(InterpreterTraits).
121 53 -> #collectGarbage -> #(LobbyObject).
122 54 -> #bytesPerWord -> #(LobbyObject).
123 55 -> #firstObject -> #(LobbyObject).
124 56 -> #nextObjectAfter: -> #(LobbyObject NoRoleObject).
125 57 -> #firstObjectDelegatingTo: -> #(LobbyObject NoRoleObject).
126 58 -> #nextObjectAfter:delegatingTo: -> #(LobbyObject NoRoleObject NoRoleObject).
127 59 -> #firstObjectReferringTo: -> #(LobbyObject NoRoleObject).
128 60 -> #nextObjectAfter:referringTo: -> #(LobbyObject NoRoleObject NoRoleObject).
129 61 -> #isLastObject: -> #(LobbyObject NoRoleObject).
130 62 -> #isLastObject:delegatingTo: -> #(LobbyObject NoRoleObject NoRoleObject).
131 63 -> #isLastObject:referringTo: -> #(LobbyObject NoRoleObject NoRoleObject).
132 64 -> #read:from:into:startingAt: -> #(ConsoleObject NoRoleObject NoRoleObject NoRoleObject NoRoleObject).
133 65 -> #write:to:from:startingAt: -> #(ConsoleObject NoRoleObject NoRoleObject NoRoleObject NoRoleObject).
134 66 -> #flushOutput -> #(ConsoleObject).
135 67 -> #handleFor: -> #(FileTraits NoRoleObject).
136 68 -> #handleForInput: -> #(FileTraits NoRoleObject).
137 69 -> #handleForOutput: -> #(FileTraits NoRoleObject).
138 70 -> #handleForNew: -> #(FileTraits NoRoleObject).
139 71 -> #close: -> #(FileTraits NoRoleObject).
140 72 -> #read:from:into:startingAt: -> #(FileTraits NoRoleObject NoRoleObject NoRoleObject NoRoleObject).
141 73 -> #write:to:from:startingAt: -> #(FileTraits NoRoleObject NoRoleObject NoRoleObject NoRoleObject).
142 74 -> #reposition:to: -> #(FileTraits NoRoleObject NoRoleObject).
143 75 -> #positionOf: -> #(FileTraits NoRoleObject).
144 76 -> #atEndOf: -> #(FileTraits NoRoleObject).
145 77 -> #sizeOf: -> #(FileTraits NoRoleObject).
146 78 -> #saveImageNamed: -> #(LobbyObject NoRoleObject).
147 79 -> #primitiveOpen: -> #(DirectoryTraits NoRoleObject).
148 80 -> #primitiveClose: -> #(DirectoryTraits NoRoleObject).
149 81 -> #primitiveRead:into: -> #(DirectoryTraits NoRoleObject NoRoleObject).
150 82 -> #primitiveGetCurrentDirectory: -> #(DirectoryTraits NoRoleObject).
151 83 -> #primitiveSetCurrentDirectory: -> #(DirectoryTraits NoRoleObject).
152 84 -> #significand -> #(FloatTraits).
153 85 -> #exponent -> #(FloatTraits).
154 86 -> #withSignificand:exponent: -> #(FloatTraits NoRoleObject NoRoleObject).
155 87 -> #'=' -> #(FloatTraits FloatTraits).
156 88 -> #'<' -> #(FloatTraits FloatTraits).
157 89 -> #'+' -> #(FloatTraits FloatTraits).
158 90 -> #'-' -> #(FloatTraits FloatTraits).
159 91 -> #'*' -> #(FloatTraits FloatTraits).
160 92 -> #'/' -> #(FloatTraits FloatTraits).
161 93 -> #raisedTo: -> #(FloatTraits FloatTraits).
162 94 -> #ln -> #(FloatTraits).
163 95 -> #exp -> #(FloatTraits).
164 96 -> #sin -> #(FloatTraits).
165 97 -> #cos -> #(FloatTraits).
166 98 -> #tan -> #(FloatTraits).
167 99 -> #arcsin -> #(FloatTraits).
168 100 -> #arccos -> #(FloatTraits).
169 101 -> #arctan -> #(FloatTraits).
170 102 -> #arctan: -> #(FloatTraits FloatTraits).
171 103 -> #newFixedAreaSized: -> #(ByteArrayTraits NoRoleObject).
172 104 -> #close: -> #(ByteArrayTraits NoRoleObject).
173 105 -> #noteNewReferenceTo: -> #(ByteArrayTraits NoRoleObject).
174 106 -> #write:into:startingAt: -> #(ByteArrayTraits NoRoleObject NoRoleObject NoRoleObject).
175 107 -> #read:from:startingAt: -> #(ByteArrayTraits NoRoleObject NoRoleObject NoRoleObject).
176 108 -> #sizeOf: -> #(ByteArrayTraits NoRoleObject).
177 109 -> #resize:to: -> #(ByteArrayTraits NoRoleObject NoRoleObject).
178 110 -> #addressOf:at:into: -> #(ByteArrayTraits NoRoleObject NoRoleObject NoRoleObject).
179 111 -> #primitiveOpen:handle: -> #(ExternalLibraryTraits ASCIIStringTraits ByteArrayTraits).
180 112 -> #primitiveClose: -> #(ExternalLibraryTraits ByteArrayTraits).
181 113 -> #primitiveLookup:handle:into: -> #(ExternalLibraryTraits ASCIIStringTraits ByteArrayTraits ByteArrayTraits).
182 114 -> #primitiveErrorInto: -> #(ExternalLibraryTraits ByteArrayTraits).
183 115 -> #primitiveApply:accepting:callFormat:returning:to: -> #(ExternalLibraryTraits ByteArrayTraits NoRoleObject NoRoleObject NoRoleObject ArrayTraits).
184 116 -> #timeSinceEpoch -> #(LobbyObject).
185 117 -> #cloneSystem -> #(LobbyObject).
186 118 -> #readFromPipe:start:end: -> #(NoRoleObject SmallIntegerTraits SmallIntegerTraits SmallIntegerTraits).
187 119 -> #writeToPipe:start:end: -> #(NoRoleObject SmallIntegerTraits SmallIntegerTraits SmallIntegerTraits).
188 120 -> #selectOnReadPipesFor: -> #(ArrayTraits SmallIntegerTraits).
189 121 -> #selectOnWritePipesFor: -> #(ArrayTraits SmallIntegerTraits).
190 122 -> #closePipe -> #(SmallIntegerTraits).
191 123 -> #socketCreate:protocol: -> #(SmallIntegerTraits SmallIntegerTraits SmallIntegerTraits).
192 124 -> #socketListenSize: -> #(SmallIntegerTraits SmallIntegerTraits).
193 125 -> #socketAcceptConnection -> #(SmallIntegerTraits). "returns {retval. struct sockaddr}"
194 126 -> #socketBindOn: -> #(SmallIntegerTraits ByteArrayTraits).
195 127 -> #socketConnect: -> #(SmallIntegerTraits ByteArrayTraits).
196 128 -> #createIPAddress:port:options: -> #(SmallIntegerTraits NoRoleObject NoRoleObject NoRoleObject). "AF_INET createIPAddress: {127. 0. 0. 1} port: 80 options: #()"
197 129 -> #smallIntegerMinimum -> #(LobbyObject).
198 130 -> #smallIntegerMaximum -> #(LobbyObject).
199 131 -> #socketGetError -> #(SmallIntegerTraits).
200 "lobby getAddrInfo: ('slatelanguage.org' as: ByteArray)
201 service: ('http' as: ByteArray)
202 family: Net Socket Domains IP4
203 type: Net Socket Types Stream
204 protocol: Net Socket Protocols Default
206 "returns an integer to the ticket you've been assigned (since it is asynchronous)"
207 132 -> #getAddrInfo:service:family:type:protocol:flags: -> #(LobbyObject NoRoleObject NoRoleObject SmallIntegerTraits SmallIntegerTraits SmallIntegerTraits SmallIntegerTraits).
208 "Gets the result of the earlier async call or Nil if it's not ready. if it's done you get an error code(int) or an array (resolved addresses)"
209 133 -> #getAddrInfoResult -> #(SmallIntegerTraits).
210 134 -> #freeAddrInfoResult -> #(SmallIntegerTraits).
211 135 -> #vmArgCount -> #(LobbyObject).
212 136 -> #vmArg: -> #(LobbyObject SmallIntegerTraits).
213 137 -> #environmentVariables -> #(LobbyObject).
214 138 -> #environmentAt:put: -> #(LobbyObject ASCIIStringTraits ASCIIStringTraits).
215 139 -> #environmentRemoveKey: -> #(LobbyObject ASCIIStringTraits).
216 140 -> #isLittleEndian -> #(LobbyObject).
217 141 -> #systemName -> #(LobbyObject).
218 142 -> #systemRelease -> #(LobbyObject).
219 143 -> #systemVersion -> #(LobbyObject).
220 144 -> #systemPlatform -> #(LobbyObject).
221 145 -> #systemMachine -> #(LobbyObject).
222 146 -> #systemExecute: -> #(LobbyObject ASCIIStringTraits).
223 147 -> #startProfiling -> #(LobbyObject).
224 148 -> #stopProfiling -> #(LobbyObject).
225 149 -> #profilerStatistics -> #(LobbyObject).
226 150 -> #deleteFileNamed: -> #(FileTraits ASCIIStringTraits).
227 151 -> #touchFileReplaceMe: -> #(FileTraits ASCIIStringTraits). "replace me with a new primitive"
228 152 -> #renameFileNamed:to: -> #(FileTraits ASCIIStringTraits ASCIIStringTraits).
229 153 -> #informationForFileNamed: -> #(FileTraits ASCIIStringTraits).
230 154 -> #createDirectoryNamed: -> #(DirectoryTraits ASCIIStringTraits).
231 155 -> #renameDirectoryNamed:to: -> #(DirectoryTraits ASCIIStringTraits ASCIIStringTraits).
232 156 -> #deleteDirectoryNamed: -> #(DirectoryTraits ASCIIStringTraits).
233 157 -> #objectPointerAddress: -> #(LobbyObject NoRoleObject).
236 Image Definition traits define: #cached &builder: [Dictionary new].
238 Image Definition cached at: 'bare' put: (Image Definition clone `setting: #(bootstrapFilenames)
239 to: {{'src/mobius/pre-bootstrap.slate'}}).
240 "An Image Definition consisting of the bare minimum to run some primitive call,
241 like adding 3 + 4, say."
242 "TODO: refactor Image Definition so that we can just supply a block here."
244 def@(Image Definition traits) newNamed: filename littleEndian: littleEndian wordSize: wordSize
246 (def clone `setting: #(littleEndian wordSize) to: {littleEndian. wordSize})
247 `>> [| :newDef | filename: (newDef defaultFilename &base: filename). ]
250 def@(Image Definition traits) defaultFilename &base: base
251 "Generates a unique and descriptive image filename based on the definition."
253 base `defaultsTo: 'kernel'.
255 ; '.' ; (def littleEndian ifTrue: ['little'] ifFalse: ['big']) "endianness"
256 ; '.' ; def wordSize printString "size of a word in bits"
257 ; '.' ; (lobby timeSinceEpoch as: Integer) printString "timestamp"
261 def@(Image Definition traits) generate
262 [| builder bootBlock statements |
263 builder: (Image Bootstrap Generator new &littleEndian: def littleEndian &wordSize: def wordSize).
264 def filename ifNil: [def filename: def defaultFilename].
265 (File newNamed: def filename &mode: File CreateWrite) sessionDo:
266 [| :imageFile image dir |
267 image: imageFile writer.
268 bootBlock: Syntax Block new.
269 statements: bootBlock statements writer.
270 dir: (Directory newNamed: def bootstrapDirectory).
271 (def bootstrapFilenames collect: [| :each | dir / each]) do:
273 inform: 'Parsing: ' ; file locator printString.
274 file mode: file Read.
276 [| :file | (Syntax Parser newOn: file reader) >> statements]].
277 bootBlock statements: statements contents.
278 inform: 'Building image: \'' ; def filename ; '\''.
279 builder generateImageBooting: bootBlock withPrims: def primitives.
280 builder emitOn: image].
284 i@Image generateAmd64Test
286 ((i Definition cached at: 'bare') newNamed: 'k64' littleEndian: True wordSize: 64) generate.
289 i@Image generateAmd64
291 (i Definition newNamed: 'amd64' littleEndian: True wordSize: 64) generate.
294 i@Image bootstrap &littleEndian: littleEndian &wordSize: wordSize
295 "Only to be called during or after fullCleanBootstrap to build new images
296 based on the new VM Definition."
298 wordSize `defaultsTo: Platform Current bytesPerWord * 8.
299 littleEndian `defaultsTo: (Platform Current endianness == #LittleEndian).
300 def: (i Definition newNamed: 'kernel.new' littleEndian: littleEndian wordSize: wordSize).
301 def cached at: {'new'. littleEndian ifTrue: ['little'] ifFalse: ['big']. wordSize} put: def.
303 inform: 'Generated new kernel image at: \'' ; def filename ; '\''.
304 inform: 'Suggested next command: ' ; StartupArguments first ; ' -i ' ; def filename.