RegressionTests__CompilerTests2.st
changeset 921 cb5e99d58aab
parent 900 7acbd0cce153
child 922 7c65bb0a73f5
--- a/RegressionTests__CompilerTests2.st	Thu Apr 25 15:49:40 2013 +0200
+++ b/RegressionTests__CompilerTests2.st	Thu Apr 25 16:26:14 2013 +0200
@@ -3,7 +3,7 @@
 "{ NameSpace: RegressionTests }"
 
 TestCase subclass:#CompilerTests2
-	instanceVariableNames:''
+	instanceVariableNames:'methods enabledJIT'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'tests-Regression'
@@ -12,6 +12,39 @@
 
 !CompilerTests2 methodsFor:'private'!
 
+compile: source mode: mode
+    "Compile given source and returns the new method.
+     The from the source is prepended the mode + underscore
+     (i.e., foo -> stc_foo).
+
+     If mode is:
+       #stc....then the method is stc-compiled.
+       #jit....then the method is bytecode compiled and left
+               to the jitter
+       #bc.....them the method is bytecode compiled and marked
+               as checked so JIT won't even try.
+    "
+
+    | m |
+
+    Class withoutUpdatingChangesDo:[
+        mode == #stc ifTrue:[
+            ParserFlags withSTCCompilation:#always do:[
+                m := self class compile: (mode, '_', source) classified: 'private - *dynamic*'.
+            ].
+        ] ifFalse:[
+            ParserFlags withSTCCompilation:#never do:[
+                m := self class compile: (mode, '_', source) classified: 'private - *dynamic*'.
+                m checked: (mode == #bc)
+            ].
+        ].
+    ].
+    methods add: m.
+    ^m
+
+    "Created: / 25-04-2013 / 15:18:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 currentLineNumber
     thisContext fixAllLineNumbers.
     ^thisContext sender lineNumber.
@@ -332,18 +365,31 @@
 
 !CompilerTests2 methodsFor:'setup'!
 
-tearDown
+setUp
+    methods := Set new.
+    enabledJIT := ObjectMemory justInTimeCompilation.
+
+    "Created: / 25-04-2013 / 15:20:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
 
-    (Smalltalk at: #'exept_regression_testData_CompilerTests2') notNil ifTrue:[
-	(Smalltalk at: #'exept_regression_testData_CompilerTests2') classes do:[:e|
-	    e notNil ifTrue:[
-		Smalltalk removeClass: e
-	    ].
-	]
-    ].
+tearDown
+    ObjectMemory justInTimeCompilation: enabledJIT.
+    Class withoutUpdatingChangesDo:[
+        (Smalltalk at: #'exept_regression_testData_CompilerTests2') notNil ifTrue:[
+            (Smalltalk at: #'exept_regression_testData_CompilerTests2') classes do:[:e|
+                e notNil ifTrue:[
+                    Smalltalk removeClass: e
+                ].
+            ]
+        ].
+
+        methods do:[:m|
+            m mclass removeSelector: m selector.
+        ]
+    ]
 
     "Created: / 26-10-2012 / 11:32:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 12-02-2013 / 16:12:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 25-04-2013 / 15:21:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !CompilerTests2 methodsFor:'tests'!
@@ -426,72 +472,49 @@
 test_lineno_01_bci
     | m002 m300 l |
 
-    m002 := self class >> #method_lineno_002.
-    m002 code: nil.
-    m002 checked: true.
+    m002 := self compile: (self class >> #method_lineno_002) source mode: #bc.
+    m300 := self compile: (self class >> #method_lineno_300) source mode: #bc.
 
-    m300 := self class >> #method_lineno_300.
-    m002 code: nil.
-    m002 checked: true.
-
-    self assert: (l := self method_lineno_002) == 2.
-    self assert: (l := self method_lineno_300) == 300.
+    self assert: (l := self bc_method_lineno_002) == 2.
+    self assert: (l := self bc_method_lineno_300) == 300.
 
     self assert: m002 code isNil.
     self assert: m300 code isNil.
 
     "Created: / 12-04-2013 / 21:24:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 25-04-2013 / 15:24:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 test_lineno_01_jit
     | m002 m300 l |
 
-    m002 := self class >> #method_lineno_002.
-    m002 code: nil.
-    m002 checked: false.
-    self method_lineno_002; method_lineno_002.
+    m002 := self compile: (self class >> #method_lineno_002) source mode: #jit.
+    m300 := self compile: (self class >> #method_lineno_300) source mode: #jit.
 
-    m300 := self class >> #method_lineno_300.
-    m002 code: nil.
-    m002 checked: false.
-    self method_lineno_300;method_lineno_300.
+    self assert: (l := self jit_method_lineno_002) == 2.
+    self assert: (l := self jit_method_lineno_300) == 300.
 
-    self assert: (l := self method_lineno_002) == 2.
-    self assert: (l := self method_lineno_300) == 300.
-
-    self assert: m002 code notNil.
-    self assert: m300 code notNil.
+    self assert: m002 code isNil.
+    self assert: m300 code isNil.
 
     "Created: / 12-04-2013 / 21:41:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 25-04-2013 / 15:25:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 test_lineno_01_stc
     | m002 m300 l |
 
     m002 := self class >> #method_lineno_002.
-    ChangeSet withoutUpdatingChangesDo:[
-        ParserFlags withSTCCompilation:#always do:[
-            self class compile: 'STC_', m002 source classified: 'private - *dynamic*'
-        ].
-    ].
+    m300 := self class >> #method_lineno_300.
 
-    m300 := self class >> #method_lineno_300.
-    ChangeSet withoutUpdatingChangesDo:[
-        ParserFlags withSTCCompilation:#always do:[
-            self class compile: 'STC_', m300 source classified: 'private - *dynamic*'
-        ].
-    ].
-    [
-        self assert: (l := self STC_method_lineno_002) == 2.
-        self assert: (l := self STC_method_lineno_300) == 300.
-    ] ensure:[
-        self class
-            removeSelector:#STC_method_lineno_002;
-            removeSelector:#STC_method_lineno_300
-    ]
+    self compile: m002 source mode: #stc.
+    self compile: m300 source mode: #stc.
+
+    self assert: (l := self stc_method_lineno_002) == 2.
+    self assert: (l := self stc_method_lineno_300) == 300.
 
     "Created: / 12-04-2013 / 21:50:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 13-04-2013 / 10:13:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 25-04-2013 / 15:22:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !CompilerTests2 class methodsFor:'documentation'!