compiler/tests/extras/PPCResources.st
changeset 459 4751c407bb40
parent 452 9f4558b3be66
child 460 87a3d30ab570
child 464 f6d77fee9811
--- a/compiler/tests/extras/PPCResources.st	Sun May 10 06:28:36 2015 +0100
+++ b/compiler/tests/extras/PPCResources.st	Tue May 12 01:24:03 2015 +0100
@@ -3,15 +3,86 @@
 "{ NameSpace: Smalltalk }"
 
 TestResource subclass:#PPCResources
-	instanceVariableNames:''
+	instanceVariableNames:'cache'
 	classVariableNames:'javaCache'
 	poolDictionaries:''
 	category:'PetitCompiler-Extras-Tests-Support'
 !
 
-PPCResources comment:''
+!PPCResources methodsFor:'expressions'!
+
+expressionOfSize: size
+    | stream |
+    stream := WriteStream on: (String new: size * 5).
+    self expressionOfSize: size stream: stream.
+    ^ stream contents
+!
+
+expressionOfSize: size stream: stream
+    | index rand |
+    index := 0.
+    rand := Random new.
+    
+    [index < size] whileTrue: [ 
+ 		(rand next < 0.1) ifTrue: [  
+            | subSize |
+            subSize := rand nextInt: (size - index - 1) + 1.
+            stream nextPutAll: ' ('.
+            self expressionOfSize: subSize stream: stream.
+            stream nextPutAll: ') '.
+            index := index + subSize.
+        ] ifFalse: [ 
+            stream nextPutAll: (rand nextInt: 10) asString.
+            index := index + 1.
+        ].
+    
+        (index < size) ifTrue: [ 
+ 			(rand next < 0.5) 
+                ifTrue: [  stream nextPutAll: ' + ' ] 
+                ifFalse: [ stream nextPutAll: ' * ' ]
+        ]
+    ]
 !
 
+expressionSourcesBig
+    | sources |
+    
+    cache at: #expressionSourcesBig ifAbsentPut: [ 
+        sources := OrderedCollection new.
+        
+        2000 timesRepeat: [ 
+            sources add: (self expressionOfSize: 200).
+        ].
+        sources	
+    ].
+
+    ^ cache at: #expressionSourcesBig
+    
+!
+
+expressionSourcesMedium
+    | sources |
+    
+    cache at: #expressionSourcesMedium ifAbsentPut: [ 
+        sources := OrderedCollection new.
+        
+        1000 timesRepeat: [ 
+            sources add: (self expressionOfSize: 100).
+        ].
+        sources	
+    ].
+
+    ^ cache at: #expressionSourcesMedium
+    
+! !
+
+!PPCResources methodsFor:'initialization'!
+
+initialize
+    super initialize.
+    cache := IdentityDictionary new
+! !
+
 !PPCResources methodsFor:'java'!
 
 javaInDirectory: directory
@@ -23,7 +94,9 @@
 !
 
 javaLangMath
-    ^ (FileStream fileNamed: '../java-src/java/lang/Math.java') contents
+    ^ (FileStream fileNamed: '../java-src/java/lang/Math.java') contents asString
+
+    "Modified: / 10-05-2015 / 14:11:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 javaSourcesBig
@@ -32,7 +105,9 @@
 !
 
 javaUtilTimer
-    ^ (FileStream fileNamed: '../java-src/java/util/Timer.java') contents
+    ^ (FileStream fileNamed: '../java-src/java/util/Timer.java') contents asString
+
+    "Modified: / 10-05-2015 / 14:11:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 workingJavaInDirectory: directory
@@ -57,11 +132,24 @@
 
 readDirectory: directory
     | file |
-    file := directory asFileReference.
-    file exists ifTrue: [ 
+
+    ( (Smalltalk respondsTo: #isSmalltalkX) and:[ Smalltalk isSmalltalkX ] ) ifTrue:[ 
+        file := directory asFilename.
+        file exists ifFalse:[  
+            self error: 'Directory does not exist'.
+        ].
+        ^ file recursiveDirectoryContentsAsFilenames select:[:each | each isRegularFile ]
+    ] ifFalse:[ 
+        "Assuming Pharo..."
+
+        file := directory asFileReference.
+        file exists ifFalse: [ 
+            self error: 'Directory does not exist'.
+        ].
         ^ file allFiles
-    ].
-    ^ #()
+    ]
+
+    "Modified: / 10-05-2015 / 07:54:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !PPCResources methodsFor:'smalltalk'!