author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Tue, 02 Jun 2015 00:16:55 +0100 | |
changeset 479 | 6316a98b7150 |
parent 478 | 711c8bc1ec04 |
child 481 | 34ee0d3c72e7 |
permissions | -rw-r--r-- |
477
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
1 |
"{ Package: 'stx:goodies/petitparser/compiler' }" |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
2 |
|
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
3 |
"{ NameSpace: Smalltalk }" |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
4 |
|
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
5 |
Object subclass:#PPCCodeBlock |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
6 |
instanceVariableNames:'buffer indentation temporaries' |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
7 |
classVariableNames:'' |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
8 |
poolDictionaries:'' |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
9 |
category:'PetitCompiler-Compiler-Codegen' |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
10 |
! |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
11 |
|
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
12 |
!PPCCodeBlock class methodsFor:'instance creation'! |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
13 |
|
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
14 |
new |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
15 |
"return an initialized instance" |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
16 |
|
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
17 |
^ self basicNew initialize. |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
18 |
! ! |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
19 |
|
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
20 |
!PPCCodeBlock methodsFor:'as yet unclassified'! |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
21 |
|
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
22 |
add: string |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
23 |
self nl. |
478
711c8bc1ec04
Codegen refactoring [2/x]: Added PPCCompiler>>codeIf:then:else:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
477
diff
changeset
|
24 |
self codeIndent. |
477
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
25 |
self addOnLine: string. |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
26 |
|
478
711c8bc1ec04
Codegen refactoring [2/x]: Added PPCCompiler>>codeIf:then:else:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
477
diff
changeset
|
27 |
"Modified: / 01-06-2015 / 22:58:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
477
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
28 |
! |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
29 |
|
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
30 |
addOnLine: string |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
31 |
buffer nextPutAll: string. |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
32 |
! |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
33 |
|
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
34 |
nl |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
35 |
^ buffer nextPut: Character cr |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
36 |
! ! |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
37 |
|
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
38 |
!PPCCodeBlock methodsFor:'code generation'! |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
39 |
|
479
6316a98b7150
Action inlining [1/x]: Initial support for inlining actions parsers (i.e., ==>)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
478
diff
changeset
|
40 |
code: aStringOrBlockOrRBParseNode |
6316a98b7150
Action inlining [1/x]: Initial support for inlining actions parsers (i.e., ==>)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
478
diff
changeset
|
41 |
aStringOrBlockOrRBParseNode isString ifTrue:[ |
6316a98b7150
Action inlining [1/x]: Initial support for inlining actions parsers (i.e., ==>)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
478
diff
changeset
|
42 |
buffer nextPutAll: aStringOrBlockOrRBParseNode |
6316a98b7150
Action inlining [1/x]: Initial support for inlining actions parsers (i.e., ==>)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
478
diff
changeset
|
43 |
] ifFalse:[ |
6316a98b7150
Action inlining [1/x]: Initial support for inlining actions parsers (i.e., ==>)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
478
diff
changeset
|
44 |
(aStringOrBlockOrRBParseNode isKindOf: RBProgramNode) ifTrue:[ |
6316a98b7150
Action inlining [1/x]: Initial support for inlining actions parsers (i.e., ==>)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
478
diff
changeset
|
45 |
aStringOrBlockOrRBParseNode isSequence ifTrue:[ |
6316a98b7150
Action inlining [1/x]: Initial support for inlining actions parsers (i.e., ==>)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
478
diff
changeset
|
46 |
aStringOrBlockOrRBParseNode temporaries do:[:e | |
6316a98b7150
Action inlining [1/x]: Initial support for inlining actions parsers (i.e., ==>)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
478
diff
changeset
|
47 |
self allocateTemporaryVariableNamed: e name. |
6316a98b7150
Action inlining [1/x]: Initial support for inlining actions parsers (i.e., ==>)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
478
diff
changeset
|
48 |
]. |
6316a98b7150
Action inlining [1/x]: Initial support for inlining actions parsers (i.e., ==>)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
478
diff
changeset
|
49 |
aStringOrBlockOrRBParseNode statements do:[:e| |
6316a98b7150
Action inlining [1/x]: Initial support for inlining actions parsers (i.e., ==>)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
478
diff
changeset
|
50 |
buffer nextPutAll: e formattedCode; nextPut: $.. |
6316a98b7150
Action inlining [1/x]: Initial support for inlining actions parsers (i.e., ==>)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
478
diff
changeset
|
51 |
self nl; codeIndent. |
6316a98b7150
Action inlining [1/x]: Initial support for inlining actions parsers (i.e., ==>)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
478
diff
changeset
|
52 |
]. |
6316a98b7150
Action inlining [1/x]: Initial support for inlining actions parsers (i.e., ==>)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
478
diff
changeset
|
53 |
|
6316a98b7150
Action inlining [1/x]: Initial support for inlining actions parsers (i.e., ==>)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
478
diff
changeset
|
54 |
] ifFalse:[ |
6316a98b7150
Action inlining [1/x]: Initial support for inlining actions parsers (i.e., ==>)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
478
diff
changeset
|
55 |
buffer nextPutAll: aStringOrBlockOrRBParseNode formattedCode. |
6316a98b7150
Action inlining [1/x]: Initial support for inlining actions parsers (i.e., ==>)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
478
diff
changeset
|
56 |
]. |
6316a98b7150
Action inlining [1/x]: Initial support for inlining actions parsers (i.e., ==>)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
478
diff
changeset
|
57 |
|
6316a98b7150
Action inlining [1/x]: Initial support for inlining actions parsers (i.e., ==>)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
478
diff
changeset
|
58 |
] ifFalse:[ |
6316a98b7150
Action inlining [1/x]: Initial support for inlining actions parsers (i.e., ==>)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
478
diff
changeset
|
59 |
aStringOrBlockOrRBParseNode value |
6316a98b7150
Action inlining [1/x]: Initial support for inlining actions parsers (i.e., ==>)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
478
diff
changeset
|
60 |
]. |
477
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
61 |
]. |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
62 |
|
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
63 |
"Created: / 01-06-2015 / 21:07:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
479
6316a98b7150
Action inlining [1/x]: Initial support for inlining actions parsers (i.e., ==>)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
478
diff
changeset
|
64 |
"Modified: / 02-06-2015 / 00:06:32 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
478
711c8bc1ec04
Codegen refactoring [2/x]: Added PPCCompiler>>codeIf:then:else:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
477
diff
changeset
|
65 |
! |
711c8bc1ec04
Codegen refactoring [2/x]: Added PPCCompiler>>codeIf:then:else:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
477
diff
changeset
|
66 |
|
711c8bc1ec04
Codegen refactoring [2/x]: Added PPCCompiler>>codeIf:then:else:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
477
diff
changeset
|
67 |
codeIndent |
711c8bc1ec04
Codegen refactoring [2/x]: Added PPCCompiler>>codeIf:then:else:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
477
diff
changeset
|
68 |
self codeIndent:indentation |
711c8bc1ec04
Codegen refactoring [2/x]: Added PPCCompiler>>codeIf:then:else:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
477
diff
changeset
|
69 |
|
711c8bc1ec04
Codegen refactoring [2/x]: Added PPCCompiler>>codeIf:then:else:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
477
diff
changeset
|
70 |
"Created: / 01-06-2015 / 22:58:00 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
711c8bc1ec04
Codegen refactoring [2/x]: Added PPCCompiler>>codeIf:then:else:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
477
diff
changeset
|
71 |
! |
711c8bc1ec04
Codegen refactoring [2/x]: Added PPCCompiler>>codeIf:then:else:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
477
diff
changeset
|
72 |
|
711c8bc1ec04
Codegen refactoring [2/x]: Added PPCCompiler>>codeIf:then:else:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
477
diff
changeset
|
73 |
codeIndent: level |
711c8bc1ec04
Codegen refactoring [2/x]: Added PPCCompiler>>codeIf:then:else:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
477
diff
changeset
|
74 |
((Smalltalk respondsTo:#isSmalltalkX) and:[ Smalltalk isSmalltalkX ]) ifTrue:[ |
711c8bc1ec04
Codegen refactoring [2/x]: Added PPCCompiler>>codeIf:then:else:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
477
diff
changeset
|
75 |
level * 4 timesRepeat: [ buffer nextPut: Character space ]. |
711c8bc1ec04
Codegen refactoring [2/x]: Added PPCCompiler>>codeIf:then:else:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
477
diff
changeset
|
76 |
] ifFalse:[ |
711c8bc1ec04
Codegen refactoring [2/x]: Added PPCCompiler>>codeIf:then:else:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
477
diff
changeset
|
77 |
level timesRepeat: [ buffer nextPut: Character tab ]. |
711c8bc1ec04
Codegen refactoring [2/x]: Added PPCCompiler>>codeIf:then:else:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
477
diff
changeset
|
78 |
]. |
711c8bc1ec04
Codegen refactoring [2/x]: Added PPCCompiler>>codeIf:then:else:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
477
diff
changeset
|
79 |
|
711c8bc1ec04
Codegen refactoring [2/x]: Added PPCCompiler>>codeIf:then:else:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
477
diff
changeset
|
80 |
"Created: / 01-06-2015 / 22:58:07 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
477
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
81 |
! ! |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
82 |
|
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
83 |
!PPCCodeBlock methodsFor:'code generation - variables'! |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
84 |
|
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
85 |
allocateTemporaryVariableNamed:preferredName |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
86 |
"Allocate a new variable with (preferably) given name. |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
87 |
Returns a real variable name that should be used." |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
88 |
|
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
89 |
(temporaries includes:preferredName) ifFalse:[ |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
90 |
temporaries add:preferredName. |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
91 |
^ preferredName |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
92 |
] ifTrue:[ |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
93 |
| name | |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
94 |
|
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
95 |
name := preferredName , '_' , (temporaries size + 1) printString. |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
96 |
temporaries add:name. |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
97 |
^ name |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
98 |
]. |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
99 |
|
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
100 |
"Created: / 23-04-2015 / 17:37:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
101 |
"Modified: / 01-06-2015 / 21:03:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
102 |
! ! |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
103 |
|
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
104 |
!PPCCodeBlock methodsFor:'indentation'! |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
105 |
|
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
106 |
dedent |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
107 |
indentation := indentation - 1 |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
108 |
! |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
109 |
|
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
110 |
indent |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
111 |
indentation := indentation + 1 |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
112 |
! |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
113 |
|
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
114 |
indentationLevel |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
115 |
^ indentation |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
116 |
! |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
117 |
|
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
118 |
indentationLevel: value |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
119 |
indentation := value |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
120 |
! ! |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
121 |
|
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
122 |
!PPCCodeBlock methodsFor:'initialization'! |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
123 |
|
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
124 |
initialize |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
125 |
"Invoked when a new instance is created." |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
126 |
|
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
127 |
"/ please change as required (and remove this comment) |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
128 |
buffer := String new writeStream. |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
129 |
indentation := 1. |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
130 |
temporaries := OrderedCollection new. |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
131 |
|
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
132 |
|
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
133 |
"/ super initialize. -- commented since inherited method does nothing |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
134 |
|
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
135 |
"Modified: / 01-06-2015 / 20:57:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
136 |
! ! |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
137 |
|
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
138 |
!PPCCodeBlock methodsFor:'printing and storing'! |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
139 |
|
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
140 |
codeOn: aStream |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
141 |
"Dumps generated code on given stream" |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
142 |
|
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
143 |
temporaries notEmpty ifTrue:[ |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
144 |
((Smalltalk respondsTo:#isSmalltalkX) and:[ Smalltalk isSmalltalkX ]) ifTrue:[ |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
145 |
indentation * 4 timesRepeat: [ aStream nextPut: Character space ]. |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
146 |
] ifFalse:[ |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
147 |
indentation timesRepeat: [ buffer nextPut: Character tab ]. |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
148 |
]. |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
149 |
aStream nextPut: $|. |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
150 |
temporaries do:[:e | aStream space; nextPutAll: e ]. |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
151 |
aStream space. |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
152 |
aStream nextPut: $|. |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
153 |
self nl. |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
154 |
"In Smalltalk/X, there should be a blank line after temporaries" |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
155 |
((Smalltalk respondsTo:#isSmalltalkX) and:[ Smalltalk isSmalltalkX ]) ifTrue:[ |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
156 |
self nl. |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
157 |
]. |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
158 |
]. |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
159 |
aStream nextPutAll: buffer contents |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
160 |
|
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
161 |
"Created: / 01-06-2015 / 21:26:03 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
162 |
! ! |
b18b6cc7aabc
Codegen refactoring [1/x]: Introduced a PPCCodeBlock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
163 |