compiler/tests/extras/PPCResources.st
changeset 460 87a3d30ab570
parent 457 76de2febe7d2
parent 459 4751c407bb40
child 461 5986bf6d7d60
--- a/compiler/tests/extras/PPCResources.st	Mon May 11 18:31:26 2015 +0100
+++ b/compiler/tests/extras/PPCResources.st	Tue May 12 01:33:33 2015 +0100
@@ -3,12 +3,84 @@
 "{ NameSpace: Smalltalk }"
 
 TestResource subclass:#PPCResources
-	instanceVariableNames:''
+	instanceVariableNames:'cache'
 	classVariableNames:'javaCache'
 	poolDictionaries:''
 	category:'PetitCompiler-Extras-Tests-Support'
 !
 
+!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'!