resin 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. data/amber/css/amber-normalize.css +73 -73
  2. data/amber/css/amber-normalize.less +1 -1
  3. data/amber/css/amber.css +106 -106
  4. data/amber/css/helios.css +242 -0
  5. data/amber/images/hsplitter.png +0 -0
  6. data/amber/images/vsplitter.png +0 -0
  7. data/amber/js/Benchfib.deploy.js +116 -38
  8. data/amber/js/Benchfib.js +120 -42
  9. data/amber/js/Canvas.deploy.js +674 -403
  10. data/amber/js/Canvas.js +682 -411
  11. data/amber/js/Compiler-AST.deploy.js +1150 -0
  12. data/amber/js/Compiler-AST.js +1591 -0
  13. data/amber/js/Compiler-Core.deploy.js +1562 -0
  14. data/amber/js/Compiler-Core.js +1972 -0
  15. data/amber/js/Compiler-Exceptions.deploy.js +114 -0
  16. data/amber/js/Compiler-Exceptions.js +161 -0
  17. data/amber/js/Compiler-IR.deploy.js +2326 -0
  18. data/amber/js/Compiler-IR.js +3146 -0
  19. data/amber/js/Compiler-Inlining.deploy.js +1147 -0
  20. data/amber/js/Compiler-Inlining.js +1514 -0
  21. data/amber/js/Compiler-Semantic.deploy.js +1207 -0
  22. data/amber/js/Compiler-Semantic.js +1628 -0
  23. data/amber/js/Compiler-Tests.deploy.js +646 -60
  24. data/amber/js/Compiler-Tests.js +843 -82
  25. data/amber/js/Compiler.deploy.js +1097 -159
  26. data/amber/js/Compiler.js +1414 -161
  27. data/amber/js/Examples.deploy.js +31 -15
  28. data/amber/js/Examples.js +33 -17
  29. data/amber/js/Helios-Announcements.deploy.js +127 -0
  30. data/amber/js/Helios-Announcements.js +157 -0
  31. data/amber/js/Helios-Browser.deploy.js +1473 -0
  32. data/amber/js/Helios-Browser.js +1953 -0
  33. data/amber/js/Helios-Commands.deploy.js +403 -0
  34. data/amber/js/Helios-Commands.js +563 -0
  35. data/amber/js/Helios-Core.deploy.js +1070 -0
  36. data/amber/js/Helios-Core.js +1445 -0
  37. data/amber/js/Helios-Environments.deploy.js +132 -0
  38. data/amber/js/Helios-Environments.js +179 -0
  39. data/amber/js/Helios-Inspector.deploy.js +855 -0
  40. data/amber/js/Helios-Inspector.js +1155 -0
  41. data/amber/js/Helios-KeyBindings.deploy.js +753 -0
  42. data/amber/js/Helios-KeyBindings.js +1023 -0
  43. data/amber/js/Helios-Layout.deploy.js +383 -0
  44. data/amber/js/Helios-Layout.js +523 -0
  45. data/amber/js/Helios-Workspace.deploy.js +799 -0
  46. data/amber/js/Helios-Workspace.js +1074 -0
  47. data/amber/js/IDE.deploy.js +2541 -1490
  48. data/amber/js/IDE.js +2721 -1660
  49. data/amber/js/Importer-Exporter.deploy.js +671 -0
  50. data/amber/js/Importer-Exporter.js +816 -0
  51. data/amber/js/Kernel-Announcements.deploy.js +137 -20
  52. data/amber/js/Kernel-Announcements.js +176 -22
  53. data/amber/js/Kernel-Classes.deploy.js +555 -168
  54. data/amber/js/Kernel-Classes.js +662 -205
  55. data/amber/js/Kernel-Collections.deploy.js +1403 -618
  56. data/amber/js/Kernel-Collections.js +1545 -690
  57. data/amber/js/Kernel-Exceptions.deploy.js +109 -45
  58. data/amber/js/Kernel-Exceptions.js +123 -49
  59. data/amber/js/Kernel-Methods.deploy.js +196 -81
  60. data/amber/js/Kernel-Methods.js +214 -89
  61. data/amber/js/Kernel-Objects.deploy.js +1542 -1117
  62. data/amber/js/Kernel-Objects.js +1593 -1148
  63. data/amber/js/Kernel-Tests.deploy.js +1725 -772
  64. data/amber/js/Kernel-Tests.js +2301 -1123
  65. data/amber/js/Kernel-Transcript.deploy.js +23 -25
  66. data/amber/js/Kernel-Transcript.js +24 -26
  67. data/amber/js/SUnit.deploy.js +204 -131
  68. data/amber/js/SUnit.js +222 -139
  69. data/amber/js/Spaces.deploy.js +240 -0
  70. data/amber/js/Spaces.js +326 -0
  71. data/amber/js/amber.js +26 -7
  72. data/amber/js/boot.js +65 -47
  73. data/amber/js/init.js +1 -1
  74. data/amber/js/lib/CodeMirror/amber.css +21 -21
  75. data/amber/js/lib/CodeMirror/codemirror.css +119 -13
  76. data/amber/js/lib/CodeMirror/codemirror.js +2219 -1220
  77. data/amber/js/lib/CodeMirror/smalltalk.js +134 -129
  78. data/amber/js/lib/bootstrap/css/bootstrap.css +5837 -0
  79. data/amber/js/lib/bootstrap/css/bootstrap.min.css +841 -0
  80. data/amber/js/lib/bootstrap/img/glyphicons-halflings-white.png +0 -0
  81. data/amber/js/lib/bootstrap/img/glyphicons-halflings.png +0 -0
  82. data/amber/js/lib/bootstrap/js/bootstrap.js +2038 -0
  83. data/amber/js/lib/bootstrap/js/bootstrap.min.js +7 -0
  84. data/amber/js/lib/jQuery/jquery-1.8.2.min.js +2 -0
  85. data/amber/js/lib/jQuery/jquery-ui-1.8.24.custom.min.js +125 -0
  86. data/amber/st/Compiler-AST.st +505 -0
  87. data/amber/st/Compiler-Core.st +835 -0
  88. data/amber/st/Compiler-Exceptions.st +87 -0
  89. data/amber/st/Compiler-IR.st +1097 -0
  90. data/amber/st/Compiler-Inlining.st +650 -0
  91. data/amber/st/Compiler-Semantic.st +558 -0
  92. data/amber/st/Compiler-Tests.st +285 -381
  93. data/amber/st/Compiler.st +725 -2
  94. data/amber/st/Helios-Announcements.st +104 -0
  95. data/amber/st/Helios-Browser.st +708 -0
  96. data/amber/st/Helios-Commands.st +223 -0
  97. data/amber/st/Helios-Core.st +532 -0
  98. data/amber/st/Helios-Environments.st +98 -0
  99. data/amber/st/Helios-Inspector.st +367 -0
  100. data/amber/st/Helios-KeyBindings.st +337 -0
  101. data/amber/st/Helios-Layout.st +199 -0
  102. data/amber/st/Helios-Workspace.st +367 -0
  103. data/amber/st/IDE.st +75 -53
  104. data/amber/st/Importer-Exporter.st +386 -0
  105. data/amber/st/Kernel-Announcements.st +92 -0
  106. data/amber/st/Kernel-Classes.st +137 -15
  107. data/amber/st/Kernel-Collections.st +137 -47
  108. data/amber/st/Kernel-Exceptions.st +14 -0
  109. data/amber/st/Kernel-Methods.st +9 -1
  110. data/amber/st/Kernel-Objects.st +29 -5
  111. data/amber/st/Kernel-Tests.st +545 -199
  112. data/amber/st/SUnit.st +10 -0
  113. data/amber/st/Spaces.st +142 -0
  114. data/lib/resin/app.rb +1 -1
  115. metadata +86 -31
  116. data/amber/js/lib/jQuery/jquery-1.4.4.min.js +0 -167
  117. data/amber/js/lib/jQuery/jquery-1.6.4.min.js +0 -4
@@ -1,471 +1,375 @@
1
1
  Smalltalk current createPackage: 'Compiler-Tests' properties: #{}!
2
- TestCase subclass: #ImporterTest
3
- instanceVariableNames: ''
4
- category: 'Compiler-Tests'!
5
-
6
- !ImporterTest methodsFor: 'private'!
7
-
8
- chunkString
9
-
10
- ^'!!Object methodsFor: ''importer test method''!!
2
+ TestCase subclass: #CodeGeneratorTest
3
+ instanceVariableNames: 'receiver'
4
+ package: 'Compiler-Tests'!
11
5
 
12
- importerTestMethod
6
+ !CodeGeneratorTest methodsFor: 'accessing'!
13
7
 
14
- ^''success''
15
- !! !!
16
- '
8
+ codeGeneratorClass
9
+ ^ CodeGenerator
17
10
  !
18
11
 
19
- bigChunkString
20
-
21
- ^'Smalltalk current createPackage: ''Cypress-Definitions'' properties: #{}!!
22
- Object subclass: #CypressSnapshot
23
- instanceVariableNames: ''definitions''
24
- package: ''Cypress-Definitions''!!
25
-
26
- !!CypressSnapshot methodsFor: ''not yet classified''!!
27
-
28
- definitions: aDefinitions
29
-
30
- definitions := aDefinitions
31
- !!
32
-
33
- definitions
34
-
35
- ^definitions
36
- !! !!
37
-
38
- !!CypressSnapshot class methodsFor: ''not yet classified''!!
39
-
40
- definitions: aDefinitions
41
-
42
- ^(self new) definitions: aDefinitions
43
- !! !!
44
-
45
- Object subclass: #CypressPackage
46
- instanceVariableNames: ''name''
47
- package: ''Cypress-Definitions''!!
48
-
49
- !!CypressPackage methodsFor: ''not yet classified''!!
50
-
51
- = other
52
- ^ other species = self species and: [other name sameAs: name]
53
- !!
12
+ targetClass
13
+ ^ DoIt
14
+ ! !
54
15
 
55
- name
56
- ^ name
57
- !!
16
+ !CodeGeneratorTest methodsFor: 'factory'!
58
17
 
59
- name: aString
60
- name := aString
61
- !!
18
+ compiler
19
+ ^ Compiler new
20
+ codeGeneratorClass: self codeGeneratorClass;
21
+ yourself
22
+ ! !
62
23
 
63
- snapshot
64
- | package definitions name |
65
- package := Package named: self name.
66
- definitions := OrderedCollection new.
67
- package sortedClasses do: [:cls |
68
- definitions add: cls asCypressClassDefinition.
69
- cls methodDictionary values do: [:method |
70
- (method category match: ''^\*'') ifFalse: [
71
- definitions add: method asCypressMethodDefinition ]].
72
- cls class methodDictionary values do: [:method |
73
- (method category match: ''^\*'') ifFalse: [
74
- definitions add: method asCypressMethodDefinition ]]].
75
- name := package name.
76
- Smalltalk current classes, (Smalltalk current classes collect: [:each | each class]) do: [:each |
77
- each methodDictionary values do: [:method |
78
- method category = (''*'', name) ifTrue: [
79
- definitions add: method asCypressMethodDefinition ]]].
80
- ^ CypressSnapshot definitions: definitions
81
- !!
24
+ !CodeGeneratorTest methodsFor: 'initialization'!
82
25
 
83
- printString
84
- ^super printString, ''('', name, '')''
85
- !! !!
26
+ setUp
27
+ receiver := self targetClass new
28
+ !
86
29
 
87
- Object subclass: #CypressDefinition
88
- instanceVariableNames: ''''
89
- package: ''Cypress-Definitions''!!
30
+ tearDown
31
+ "receiver := nil"
32
+ ! !
90
33
 
91
- !!CypressDefinition methodsFor: ''not yet classified''!!
34
+ !CodeGeneratorTest methodsFor: 'testing'!
92
35
 
93
- = aDefinition
94
- ^(aDefinition isKindOf: CypressDefinition) and: [self isRevisionOf: aDefinition]
95
- !!
36
+ should: aString return: anObject
37
+ | method result |
96
38
 
97
- isRevisionOf: aDefinition
98
- ^ (aDefinition isKindOf: CypressDefinition) and: [aDefinition description = self description]
99
- !!
39
+ method := self compiler install: aString forClass: self targetClass category: 'tests'.
40
+ result := receiver perform: method selector.
41
+ self targetClass removeCompiledMethod: method.
42
+ self assert: anObject equals: result
43
+ ! !
100
44
 
101
- description
102
- self subclassResponsibility
103
- !!
45
+ !CodeGeneratorTest methodsFor: 'tests'!
104
46
 
105
- isSameRevisionAs: aDefinition
106
- ^ self = aDefinition
107
- !! !!
47
+ testAssignment
48
+ self should: 'foo | a | a := true ifTrue: [ 1 ]. ^ a' return: 1.
49
+ self should: 'foo | a | a := false ifTrue: [ 1 ]. ^ a' return: nil.
108
50
 
109
- Object subclass: #CypressPatch
110
- instanceVariableNames: ''operations''
111
- package: ''Cypress-Definitions''!!
51
+ self should: 'foo | a | ^ a := true ifTrue: [ 1 ]' return: 1
52
+ !
112
53
 
113
- !!CypressPatch methodsFor: ''not yet classified''!!
54
+ testBlockReturn
55
+ self should: 'foo ^ #(1 2 3) collect: [ :each | true ifTrue: [ each + 1 ] ]' return: #(2 3 4).
56
+ self should: 'foo ^ #(1 2 3) collect: [ :each | false ifFalse: [ each + 1 ] ]' return: #(2 3 4).
57
+ self should: 'foo ^ #(1 2 3) collect: [ :each | each odd ifTrue: [ each + 1 ] ifFalse: [ each - 1 ] ]' return: #(2 1 4).
58
+ !
114
59
 
115
- fromBase: baseSnapshot toTarget: targetSnapshot
116
- | base target |
117
- operations := OrderedCollection new.
118
- base := CypressDefinitionIndex definitions: baseSnapshot definitions.
119
- target := CypressDefinitionIndex definitions: targetSnapshot definitions.
60
+ testCascades
120
61
 
121
- target definitions do:
122
- [:t |
123
- base
124
- definitionLike: t
125
- ifPresent: [:b | (b isSameRevisionAs: t) ifFalse: [operations add: (CypressModification of: b to: t)]]
126
- ifAbsent: [operations add: (CypressAddition of: t)]].
127
-
128
- base definitions do:
129
- [:b |
130
- target
131
- definitionLike: b
132
- ifPresent: [:t | ]
133
- ifAbsent: [operations add: (CypressRemoval of: b)]]
134
- !!
135
-
136
- operations
137
-
138
- ^operations
139
- !! !!
140
-
141
- !!CypressPatch class methodsFor: ''not yet classified''!!
142
-
143
- fromBase: baseSnapshot toTarget: targetSnapshot
144
- ^ (self new)
145
- fromBase: baseSnapshot
146
- toTarget: targetSnapshot
147
- !! !!
148
-
149
- Object subclass: #CypressDefinitionIndex
150
- instanceVariableNames: ''definitionMap''
151
- package: ''Cypress-Definitions''!!
152
-
153
- !!CypressDefinitionIndex methodsFor: ''not yet classified''!!
154
-
155
- add: aDefinition
156
- ^ self definitionMap at: aDefinition description put: aDefinition
157
- !!
158
-
159
- addAll: aCollection
160
- aCollection do: [:ea | self add: ea]
161
- !!
162
-
163
- definitionLike: aDefinition ifPresent: foundBlock ifAbsent: errorBlock
164
- | definition |
165
- definition := self definitionMap at: aDefinition description ifAbsent: [].
166
- ^ definition
167
- ifNil: errorBlock
168
- ifNotNil: [foundBlock value: definition]
169
- !!
170
-
171
- definitions
172
- ^self definitionMap values
173
- !!
174
-
175
- definitionMap
176
- definitionMap ifNil: [ definitionMap := Dictionary new ].
177
- ^ definitionMap
178
- !!
179
-
180
- remove: aDefinition
181
- self definitionMap removeKey: aDefinition description ifAbsent: []
182
- !! !!
183
-
184
- !!CypressDefinitionIndex class methodsFor: ''not yet classified''!!
185
-
186
- definitions: aCollection
187
- ^ self new addAll: aCollection
188
- !! !!
189
-
190
- Object subclass: #CypressPatchOperation
191
- instanceVariableNames: ''''
192
- package: ''Cypress-Definitions''!!
193
-
194
- CypressDefinition subclass: #CypressClassDefinition
195
- instanceVariableNames: ''name superclassName category comment instVarNames classInstVarNames''
196
- package: ''Cypress-Definitions''!!
197
-
198
- !!CypressClassDefinition methodsFor: ''not yet classified''!!
199
-
200
- name: aClassName superclassName: aSuperclassName category: aCategory instVarNames: anInstanceVariableNames classInstVarNames: aClassInstanceVariableNames comment: aComment
201
-
202
- name := aClassName.
203
- superclassName := aSuperclassName.
204
- category := aCategory.
205
- instVarNames := anInstanceVariableNames.
206
- classInstVarNames := aClassInstanceVariableNames.
207
- comment := aComment
208
- !!
209
-
210
- = aDefinition
211
- ^(super = aDefinition)
212
- and: [superclassName = aDefinition superclassName
213
- and: [category = aDefinition category
214
- and: [instVarNames = aDefinition instVarNames
215
- and: [classInstVarNames = aDefinition classInstVarNames
216
- and: [comment = aDefinition comment]]]]]
217
- !!
218
-
219
- superclassName
220
-
221
- ^superclassName
222
- !!
223
-
224
- name
225
-
226
- ^name
227
- !!
228
-
229
- category
230
-
231
- ^category
232
- !!
233
-
234
- comment
235
-
236
- ^comment
237
- !!
62
+ self should: 'foo ^ Array new add: 3; add: 4; yourself' return: #(3 4)
63
+ !
238
64
 
239
- description
65
+ testLiterals
66
+ self should: 'foo ^ 1' return: 1.
67
+ self should: 'foo ^ ''hello''' return: 'hello'.
68
+ self should: 'foo ^ #(1 2 3 4)' return: #(1 2 3 4).
69
+ self should: 'foo ^ {1. [:x | x ] value: 2. 3. [4] value}' return: #(1 2 3 4).
70
+ self should: 'foo ^ true' return: true.
71
+ self should: 'foo ^ false' return: false.
72
+ self should: 'foo ^ #{1->2. 3->4}' return: #{1->2. 3->4}.
73
+ self should: 'foo ^ #hello' return: #hello.
74
+ self should: 'foo ^ -123.456' return: -123.456
75
+ !
240
76
 
241
- ^ Array with: name
242
- !!
77
+ testLocalReturn
78
+ self should: 'foo ^ 1' return: 1.
79
+ self should: 'foo ^ 1 + 1' return: 2.
80
+ self should: 'foo ' return: receiver.
81
+ self should: 'foo self asString' return: receiver.
82
+ self should: 'foo | a b | a := 1. b := 2. ^ a + b' return: 3
83
+ !
243
84
 
244
- instVarNames
85
+ testMessageSends
86
+ self should: 'foo ^ 1 asString' return: '1'.
245
87
 
246
- ^instVarNames
247
- !!
88
+ self should: 'foo ^ 1 + 1' return: 2.
89
+ self should: 'foo ^ 1 + 2 * 3' return: 9.
248
90
 
249
- classInstVarNames
91
+ self should: 'foo ^ 1 to: 3' return: #(1 2 3).
92
+ self should: 'foo ^ 1 to: 5 by: 2' return: #(1 3 5)
93
+ !
250
94
 
251
- ^classInstVarNames
252
- !! !!
95
+ testNestedIfTrue
96
+ self should: 'foo ^ true ifTrue: [ false ifFalse: [ 1 ] ]' return: 1.
97
+ self should: 'foo ^ true ifTrue: [ false ifTrue: [ 1 ] ]' return: nil.
253
98
 
254
- !!CypressClassDefinition class methodsFor: ''not yet classified''!!
99
+ self should: 'foo true ifTrue: [ false ifFalse: [ ^ 1 ] ]' return: 1.
100
+ self should: 'foo true ifTrue: [ false ifTrue: [ ^ 1 ] ]' return: receiver.
101
+ !
255
102
 
256
- name: aClassName
257
- superclassName: aSuperclassName
258
- category: aCategory
259
- instVarNames: anInstanceVariableNames
260
- classInstVarNames: aClassInstanceVariableNames
261
- comment: aComment
103
+ testNonLocalReturn
104
+ self should: 'foo [ ^ 1 ] value' return: 1.
105
+ self should: 'foo [ ^ 1 + 1 ] value' return: 2.
106
+ self should: 'foo | a b | a := 1. b := 2. [ ^ a + b ] value. self halt' return: 3.
107
+ self should: 'foo [ :x | ^ x + x ] value: 4. ^ 2' return: 8
108
+ !
262
109
 
263
- ^(self new)
264
- name: aClassName
265
- superclassName: aSuperclassName
266
- category: aCategory
267
- instVarNames: anInstanceVariableNames
268
- classInstVarNames: aClassInstanceVariableNames
269
- comment: aComment
270
- !! !!
110
+ testifFalse
111
+ self should: 'foo true ifFalse: [ ^ 1 ]' return: receiver.
112
+ self should: 'foo false ifFalse: [ ^ 2 ]' return: 2.
113
+
114
+ self should: 'foo ^ true ifFalse: [ 1 ]' return: nil.
115
+ self should: 'foo ^ false ifFalse: [ 2 ]' return: 2.
116
+ !
271
117
 
272
- CypressDefinition subclass: #CypressMethodDefinition
273
- instanceVariableNames: ''classIsMeta source category selector className''
274
- package: ''Cypress-Definitions''!!
118
+ testifFalseIfTrue
119
+ self should: 'foo true ifFalse: [ ^ 1 ] ifTrue: [ ^ 2 ]' return: 2.
120
+ self should: 'foo false ifFalse: [ ^ 2 ] ifTrue: [ ^1 ]' return: 2.
121
+
122
+ self should: 'foo ^ true ifFalse: [ 1 ] ifTrue: [ 2 ]' return: 2.
123
+ self should: 'foo ^ false ifFalse: [ 2 ] ifTrue: [ 1 ]' return: 2.
124
+ !
275
125
 
276
- !!CypressMethodDefinition methodsFor: ''not yet classified''!!
126
+ testifNil
127
+ self should: 'foo ^ 1 ifNil: [ 2 ]' return: 1.
128
+ self should: 'foo ^ nil ifNil: [ 2 ]' return: 2.
277
129
 
278
- className: aName classIsMeta: isMetaclass selector: aSelector category: aCategory source: aSource
130
+ self should: 'foo 1 ifNil: [ ^ 2 ]' return: receiver.
131
+ self should: 'foo nil ifNil: [ ^ 2 ]' return: 2.
132
+ !
279
133
 
280
- className := aName.
281
- classIsMeta := isMetaclass.
282
- selector := aSelector.
283
- category := aCategory.
284
- source := aSource.
285
- !!
134
+ testifNilIfNotNil
135
+ self should: 'foo ^ 1 ifNil: [ 2 ] ifNotNil: [ 3 ]' return: 3.
136
+ self should: 'foo ^ nil ifNil: [ 2 ] ifNotNil: [ 3 ]' return: 2.
286
137
 
287
- = aDefinition
288
- ^ super = aDefinition
289
- and: [ aDefinition source = self source
290
- and: [ aDefinition category = self category ] ]
291
- !!
138
+ self should: 'foo 1 ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]' return: 3.
139
+ self should: 'foo nil ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]' return: 2.
140
+ !
292
141
 
293
- source
142
+ testifNotNil
143
+ self should: 'foo ^ 1 ifNotNil: [ 2 ]' return: 2.
144
+ self should: 'foo ^ nil ifNotNil: [ 2 ]' return: nil.
294
145
 
295
- ^source
296
- !!
146
+ self should: 'foo 1 ifNotNil: [ ^ 2 ]' return: 2.
147
+ self should: 'foo nil ifNotNil: [ ^ 2 ]' return: receiver.
148
+ !
297
149
 
298
- category
150
+ testifTrue
151
+ self should: 'foo false ifTrue: [ ^ 1 ]' return: receiver.
152
+ self should: 'foo true ifTrue: [ ^ 2 ]' return: 2.
153
+
154
+ self should: 'foo ^ false ifTrue: [ 1 ]' return: nil.
155
+ self should: 'foo ^ true ifTrue: [ 2 ]' return: 2.
156
+ !
299
157
 
300
- ^category
301
- !!
158
+ testifTrueIfFalse
159
+ self should: 'foo false ifTrue: [ ^ 1 ] ifFalse: [ ^2 ]' return: 2.
160
+ self should: 'foo true ifTrue: [ ^ 1 ] ifFalse: [ ^ 2 ]' return: 1.
161
+
162
+ self should: 'foo ^ false ifTrue: [ 2 ] ifFalse: [ 1 ]' return: 1.
163
+ self should: 'foo ^ true ifTrue: [ 2 ] ifFalse: [ 1 ]' return: 2.
164
+ ! !
302
165
 
303
- description
304
- ^ Array
305
- with: className
306
- with: selector
307
- with: classIsMeta
308
- !! !!
166
+ CodeGeneratorTest subclass: #InliningCodeGeneratorTest
167
+ instanceVariableNames: ''
168
+ package: 'Compiler-Tests'!
309
169
 
310
- !!CypressMethodDefinition class methodsFor: ''not yet classified''!!
170
+ !InliningCodeGeneratorTest methodsFor: 'accessing'!
311
171
 
312
- className: aName
313
- classIsMeta: isMetaclass
314
- selector: aSelector
315
- category: aCategory
316
- source: aSource
172
+ codeGeneratorClass
173
+ ^ InliningCodeGenerator
174
+ ! !
317
175
 
318
- ^(self new)
319
- className: aName
320
- classIsMeta: isMetaclass
321
- selector: aSelector
322
- category: aCategory
323
- source: aSource
324
- !! !!
176
+ TestCase subclass: #ScopeVarTest
177
+ instanceVariableNames: ''
178
+ package: 'Compiler-Tests'!
325
179
 
326
- CypressPatchOperation subclass: #CypressAddition
327
- instanceVariableNames: ''definition''
328
- package: ''Cypress-Definitions''!!
180
+ !ScopeVarTest methodsFor: 'tests'!
329
181
 
330
- !!CypressAddition methodsFor: ''not yet classified''!!
182
+ testClassRefVar
183
+ | node |
184
+ node := ClassReferenceNode new
185
+ value: 'Object';
186
+ yourself.
187
+ SemanticAnalyzer new visit: node.
188
+ self assert: node binding isClassRefVar
189
+ !
331
190
 
332
- definition: aDefinition
191
+ testInstanceVar
192
+ | node scope |
193
+ node := VariableNode new
194
+ value: 'bzzz';
195
+ yourself.
196
+ scope := MethodLexicalScope new.
197
+ scope addIVar: 'bzzz'.
198
+ self assert: (scope bindingFor: node) isInstanceVar
199
+ !
333
200
 
334
- definition := aDefinition
335
- !! !!
201
+ testPseudoVar
202
+ | node pseudoVars |
203
+ pseudoVars := #('self' 'super' 'true' 'false' 'nil').
204
+ pseudoVars do: [:each |
205
+ node := VariableNode new
206
+ value: each;
207
+ yourself.
208
+ self assert: (MethodLexicalScope new bindingFor: node) isPseudoVar ]
209
+ !
336
210
 
337
- !!CypressAddition class methodsFor: ''not yet classified''!!
211
+ testTempVar
212
+ | node scope |
213
+ node := VariableNode new
214
+ value: 'bzzz';
215
+ yourself.
216
+ scope := MethodLexicalScope new.
217
+ scope addTemp: 'bzzz'.
218
+ self assert: (scope bindingFor: node) isTempVar
219
+ !
338
220
 
339
- of: aDefinition
340
- ^ self new definition: aDefinition
341
- !! !!
221
+ testUnknownVar
222
+ | node |
223
+ node := VariableNode new
224
+ value: 'bzzz';
225
+ yourself.
226
+ self assert: (MethodLexicalScope new bindingFor: node) isNil
227
+ ! !
342
228
 
343
- CypressPatchOperation subclass: #CypressModification
344
- instanceVariableNames: ''obsoletion modification''
345
- package: ''Cypress-Definitions''!!
229
+ TestCase subclass: #SemanticAnalyzerTest
230
+ instanceVariableNames: 'analyzer'
231
+ package: 'Compiler-Tests'!
346
232
 
347
- !!CypressModification methodsFor: ''not yet classified''!!
233
+ !SemanticAnalyzerTest methodsFor: 'running'!
348
234
 
349
- base: base target: target
235
+ setUp
236
+ analyzer := SemanticAnalyzer on: Object
237
+ ! !
350
238
 
351
- obsoletion := base.
352
- modification := target.
353
- !! !!
239
+ !SemanticAnalyzerTest methodsFor: 'tests'!
354
240
 
355
- !!CypressModification class methodsFor: ''not yet classified''!!
241
+ testAssignment
242
+ | src ast |
356
243
 
357
- of: base to: target
358
- ^ self new base: base target: target
359
- !! !!
244
+ src := 'foo self := 1'.
245
+ ast := smalltalk parse: src.
246
+ self should: [analyzer visit: ast] raise: InvalidAssignmentError
247
+ !
360
248
 
361
- CypressPatchOperation subclass: #CypressRemoval
362
- instanceVariableNames: ''definition''
363
- package: ''Cypress-Definitions''!!
249
+ testNonLocalReturn
250
+ | src ast |
364
251
 
365
- !!CypressRemoval methodsFor: ''not yet classified''!!
252
+ src := 'foo | a | a + 1. ^ a'.
253
+ ast := smalltalk parse: src.
254
+ analyzer visit: ast.
366
255
 
367
- definition: aDefinition
256
+ self deny: ast scope hasNonLocalReturn
257
+ !
368
258
 
369
- definition := aDefinition
370
- !! !!
259
+ testNonLocalReturn2
260
+ | src ast |
371
261
 
372
- !!CypressRemoval class methodsFor: ''not yet classified''!!
262
+ src := 'foo | a | a + 1. [ [ ^ a] ]'.
263
+ ast := smalltalk parse: src.
264
+ analyzer visit: ast.
373
265
 
374
- of: aDefinition
375
- ^ self new definition: aDefinition
376
- !! !!
266
+ self assert: ast scope hasNonLocalReturn
267
+ !
377
268
 
378
- !!Object methodsFor: ''*Cypress-Definitions''!!
269
+ testScope
270
+ | src ast |
379
271
 
380
- species
272
+ src := 'foo | a | a + 1. [ | b | b := a ]'.
273
+ ast := smalltalk parse: src.
274
+ analyzer visit: ast.
381
275
 
382
- ^self class
383
- !! !!
276
+ self deny: ast nodes first nodes last scope == ast scope.
277
+ !
384
278
 
385
- !!Class methodsFor: ''*Cypress-Definitions''!!
279
+ testScope2
280
+ | src ast |
386
281
 
387
- asCypressClassDefinition
388
- ^CypressClassDefinition
389
- name: self name
390
- superclassName: self superclass name
391
- category: self category
392
- instVarNames: self instanceVariableNames
393
- classInstVarNames: self class instanceVariableNames
394
- comment: self comment
395
- !! !!
282
+ src := 'foo | a | a + 1. [ [ | b | b := a ] ]'.
283
+ ast := smalltalk parse: src.
284
+ analyzer visit: ast.
396
285
 
397
- !!CompiledMethod methodsFor: ''*Cypress-Definitions''!!
286
+ self deny: ast nodes first nodes last nodes first nodes first scope == ast scope.
287
+ !
398
288
 
399
- asCypressMethodDefinition
289
+ testScopeLevel
290
+ | src ast |
400
291
 
401
- ^CypressMethodDefinition
402
- className: self methodClass name
403
- classIsMeta: self methodClass isMetaclass
404
- selector: self selector
405
- category: self category
406
- source: self source
407
- !! !!
292
+ src := 'foo | a | a + 1. [ [ | b | b := a ] ]'.
293
+ ast := smalltalk parse: src.
294
+ analyzer visit: ast.
408
295
 
409
- !!CharacterArray methodsFor: ''*Cypress-Definitions''!!
296
+ self assert: ast scope scopeLevel = 1.
297
+ self assert: ast nodes first nodes last nodes first nodes first scope scopeLevel = 3
298
+ !
410
299
 
411
- sameAs: aString
300
+ testUnknownVariables
301
+ | src ast |
412
302
 
413
- ^self asUppercase = aString asUppercase
414
- !! !!
303
+ src := 'foo | a | b + a'.
304
+ ast := smalltalk parse: src.
415
305
 
416
- '
417
- ! !
306
+ self should: [ analyzer visit: ast ] raise: UnknownVariableError
307
+ !
418
308
 
419
- !ImporterTest methodsFor: 'running'!
309
+ testUnknownVariablesDefinedInJS
420
310
 
421
- setUp
311
+ < var someVariable = 1 >.
422
312
 
423
- super setUp.
424
- self cleanUp
313
+ self shouldnt: [ smalltalk parse: 'foo someVariable' ] raise: UnknownVariableError
425
314
  !
426
315
 
427
- tearDown
316
+ testUnknownVariablesWithScope
317
+ | src ast |
428
318
 
429
- super tearDown.
430
- self cleanUp
319
+ src := 'foo | a b | [ c + 1. [ a + 1. d + 1 ]]'.
320
+ ast := smalltalk parse: src.
321
+
322
+ self should: [ analyzer visit: ast ] raise: UnknownVariableError
431
323
  !
432
324
 
433
- cleanUp
434
-
435
- (Object methodDictionary includesKey: #importerTestMethod)
436
- ifTrue: [ Object removeCompiledMethod: (Object methodAt: #importerTestMethod)].
437
- ! !
438
-
439
- !ImporterTest methodsFor: 'tests'!
440
-
441
- testBigChunkString
442
- "importer does not correctly add extension methods.
443
-
444
- After loading in AmberProjectImporter, the following import fails...get a MNU from `CypressPackage new species`:
445
-
446
- AmberProjectImporter
447
- importSTPackage: 'Cypress-Definitions'
448
- prefix: 'tests/'.
325
+ testVariableShadowing
326
+ | src ast |
327
+ src := 'foo | a | a + 1'.
328
+ ast := smalltalk parse: src.
329
+ analyzer visit: ast
330
+ !
449
331
 
450
- CypressPackage new species.
332
+ testVariableShadowing2
333
+ | src ast |
334
+ src := 'foo | a | a + 1. [ | a | a := 2 ]'.
335
+ ast := smalltalk parse: src.
336
+ self should: [analyzer visit: ast] raise: ShadowingVariableError
337
+ !
451
338
 
452
- WARNING this guy isn't cleaned up automatically"
339
+ testVariableShadowing3
340
+ | src ast |
341
+ src := 'foo | a | a + 1. [ | b | b := 2 ]'.
342
+ ast := smalltalk parse: src.
343
+ analyzer visit: ast
344
+ !
453
345
 
454
- Importer new import: self bigChunkString readStream.
455
- CypressPackage new species.
346
+ testVariableShadowing4
347
+ | src ast |
348
+ src := 'foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]'.
349
+ ast := smalltalk parse: src.
350
+ analyzer visit: ast
456
351
  !
457
352
 
458
- testChunkString
353
+ testVariableShadowing5
354
+ | src ast |
355
+ src := 'foo | a | a + 1. [ [ [ | a | a := 2 ] ] ]'.
356
+ ast := smalltalk parse: src.
357
+ self should: [analyzer visit: ast] raise: ShadowingVariableError
358
+ !
459
359
 
460
- Importer new import: self chunkString readStream.
461
- self assert: (Object methodDictionary includesKey: 'importerTestMethod').
462
- self assert: (Object new importerTestMethod = 'success').
463
- ! !
360
+ testVariablesLookup
361
+ | src ast |
464
362
 
465
- !Object methodsFor: '*Compiler-Tests'!
363
+ src := 'foo | a | a + 1. [ | b | b := a ]'.
364
+ ast := smalltalk parse: src.
365
+ analyzer visit: ast.
466
366
 
467
- importerLoadMethod
367
+ "Binding for `a` in the message send"
368
+ self assert: ast nodes first nodes first receiver binding isTempVar.
369
+ self assert: ast nodes first nodes first receiver binding scope == ast scope.
468
370
 
469
- ^'success'
371
+ "Binding for `b`"
372
+ self assert: ast nodes first nodes last nodes first nodes first left binding isTempVar.
373
+ self assert: ast nodes first nodes last nodes first nodes first left binding scope == ast nodes first nodes last scope.
470
374
  ! !
471
375