1 define: #ImageDefinition &slots:
2 {#bootstrapDirectory -> '.'. "Where the source filename paths relate to."
3 #bootstrapFilenames -> {}. "The names of the sources used to build the kernel REPL image, in necessary load-order."
4 #filename -> Nil. "The filename for the image."
5 #wordSize -> (imports Platform Current bytesPerWord * 8). "The size of a word in bits of the image"
6 #primitives -> imports ExtensibleArray new.
7 #endianness -> #LittleEndian. "Whether to have a little-endian byte-word format."
10 ImageDefinition traits define: #PrimitiveDefaults &builder: [#{
11 {0. #asMethod:on:. {#MethodTraits. #SymbolTraits. #ArrayTraits}}.
12 {1. #asAccessor:for:on:. {#MethodTraits. #SymbolTraits. #NoRoleObject. #ArrayTraits}}.
13 {2. #_map. {#RootTraits}}.
14 {3. #_map:. {#RootTraits. #MapTraits}}.
15 {4. #addRolesFrom:. {#RootTraits. #RootTraits}}.
16 {5. #removeFrom:. {#MethodTraits. #ArrayTraits}}.
17 {6. #clone. {#CloneableTraits}}.
18 {7. #cloneSettingSlots:to:. {#RootTraits. #ArrayTraits. #ArrayTraits}}.
19 {8. #cloneWithSlot:valued:. {#RootTraits. #SymbolTraits. #NoRoleObject}}.
20 {9. #cloneWithDelegate:valued:. {#RootTraits. #SymbolTraits. #NoRoleObject}}.
21 {10. #cloneWithDelegate:before:valued:. {#RootTraits. #SymbolTraits. #NoRoleObject. #NoRoleObject}}.
22 {11. #cloneWithDelegate:after:valued:. {#RootTraits. #SymbolTraits. #NoRoleObject. #NoRoleObject}}.
23 {12. #cloneWithoutSlot:. {#RootTraits. #SymbolTraits}}.
24 {13. #atSlotNamed:. {#RootTraits. #SymbolTraits}}.
25 {14. #atSlotNamed:. {#SmallIntegerProto. #SymbolTraits}}.
26 {15. #atSlotNamed:put:. {#RootTraits. #SymbolTraits. #NoRoleObject}}.
27 {16. #forwardTo:. {#RootTraits. #NoRoleObject}}.
28 {17. #newSize:. {#ByteArrayTraits. #NoRoleObject}}.
29 {18. #size. {#ByteArrayTraits}}.
30 {19. #byteAt:. {#ByteArrayTraits. #NoRoleObject}}.
31 {20. #byteAt:put:. {#ByteArrayTraits. #NoRoleObject. #NoRoleObject}}.
32 {21. #newSize:. {#ArrayTraits. #NoRoleObject}}.
33 {22. #size. {#ArrayTraits}}.
34 {23. #at:. {#ArrayTraits. #NoRoleObject}}.
35 {24. #at:put:. {#ArrayTraits. #NoRoleObject. #NoRoleObject}}.
36 {25. #ensure:. {#MethodTraits. #MethodTraits}}.
37 {26. #applyTo:. {#MethodTraits. #ArrayTraits}}.
38 {27. #sendTo:. {#SymbolTraits. #ArrayTraits}}.
39 {28. #sendTo:through:. {#SymbolTraits. #ArrayTraits. #ArrayTraits}}.
40 {29. #findOn:. {#SymbolTraits. #ArrayTraits}}.
41 {30. #findOn:after:. {#SymbolTraits. #ArrayTraits. #NoRoleObject}}.
42 {31. #runArgsInto:. {#BootstrapObject. #ByteArrayTraits}}.
43 {32. #exit:. {#BootstrapObject. #SmallIntegerTraits}}.
44 {33. #'=='. {#RootTraits. #RootTraits}}.
45 {34. #identityHash. {#RootTraits}}.
46 {35. #identityHash. {#SmallIntegerTraits}}.
47 {36. #'='. {#SmallIntegerTraits. #SmallIntegerTraits}}.
48 {37. #'<'. {#SmallIntegerTraits. #SmallIntegerTraits}}.
49 {38. #bitOr:. {#SmallIntegerTraits. #SmallIntegerTraits}}.
50 {39. #bitAnd:. {#SmallIntegerTraits. #SmallIntegerTraits}}.
51 {40. #bitXor:. {#SmallIntegerTraits. #SmallIntegerTraits}}.
52 {41. #bitNot. {#SmallIntegerTraits}}.
53 {42. #bitShift:. {#SmallIntegerTraits. #SmallIntegerTraits}}.
54 {43. #'+'. {#SmallIntegerTraits. #SmallIntegerTraits}}.
55 {44. #'-'. {#SmallIntegerTraits. #SmallIntegerTraits}}.
56 {45. #'*'. {#SmallIntegerTraits. #SmallIntegerTraits}}.
57 {46. #quo:. {#SmallIntegerTraits. #SmallIntegerTraits}}.
58 {47. #interrupt. {#InterpreterTraits}}.
59 {48. #initializeThreadOn:. {#InterpreterTraits. #NoRoleObject}}.
60 {49. #framePointerOf:. {#InterpreterTraits. #NoRoleObject}}.
61 {50. #stackPointer. {#InterpreterTraits}}.
62 {51. #framePointer. {#InterpreterTraits}}.
63 {52. #codePointer. {#InterpreterTraits}}.
64 {53. #collectGarbage. {#BootstrapObject}}.
65 {54. #bytesPerWord. {#BootstrapObject}}.
66 {55. #firstObject. {#BootstrapObject}}.
67 {56. #nextObjectAfter:. {#BootstrapObject. #NoRoleObject}}.
68 {57. #firstObjectDelegatingTo:. {#BootstrapObject. #NoRoleObject}}.
69 {58. #nextObjectAfter:delegatingTo:. {#BootstrapObject. #NoRoleObject. #NoRoleObject}}.
70 {59. #firstObjectReferringTo:. {#BootstrapObject. #NoRoleObject}}.
71 {60. #nextObjectAfter:referringTo:. {#BootstrapObject. #NoRoleObject. #NoRoleObject}}.
72 {61. #isLastObject:. {#BootstrapObject. #NoRoleObject}}.
73 {62. #isLastObject:delegatingTo:. {#BootstrapObject. #NoRoleObject. #NoRoleObject}}.
74 {63. #isLastObject:referringTo:. {#BootstrapObject. #NoRoleObject. #NoRoleObject}}.
75 {64. #read:from:into:startingAt:. {#ConsoleObject. #NoRoleObject. #NoRoleObject. #NoRoleObject. #NoRoleObject}}.
76 {65. #write:to:from:startingAt:. {#ConsoleObject. #NoRoleObject. #NoRoleObject. #NoRoleObject. #NoRoleObject}}.
77 {66. #flushOutput. {#ConsoleObject}}.
78 {67. #handleFor:. {#FileTraits. #NoRoleObject}}.
79 {68. #handleForInput:. {#FileTraits. #NoRoleObject}}.
80 {69. #handleForOutput:. {#FileTraits. #NoRoleObject}}.
81 {70. #handleForNew:. {#FileTraits. #NoRoleObject}}.
82 {71. #close:. {#FileTraits. #NoRoleObject}}.
83 {72. #read:from:into:startingAt:. {#FileTraits. #NoRoleObject. #NoRoleObject. #NoRoleObject. #NoRoleObject}}.
84 {73. #write:to:from:startingAt:. {#FileTraits. #NoRoleObject. #NoRoleObject. #NoRoleObject. #NoRoleObject}}.
85 {74. #reposition:to:. {#FileTraits. #NoRoleObject. #NoRoleObject}}.
86 {75. #positionOf:. {#FileTraits. #NoRoleObject}}.
87 {76. #atEndOf:. {#FileTraits. #NoRoleObject}}.
88 {77. #sizeOf:. {#FileTraits. #NoRoleObject}}.
89 {78. #saveImageNamed:. {#BootstrapObject. #NoRoleObject}}.
90 {79. #primitiveOpen:. {#DirectoryTraits. #NoRoleObject}}.
91 {80. #primitiveClose:. {#DirectoryTraits. #NoRoleObject}}.
92 {81. #primitiveRead:into:. {#DirectoryTraits. #NoRoleObject. #NoRoleObject}}.
93 {82. #primitiveGetCurrentDirectory:. {#DirectoryTraits. #NoRoleObject}}.
94 {83. #primitiveSetCurrentDirectory:. {#DirectoryTraits. #NoRoleObject}}.
95 {84. #significand. {#FloatTraits}}.
96 {85. #exponent. {#FloatTraits}}.
97 {86. #withSignificand:exponent:. {#FloatTraits. #NoRoleObject. #NoRoleObject}}.
98 {87. #'='. {#FloatTraits. #FloatTraits}}.
99 {88. #'<'. {#FloatTraits. #FloatTraits}}.
100 {89. #'+'. {#FloatTraits. #FloatTraits}}.
101 {90. #'-'. {#FloatTraits. #FloatTraits}}.
102 {91. #'*'. {#FloatTraits. #FloatTraits}}.
103 {92. #'/'. {#FloatTraits. #FloatTraits}}.
104 {93. #raisedTo:. {#FloatTraits. #FloatTraits}}.
105 {94. #ln. {#FloatTraits}}.
106 {95. #exp. {#FloatTraits}}.
107 {96. #sin. {#FloatTraits}}.
108 {97. #cos. {#FloatTraits}}.
109 {98. #tan. {#FloatTraits}}.
110 {99. #arcsin. {#FloatTraits}}.
111 {100. #arccos. {#FloatTraits}}.
112 {101. #arctan. {#FloatTraits}}.
113 {102. #arctan:. {#FloatTraits. #FloatTraits}}.
114 {103. #newFixedAreaSized:. {#ByteArrayTraits. #NoRoleObject}}.
115 {104. #close:. {#ByteArrayTraits. #NoRoleObject}}.
116 {105. #noteNewReferenceTo:. {#ByteArrayTraits. #NoRoleObject}}.
117 {106. #write:into:startingAt:. {#ByteArrayTraits. #NoRoleObject. #NoRoleObject. #NoRoleObject}}.
118 {107. #read:from:startingAt:. {#ByteArrayTraits. #NoRoleObject. #NoRoleObject. #NoRoleObject}}.
119 {108. #sizeOf:. {#ByteArrayTraits. #NoRoleObject}}.
120 {109. #resize:to:. {#ByteArrayTraits. #NoRoleObject. #NoRoleObject}}.
121 {110. #addressOf:at:into:. {#ByteArrayTraits. #NoRoleObject. #NoRoleObject. #NoRoleObject}}.
122 {111. #primitiveOpen:handle:. {#ExternalLibraryTraits. #ASCIIStringTraits. #ByteArrayTraits}}.
123 {112. #primitiveClose:. {#ExternalLibraryTraits. #ByteArrayTraits}}.
124 {113. #primitiveLookup:handle:into:. {#ExternalLibraryTraits. #ASCIIStringTraits. #ByteArrayTraits. #ByteArrayTraits}}.
125 {114. #primitiveErrorInto:. {#ExternalLibraryTraits. #ByteArrayTraits}}.
126 {115. #primitiveApply:accepting:callFormat:returning:to:. {#ExternalLibraryTraits. #ByteArrayTraits. #NoRoleObject. #NoRoleObject. #NoRoleObject. #ArrayTraits}}.
127 {116. #timeSinceEpoch. {#BootstrapObject}}.
128 {117. #cloneSystem. {#BootstrapObject}}.
129 {118. #readFromPipe:start:end:. {#NoRoleObject. #SmallIntegerTraits. #SmallIntegerTraits. #SmallIntegerTraits}}.
130 {119. #writeToPipe:start:end:. {#NoRoleObject. #SmallIntegerTraits. #SmallIntegerTraits. #SmallIntegerTraits}}.
131 {120. #selectOnReadPipesFor:. {#ArrayTraits. #SmallIntegerTraits}}.
132 {121. #selectOnWritePipesFor:. {#ArrayTraits. #SmallIntegerTraits}}.
133 {122. #closePipe. {#SmallIntegerTraits}}.
134 {123. #socketCreate:protocol:. {#SmallIntegerTraits. #SmallIntegerTraits. #SmallIntegerTraits}}.
135 {124. #socketListenSize:. {#SmallIntegerTraits. #SmallIntegerTraits}}.
136 {125. #socketAcceptConnection. {#SmallIntegerTraits}}.
137 "{returns {retval. struct sockaddr}"
138 {126. #socketBindOn:. {#SmallIntegerTraits. #ByteArrayTraits}}.
139 {127. #socketConnect:. {#SmallIntegerTraits. #ByteArrayTraits}}.
140 {128. #createIPAddress:port:options:. {#SmallIntegerTraits. #NoRoleObject. #NoRoleObject. #NoRoleObject}}.
141 "AF_INET createIPAddress: {127. 0. 0. 1} port: 80 options: #{}."
142 {129. #smallIntegerMinimum. {#BootstrapObject}}.
143 {130. #smallIntegerMaximum. {#BootstrapObject}}.
144 {131. #socketGetError. {#SmallIntegerTraits}}.
145 "lobby getAddrInfo: ('slatelanguage.org' as: ByteArray)
146 service: ('http' as: ByteArray)
147 family: Net Socket Domains IP4
148 type: Net Socket Types Stream
149 protocol: Net Socket Protocols Default
151 "returns an integer to the ticket you've been assigned (since it is asynchronous)"
152 {132. #getAddrInfo:service:family:type:protocol:flags:. {#BootstrapObject. #NoRoleObject. #NoRoleObject. #SmallIntegerTraits. #SmallIntegerTraits. #SmallIntegerTraits. #SmallIntegerTraits}}.
153 "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)"
154 {133. #getAddrInfoResult. {#SmallIntegerTraits}}.
155 {134. #freeAddrInfoResult. {#SmallIntegerTraits}}.
156 {135. #vmArgCount. {#BootstrapObject}}.
157 {136. #vmArg:. {#BootstrapObject. #SmallIntegerTraits}}.
158 {137. #environmentVariables. {#BootstrapObject}}.
159 {138. #environmentAt:put:. {#BootstrapObject. #ASCIIStringTraits. #ASCIIStringTraits}}.
160 {139. #environmentRemoveKey:. {#BootstrapObject. #ASCIIStringTraits}}.
161 {140. #isLittleEndian. {#BootstrapObject}}.
162 {141. #systemName. {#BootstrapObject}}.
163 {142. #systemRelease. {#BootstrapObject}}.
164 {143. #systemVersion. {#BootstrapObject}}.
165 {144. #systemPlatform. {#BootstrapObject}}.
166 {145. #systemMachine. {#BootstrapObject}}.
167 {146. #systemExecute:. {#BootstrapObject. #ASCIIStringTraits}}.
168 {147. #startProfiling. {#BootstrapObject}}.
169 {148. #stopProfiling. {#BootstrapObject}}.
170 {149. #profilerStatistics. {#BootstrapObject}}.
171 {150. #deleteFileNamed:. {#FileTraits. #ASCIIStringTraits}}.
172 {151. #replaceFrom:to:with:startingAt:. {#ByteArrayTraits. #SmallIntegerTraits. #SmallIntegerTraits. #ByteArrayTraits. #SmallIntegerTraits}}.
173 {152. #renameFileNamed:to:. {#FileTraits. #ASCIIStringTraits. #ASCIIStringTraits}}.
174 {153. #informationForFileNamed:. {#FileTraits. #ASCIIStringTraits}}.
175 {154. #createDirectoryNamed:. {#DirectoryTraits. #ASCIIStringTraits}}.
176 {155. #renameDirectoryNamed:to:. {#DirectoryTraits. #ASCIIStringTraits. #ASCIIStringTraits}}.
177 {156. #deleteDirectoryNamed:. {#DirectoryTraits. #ASCIIStringTraits}}.
178 {157. #objectPointerAddress:. {#BootstrapObject. #NoRoleObject}}.
179 {158. #replaceFrom:to:with:startingAt:. {#ArrayTraits. #SmallIntegerTraits. #SmallIntegerTraits. #ArrayTraits. #SmallIntegerTraits}}.
180 {159. #openProcessPipe:args:. {#BootstrapObject. #ASCIIStringTraits. #ArrayTraits}}.
181 {160. #closeProcessPipe:. {#BootstrapObject. #SmallIntegerTraits}}.
182 {161. #readProcessPipe:count:into:startingAt:. {#BootstrapObject. #SmallIntegerTraits. #SmallIntegerTraits. #ByteArrayTraits. #SmallIntegerTraits}}.
183 {162. #writeProcessPipe:count:into:startingAt:. {#BootstrapObject. #SmallIntegerTraits. #SmallIntegerTraits. #ByteArrayTraits. #SmallIntegerTraits}}
186 i@(ImageDefinition traits) refreshPrimitives
189 [| :code :selector :roles |
190 i primitives add: code ->
191 (nodes MethodDefinition new `>>
192 [selector := selector.
193 roles := roles collect:
194 [| :val | val = #NoRoleObject ifFalse: [nodes UnaryMessage sending: val]]. ])
195 ] applier for: i PrimitiveDefaults.
198 ImageDefinition traits define: #cached &builder: [Dictionary new].
200 "ImageDefinition cached at: 'bare' put:
201 (ImageDefinition clone `>> [bootstrapFilenames := {'src/mobius/pre-bootstrap.slate'}. ])."
202 "An ImageDefinition consisting of the bare minimum to run some primitive call,
203 like adding 3 + 4, say."
204 "TODO: refactor ImageDefinition so that we can just supply a block here."
206 def@(ImageDefinition traits) newNamed: filename endianness: endianness wordSize: wordSize &useTimestamp: useTimestamp
208 (def clone `setting: #{#endianness. #wordSize} to: {endianness. wordSize})
209 `>> [| :newDef | filename := newDef defaultFilename &base: filename &useTimestamp: useTimestamp. ]
212 def@(ImageDefinition traits) defaultFilename &base: base &useTimestamp: useTimestamp
213 "Generates a unique and descriptive image filename based on the definition."
215 useTimestamp `defaultsTo: True.
216 '%s.%s.%d.%d.image' sprintf*,
217 (base ifNil: ['kernel']),
218 (def endianness caseOf: {#LittleEndian -> ['little']. #BigEndian -> ['big']}),
220 (useTimestamp ifTrue: [lobby ticksSinceEpoch] ifFalse: ['latest'])
223 def@(ImageDefinition traits) generate
224 [| builder bootBlock |
225 builder := Bootstrap Generator new &endianness: def endianness &wordSize: def wordSize.
226 def filename `defaultsTo: def defaultFilename.
227 def bootstrapFilenames isEmpty ifTrue:
228 [def bootstrapFilenames :=
230 (File newNamed: def bootstrapDirectory ; '/src/mobius/bootstrap-files.txt') sessionDo:
232 filelist ASCIIReader lines do:
233 [| :line | line isEmpty ifFalse: [out nextPut: line]]].
234 ] writingAs: def bootstrapFilenames)].
235 bootBlock := nodes Block new.
236 bootBlock statements := [| :out |
237 (def bootstrapFilenames collect:
238 [| :each | File newNamed: def bootstrapDirectory ; '/' ; each]) do:
240 inform: 'Parsing: %r', file locator.
242 [| :file | (Parser newOn: file ASCIIReader) do: [| :node | out nextPut: node macroExpand]]
244 writingAs: bootBlock statements.
245 inform: 'Building image: %r', def filename.
246 builder generateImageBooting: bootBlock withPrims: def primitives.
247 (File newNamed: def filename &mode: File CreateWrite) sessionDo:
248 [| :imageFile | builder emitOn: imageFile writer].
252 i@(ImageDefinition traits) generateAmd64Test
254 ((i cached at: 'bare') newNamed: 'k64' endianness: #LittleEndian wordSize: 64) generate.
257 i@(ImageDefinition traits) generateAmd64
259 (i newNamed: 'amd64' endianness: #LittleEndian wordSize: 64) generate.
262 i@(ImageDefinition traits) bootstrap &bootstrapDirectory: dir &endianness: endianness &wordSize: wordSize
263 "Only to be called during or after fullCleanBootstrap to build new images
264 based on the new VM ImageDefinition."
266 wordSize `defaultsTo: Platform Current bytesPerWord * 8.
267 endianness `defaultsTo: Platform Current endianness.
268 def := i newNamed: 'kernel.new' endianness: endianness wordSize: wordSize.
269 def refreshPrimitives.
270 dir ifNotNil: [def bootstrapDirectory := dir].
271 def cached at: {'new'. endianness. wordSize} put: def.
273 inform: 'Generated new kernel image at: %r', def filename.
274 inform: 'Suggested next command: %s -i %s', StartupArguments first, def filename.
275 inform: 'Alternate command: make slate%s', (def filename allButFirst: 'kernel.new' length).