-
-
Notifications
You must be signed in to change notification settings - Fork 353
/
OCCompiledMethodIntegrityTest.class.st
114 lines (99 loc) · 3.49 KB
/
OCCompiledMethodIntegrityTest.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
Class {
#name : #OCCompiledMethodIntegrityTest,
#superclass : #TestCase,
#category : #'OpalCompiler-Tests-Misc'
}
{ #category : #test }
OCCompiledMethodIntegrityTest >> testBlockTemps [
| newCompiledMethod |
newCompiledMethod := OpalCompiler new
source:
'ascentOf: aCharacter
^ [ | temp1 temp2 temp3 | 1= temp1. 2 = temp2. 3 = temp3].';
class: OCMockCompilationClass;
compile.
self assert: newCompiledMethod numArgs equals: 1.
self assert: (newCompiledMethod numLiterals = 3 or: [ newCompiledMethod numLiterals = 4 "Sista Bytecode" ]).
self assert: newCompiledMethod numTemps equals: 1.
self assert: newCompiledMethod primitive equals: 0
]
{ #category : #test }
OCCompiledMethodIntegrityTest >> testNotUsedArgument [
| newCompiledMethod |
newCompiledMethod := OpalCompiler new
source:
'ascentOf: aCharacter
^ self ascent.';
class: OCMockCompilationClass;
compile.
self assert: newCompiledMethod numArgs equals: 1.
self assert: newCompiledMethod numLiterals equals: 3.
self assert: newCompiledMethod numTemps equals: 1.
self assert: newCompiledMethod primitive equals: 0
]
{ #category : #test }
OCCompiledMethodIntegrityTest >> testPragmas [
| newCompiledMethod |
newCompiledMethod := OpalCompiler new
source:
'methodDoublePragma
<hello: 5>
<hello: 2>';
class: OCMockCompilationClass;
compile.
self assert: newCompiledMethod numArgs equals: 0.
self assert: newCompiledMethod numLiterals equals: 2.
"AdditionalState assertions"
self assert: newCompiledMethod allLiterals first selector equals: #methodDoublePragma.
self assert: (newCompiledMethod allLiterals first instVarNamed: 'method') equals: newCompiledMethod.
self assert: newCompiledMethod primitive equals: 256
]
{ #category : #test }
OCCompiledMethodIntegrityTest >> testPrimitive [
| newCompiledMethod |
newCompiledMethod := OpalCompiler new
source:
'size
<primitive: 62>
^ self basicSize.';
class: OCMockCompilationClass;
compile.
self assert: newCompiledMethod numArgs equals: 0.
self assert: newCompiledMethod numLiterals equals: 3.
self assert: newCompiledMethod numTemps equals: 0.
self assert: newCompiledMethod primitive equals: 62
]
{ #category : #test }
OCCompiledMethodIntegrityTest >> testRemoteTempInVector [
| newCompiledMethod expectedLiterals |
newCompiledMethod := OpalCompiler new
source:
'value
| answer |
self do:
[:each |
answer := each value].
^answer';
class: Object;
compile.
"In FullBlockClosure the block is another literal of the method"
expectedLiterals := (CompilationContext optionFullBlockClosure) ifTrue: [ 3 ] ifFalse: [ 2 ].
self assert: newCompiledMethod numArgs equals: 0.
self assert: newCompiledMethod numLiterals equals: expectedLiterals.
self assert: newCompiledMethod numTemps equals: 1.
self assert: newCompiledMethod primitive equals: 0
]
{ #category : #test }
OCCompiledMethodIntegrityTest >> testUndeclaredVariable [
| newCompiledMethod undeclaredBinding |
newCompiledMethod := OpalCompiler new
source:
'methodWithUndeclaredVar
^ undeclaredTestVar';
class: OCMockCompilationClass;
compile.
undeclaredBinding := newCompiledMethod literals detect: [ :each | each name = #undeclaredTestVar ].
self assert: undeclaredBinding class equals: UndeclaredVariable.
self assert: undeclaredBinding identicalTo: (Undeclared associationAt: #undeclaredTestVar).
Undeclared removeKey: #undeclaredTestVar
]