Skip to content

Commit

Permalink
A sketch of the compiler structure for modules, classes, behaviors, a…
Browse files Browse the repository at this point in the history
…nd methods. It's now ready to have more work done on the grammar and parser.
  • Loading branch information
martinmcclure committed Jan 26, 2015
1 parent eb868b9 commit e857b0f
Show file tree
Hide file tree
Showing 48 changed files with 260 additions and 10 deletions.
@@ -0,0 +1,3 @@
compiling
compileIn: image
self compilerClass new compile: self in: image
@@ -0,0 +1,3 @@
compiling
compilerClass
^ MistBehaviorCompiler
@@ -0,0 +1,3 @@
enumerating
methodsDo: aBlock
^ methods do: aBlock
Expand Up @@ -3,4 +3,7 @@
},
"instance" : {
"addMethod:" : "MartinMcClure 2/7/2014 14:29",
"initialize" : "MartinMcClure 2/7/2014 14:30" } }
"compileIn:" : "MartinMcClure 1/25/2015 20:41",
"compilerClass" : "MartinMcClure 1/25/2015 22:32",
"initialize" : "MartinMcClure 2/7/2014 14:30",
"methodsDo:" : "MartinMcClure 1/25/2015 22:38" } }
@@ -0,0 +1,3 @@
accessing
classSpec
^ classSpec
@@ -0,0 +1,3 @@
compiling
compilerClass
^ MistClassCompiler
@@ -0,0 +1,3 @@
accessing
metaclassSpec
^ metaclassSpec
Expand Up @@ -3,4 +3,7 @@
},
"instance" : {
"addInstanceMethod:" : "MartinMcClure 2/7/2014 14:28",
"initialize" : "MartinMcClure 2/7/2014 14:32" } }
"classSpec" : "MartinMcClure 1/25/2015 20:39",
"compilerClass" : "MartinMcClure 1/25/2015 20:36",
"initialize" : "MartinMcClure 2/7/2014 14:32",
"metaclassSpec" : "MartinMcClure 1/25/2015 20:39" } }
@@ -0,0 +1,3 @@
compiling
compilerClass
^ MistMethodCompiler
Expand Up @@ -2,5 +2,6 @@
"class" : {
},
"instance" : {
"compilerClass" : "MartinMcClure 1/25/2015 22:52",
"source" : "MartinMcClure 1/10/2015 18:34",
"source:" : "MartinMcClure 2/7/2014 13:42" } }
Expand Up @@ -12,5 +12,5 @@
"name" : "MistModule",
"pools" : [
],
"super" : "Object",
"super" : "MistObject",
"type" : "normal" }
Expand Up @@ -12,4 +12,4 @@ imports
- Specs for modules imported into this module.

name
- The name by which code defined in the module's definitions refers to the module.
- The name by which code defined in the module's definitions refers to the module. Other modules are likely to use the same name to refer to this module, but are free to use a different name if they need to (for example, because there are two modules written by different parties that have the same internal name).
@@ -0,0 +1,3 @@
compiling
compilerClass
^ MistModuleCompiler
@@ -0,0 +1,3 @@
enumerating
definitionsDo: aBlock
^ definitions do: aBlock
Expand Up @@ -3,4 +3,6 @@
},
"instance" : {
"addClass:" : "MartinMcClure 2/7/2014 14:38",
"compilerClass" : "MartinMcClure 1/25/2015 19:54",
"definitionsDo:" : "MartinMcClure 1/25/2015 20:30",
"initialize" : "MartinMcClure 2/7/2014 14:38" } }
Expand Up @@ -4,7 +4,7 @@
],
"classvars" : [
],
"commentStamp" : "<historical>",
"commentStamp" : "MartinMcClure 1/25/2015 20:25",
"instvars" : [
"imports",
"definitions" ],
Expand Down
@@ -0,0 +1,3 @@
compiling
compileIn: image
self compilerClass new compile: self in: image
@@ -0,0 +1,3 @@
compiling
compilerClass
self subclassResponsibility
Expand Up @@ -2,5 +2,7 @@
"class" : {
},
"instance" : {
"compileIn:" : "MartinMcClure 1/25/2015 19:52",
"compilerClass" : "MartinMcClure 1/25/2015 19:54",
"name:" : "MartinMcClure 1/10/2015 12:52",
"printOn:" : "MartinMcClure 1/10/2015 12:50" } }
2 changes: 1 addition & 1 deletion packages/Mist-Classes.package/monticello.meta/version
@@ -1 +1 @@
(name 'Mist-Classes-MartinMcClure.4' message 'Introduced new common superclass MistSpec.Added getter for method source, used by the emerging compiler.' id '4a4af27e-e68c-47e9-af55-0f9c1d7778f2' date '14 January 2015' time '7:24:09.240533 pm' author 'MartinMcClure' ancestors ((name 'Mist-Classes-MartinMcClure.3' message 'More work on the tests for, and the implementation of, classes and modules.' id '8495270f-0b92-46c3-8355-d898c8f97dd8' date '17 February 2014' time '12:42:19.675961 am' author 'MartinMcClure' ancestors ((name 'Mist-Classes-MartinMcClure.2' message 'Many little changes. Most are connected with getting call and return to work, and handling args and temps of methods correctly with call and return.' id 'fac490da-667c-4a6a-ae8c-463b3b1313d9' date '28 December 2013' time '5:43:02.75 pm' author 'MartinMcClure' ancestors ((name 'Mist-Classes-MartinMcClure.1' message 'The very bare beginnings of the Mist-Classes package.' id '2b4742df-3ee0-468f-a1a9-581b284d8a93' date '3 November 2013' time '6:56:24.723 pm' author 'MartinMcClure' ancestors () stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())
(name 'Mist-Classes-MartinMcClure.5' message 'A sketch of the compiler structure for modules, classes, behaviors, and methods. It''s now ready to have more work done on the grammar and parser.' id 'c728447a-3179-45ee-8d48-eae6095bd7ac' date '25 January 2015' time '11:08:41.609895 pm' author 'MartinMcClure' ancestors ((name 'Mist-Classes-MartinMcClure.4' message 'Introduced new common superclass MistSpec.Added getter for method source, used by the emerging compiler.' id '4a4af27e-e68c-47e9-af55-0f9c1d7778f2' date '14 January 2015' time '7:24:09.240533 pm' author 'MartinMcClure' ancestors ((name 'Mist-Classes-MartinMcClure.3' message 'More work on the tests for, and the implementation of, classes and modules.' id '8495270f-0b92-46c3-8355-d898c8f97dd8' date '17 February 2014' time '12:42:19.675961 am' author 'MartinMcClure' ancestors ((name 'Mist-Classes-MartinMcClure.2' message 'Many little changes. Most are connected with getting call and return to work, and handling args and temps of methods correctly with call and return.' id 'fac490da-667c-4a6a-ae8c-463b3b1313d9' date '28 December 2013' time '5:43:02.75 pm' author 'MartinMcClure' ancestors ((name 'Mist-Classes-MartinMcClure.1' message 'The very bare beginnings of the Mist-Classes package.' id '2b4742df-3ee0-468f-a1a9-581b284d8a93' date '3 November 2013' time '6:56:24.723 pm' author 'MartinMcClure' ancestors () stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())
Expand Down
@@ -0,0 +1,11 @@
A MistBehaviorCompiler compiles a BehaviorSpec into a MistBehavior, and installs it into an Image.

Instance Variables
image: <MistImage>
spec: <MistClassSpec>

image
- xxxxx

spec
- xxxxx
@@ -0,0 +1,5 @@
public
compile: aSpec in: anImage
spec := aSpec.
image := anImage.
^ self compile
@@ -0,0 +1,8 @@
private
compile
"Omitted: A bunch of class composition stuff that needs to happen before the methods are compiled.
Only one class at this point..."

"Also omitted: Creating the behavior itself. Right now there are only methods on SmallInteger, which does not quite need to exist."

spec methodsDo: [ :methodSpec | methodSpec compileIn: image ]
@@ -0,0 +1,6 @@
{
"class" : {
},
"instance" : {
"compile" : "MartinMcClure 1/25/2015 22:37",
"compile:in:" : "MartinMcClure 1/25/2015 22:33" } }
@@ -0,0 +1,15 @@
{
"category" : "Mist-Compiler",
"classinstvars" : [
],
"classvars" : [
],
"commentStamp" : "MartinMcClure 1/25/2015 22:31",
"instvars" : [
"spec",
"image" ],
"name" : "MistBehaviorCompiler",
"pools" : [
],
"super" : "Object",
"type" : "normal" }
11 changes: 11 additions & 0 deletions packages/Mist-Compiler.package/MistClassCompiler.class/README.md
@@ -0,0 +1,11 @@
A MistClassCompiler compiles a ClassSpec into a class-side and an instance-side pair of MistBehaviors, and installs them into an Image.

Instance Variables
image: <MistImage>
spec: <MistClassSpec>

image
- xxxxx

spec
- xxxxx
@@ -0,0 +1,5 @@
public
compile: aSpec in: anImage
spec := aSpec.
image := anImage.
^ self compile
@@ -0,0 +1,4 @@
private
compile
spec metaclassSpec compileIn: image.
spec classSpec compileIn: image
@@ -0,0 +1,6 @@
{
"class" : {
},
"instance" : {
"compile" : "MartinMcClure 1/25/2015 20:39",
"compile:in:" : "MartinMcClure 1/25/2015 20:37" } }
@@ -0,0 +1,15 @@
{
"category" : "Mist-Compiler",
"classinstvars" : [
],
"classvars" : [
],
"commentStamp" : "MartinMcClure 1/25/2015 20:35",
"instvars" : [
"spec",
"image" ],
"name" : "MistClassCompiler",
"pools" : [
],
"super" : "Object",
"type" : "normal" }
23 changes: 23 additions & 0 deletions packages/Mist-Compiler.package/MistMethodCompiler.class/README.md
@@ -0,0 +1,23 @@
A MistMethodCompiler compiles a MethodSpec into a MistMethod.

Instance Variables
fogRoot: <FogNode>
image: <MistImage>
machineCode: <MistMachineCode>
method: <MistMethod>
spec: <MistMethodSpec>

fogRoot
- The root of the Fog intermediate code representation of the method, which is built and refined through the phases of compilation.

image
- The image into which the method will be installed.

machineCode
- The actual executable bytes that are part of the final result of the compilation.

method
- The method object that is the result of the compilation. It references the machineCode, the fogRoot, and the source code.

spec
- The spec that serves as the source for compilation.
@@ -0,0 +1,5 @@
public
compile: aSpec in: anImage
spec := aSpec.
image := anImage.
^ self compile
@@ -0,0 +1,8 @@
private
compile
"First, syntax."

fogRoot := self parse.
fogRoot isPrimitive
ifTrue: [ self compilePrimitive ]
ifFalse: [ self compileMist ]
@@ -0,0 +1,8 @@
private
parse
"Parse the source into a Fog AST. This Fog will be massaged quite a bit in further compiler passes, this is just the first one."

| source parser |
source := spec source.
parser := MistParser new.
^ parser parse: source
@@ -0,0 +1,7 @@
{
"class" : {
},
"instance" : {
"compile" : "MartinMcClure 1/25/2015 22:59",
"compile:in:" : "MartinMcClure 1/25/2015 22:57",
"parse" : "MartinMcClure 1/25/2015 23:04" } }
@@ -0,0 +1,18 @@
{
"category" : "Mist-Compiler",
"classinstvars" : [
],
"classvars" : [
],
"commentStamp" : "MartinMcClure 1/25/2015 22:47",
"instvars" : [
"spec",
"image",
"method",
"fogRoot",
"machineCode" ],
"name" : "MistMethodCompiler",
"pools" : [
],
"super" : "Object",
"type" : "normal" }
@@ -0,0 +1 @@
A MistModuleCompiler compiles a ModuleSpec into a Module, and installs that Module into an Image.
@@ -0,0 +1,5 @@
private
checkForConflicts
"There's only one module at the moment, so no conflicts are possible. Checking will come later."


@@ -0,0 +1,5 @@
public
compile: aSpec in: anImage
spec := aSpec.
image := anImage.
^ self compile
@@ -0,0 +1,7 @@
private
compile
"Compile any module dependencies into the image, if not already present, and resolve imports from them."
self resolveImports.
self checkForConflicts.
"Compile each class definition in the spec"
self compileClasses.
@@ -0,0 +1,3 @@
private
compileClasses
spec definitionsDo: [ :def | def compileIn: image ]
@@ -0,0 +1,5 @@
private
resolveImports
"Imports are not yet implemented, so nothing here yet."


@@ -0,0 +1,9 @@
{
"class" : {
},
"instance" : {
"checkForConflicts" : "MartinMcClure 1/25/2015 20:27",
"compile" : "MartinMcClure 1/25/2015 20:23",
"compile:in:" : "MartinMcClure 1/25/2015 19:56",
"compileClasses" : "MartinMcClure 1/25/2015 20:31",
"resolveImports" : "MartinMcClure 1/25/2015 20:26" } }
@@ -0,0 +1,16 @@
{
"category" : "Mist-Compiler",
"classinstvars" : [
],
"classvars" : [
],
"commentStamp" : "MartinMcClure 1/25/2015 19:53",
"instvars" : [
"spec",
"module",
"image" ],
"name" : "MistModuleCompiler",
"pools" : [
],
"super" : "Object",
"type" : "normal" }
2 changes: 1 addition & 1 deletion packages/Mist-Compiler.package/monticello.meta/version
@@ -1 +1 @@
(name 'Mist-Compiler-MartinMcClure.1' message 'The very very small beginnings of a Mist parser, based on PetitSmalltalk''s grammar.' id 'f9b0bfa0-2762-481c-8635-dafd4010e901' date '14 January 2015' time '7:29:44.834529 pm' author 'MartinMcClure' ancestors () stepChildren ())
(name 'Mist-Compiler-MartinMcClure.2' message 'A sketch of the compiler structure for modules, classes, behaviors, and methods. It''s now ready to have more work done on the grammar and parser.' id 'fb3d8d8b-bfac-4790-b673-49c6c7cde93e' date '25 January 2015' time '11:07:56.693885 pm' author 'MartinMcClure' ancestors ((name 'Mist-Compiler-MartinMcClure.1' message 'The very very small beginnings of a Mist parser, based on PetitSmalltalk''s grammar.' id 'f9b0bfa0-2762-481c-8635-dafd4010e901' date '14 January 2015' time '7:29:44.834529 pm' author 'MartinMcClure' ancestors () stepChildren ())) stepChildren ())
Expand Up @@ -2,7 +2,7 @@ tests
testThreePlusFour
| moduleSpec module |
moduleSpec := self threePlusFourModuleSpec.
module := moduleSpec installIn: image.
module := moduleSpec compileIn: image.
image startupMethod: (module definitionAt: 'SmallInteger') methodAt: #ThreePlusFour.
self
runImage: image
Expand Down
Expand Up @@ -6,5 +6,5 @@
"smallIntegerClassSpec" : "MartinMcClure 1/10/2015 12:41",
"smallIntegerPlusFogSource" : "MartinMcClure 1/10/2015 18:31",
"smallIntegerPlusSpec" : "MartinMcClure 1/11/2015 18:51",
"testThreePlusFour" : "MartinMcClure 2/7/2014 13:36",
"testThreePlusFour" : "MartinMcClure 1/25/2015 19:51",
"threePlusFourModuleSpec" : "MartinMcClure 1/7/2014 21:44" } }
2 changes: 1 addition & 1 deletion packages/Mist-Tests.package/monticello.meta/version
@@ -1 +1 @@
(name 'Mist-Tests-MartinMcClure.10' message 'Changes to tests:MethodSpecs now take a name.Some spec creation methods were not actually returning the spec (oops).Replaced smallIntegerPlusFog (which answered a Fog tree) to smallIntegerPlusFogSource, which answers the source string to build the Fog tree.' id 'b4368c47-e4c8-4b26-9d6a-3ffb1d2022cb' date '14 January 2015' time '7:28:21.288528 pm' author 'MartinMcClure' ancestors ((name 'Mist-Tests-MartinMcClure.9' message 'More work on the tests for, and the implementation of, classes and modules.' id 'd1562893-44d7-4c85-ba51-cd81bfde04ee' date '17 February 2014' time '12:42:01.744004 am' author 'MartinMcClure' ancestors ((name 'Mist-Tests-MartinMcClure.8' message 'Bare beginnings of a test case that creates an image with the class SmallInteger with two primitives.' id '56e2574f-5666-45ea-9ed6-b9043e95632c' date '7 January 2014' time '10:14:43.502303 pm' author 'MartinMcClure' ancestors ((name 'Mist-Tests-MartinMcClure.7' message 'Disassembler tests were trying to remove executable files that they never created, which caused an error in Pharo 3.0.' id '27be48dc-60a3-4e42-b427-14e754f6f2e4' date '5 January 2014' time '3:28:49.358945 pm' author 'MartinMcClure' ancestors ((name 'Mist-Tests-MartinMcClure.6' message 'Updated the echoMany test to expect the machine code generated in the new world of Method nodes.' id '9776e82d-551c-4fce-97ec-459d7ab43f9f' date '4 January 2014' time '12:08:04.228 pm' author 'MartinMcClure' ancestors ((name 'Mist-Tests-MartinMcClure.5' message 'Updated remaining tests to be methods that return rather than programs. Updated disassembler tests to account for minor differences due to location assignment changes.' id 'd7997867-d57e-49a0-a629-fc0301a27cc0' date '1 January 2014' time '10:40:44.359 pm' author 'MartinMcClure' ancestors ((name 'Mist-Tests-MartinMcClure.4' message 'Partially done updating tests for the new call/return world.' id '9b311a99-78ec-468c-8fe0-d85e2ec7b8eb' date '29 December 2013' time '10:45:33.822 pm' author 'MartinMcClure' ancestors ((name 'Mist-Tests-MartinMcClure.3' message 'Many little changes. Most are connected with getting call and return to work, and handling args and temps of methods correctly with call and return.' id 'f9013366-f016-4326-be7e-81ce54783861' date '28 December 2013' time '5:43:50.88 pm' author 'MartinMcClure' ancestors ((name 'Mist-Tests-MartinMcClure.2' message 'Modifications for Pharo 2.0.' id '26e13003-4573-4713-8e7f-45b611db017a' date '3 November 2013' time '11:23:32.755 am' author 'MartinMcClure' ancestors ((name 'Mist-Tests-MartinMcClure.1' message 'Rework of the previous Disassembler Tests and Fog Tests for the new world of objects and images. The PrintH test has been dropped since it depended on the absolute address of the code to work, and the later, longer, tests cover all of that functionality.' id 'df7b8da2-f2cf-4048-9830-38cce5131ad0' date '12 August 2013' time '10:50:46.029 am' author 'MartinMcClure' ancestors () stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())
(name 'Mist-Tests-MartinMcClure.11' message 'A sketch of the compiler structure for modules, classes, behaviors, and methods. It''s now ready to have more work done on the grammar and parser.' id '3da27c9b-a48a-4fa1-81fa-88dfa10c415b' date '25 January 2015' time '11:07:24.023884 pm' author 'MartinMcClure' ancestors ((name 'Mist-Tests-MartinMcClure.10' message 'Changes to tests:MethodSpecs now take a name.Some spec creation methods were not actually returning the spec (oops).Replaced smallIntegerPlusFog (which answered a Fog tree) to smallIntegerPlusFogSource, which answers the source string to build the Fog tree.' id 'b4368c47-e4c8-4b26-9d6a-3ffb1d2022cb' date '14 January 2015' time '7:28:21.288528 pm' author 'MartinMcClure' ancestors ((name 'Mist-Tests-MartinMcClure.9' message 'More work on the tests for, and the implementation of, classes and modules.' id 'd1562893-44d7-4c85-ba51-cd81bfde04ee' date '17 February 2014' time '12:42:01.744004 am' author 'MartinMcClure' ancestors ((name 'Mist-Tests-MartinMcClure.8' message 'Bare beginnings of a test case that creates an image with the class SmallInteger with two primitives.' id '56e2574f-5666-45ea-9ed6-b9043e95632c' date '7 January 2014' time '10:14:43.502303 pm' author 'MartinMcClure' ancestors ((name 'Mist-Tests-MartinMcClure.7' message 'Disassembler tests were trying to remove executable files that they never created, which caused an error in Pharo 3.0.' id '27be48dc-60a3-4e42-b427-14e754f6f2e4' date '5 January 2014' time '3:28:49.358945 pm' author 'MartinMcClure' ancestors ((name 'Mist-Tests-MartinMcClure.6' message 'Updated the echoMany test to expect the machine code generated in the new world of Method nodes.' id '9776e82d-551c-4fce-97ec-459d7ab43f9f' date '4 January 2014' time '12:08:04.228 pm' author 'MartinMcClure' ancestors ((name 'Mist-Tests-MartinMcClure.5' message 'Updated remaining tests to be methods that return rather than programs. Updated disassembler tests to account for minor differences due to location assignment changes.' id 'd7997867-d57e-49a0-a629-fc0301a27cc0' date '1 January 2014' time '10:40:44.359 pm' author 'MartinMcClure' ancestors ((name 'Mist-Tests-MartinMcClure.4' message 'Partially done updating tests for the new call/return world.' id '9b311a99-78ec-468c-8fe0-d85e2ec7b8eb' date '29 December 2013' time '10:45:33.822 pm' author 'MartinMcClure' ancestors ((name 'Mist-Tests-MartinMcClure.3' message 'Many little changes. Most are connected with getting call and return to work, and handling args and temps of methods correctly with call and return.' id 'f9013366-f016-4326-be7e-81ce54783861' date '28 December 2013' time '5:43:50.88 pm' author 'MartinMcClure' ancestors ((name 'Mist-Tests-MartinMcClure.2' message 'Modifications for Pharo 2.0.' id '26e13003-4573-4713-8e7f-45b611db017a' date '3 November 2013' time '11:23:32.755 am' author 'MartinMcClure' ancestors ((name 'Mist-Tests-MartinMcClure.1' message 'Rework of the previous Disassembler Tests and Fog Tests for the new world of objects and images. The PrintH test has been dropped since it depended on the absolute address of the code to work, and the later, longer, tests cover all of that functionality.' id 'df7b8da2-f2cf-4048-9830-38cce5131ad0' date '12 August 2013' time '10:50:46.029 am' author 'MartinMcClure' ancestors () stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())
Expand Down

0 comments on commit e857b0f

Please sign in to comment.