1 "{ Package: 'stx:goodies/petitparser/compiler/tests/extras' }" |
1 "{ Package: 'stx:goodies/petitparser/compiler/tests/extras' }" |
2 |
2 |
3 "{ NameSpace: Smalltalk }" |
3 "{ NameSpace: Smalltalk }" |
4 |
4 |
5 TestResource subclass:#PPCResources |
5 TestResource subclass:#PPCResources |
6 instanceVariableNames:'' |
6 instanceVariableNames:'cache' |
7 classVariableNames:'javaCache' |
7 classVariableNames:'javaCache' |
8 poolDictionaries:'' |
8 poolDictionaries:'' |
9 category:'PetitCompiler-Extras-Tests-Support' |
9 category:'PetitCompiler-Extras-Tests-Support' |
10 ! |
10 ! |
11 |
11 |
12 PPCResources comment:'' |
12 !PPCResources methodsFor:'expressions'! |
|
13 |
|
14 expressionOfSize: size |
|
15 | stream | |
|
16 stream := WriteStream on: (String new: size * 5). |
|
17 self expressionOfSize: size stream: stream. |
|
18 ^ stream contents |
13 ! |
19 ! |
|
20 |
|
21 expressionOfSize: size stream: stream |
|
22 | index rand | |
|
23 index := 0. |
|
24 rand := Random new. |
|
25 |
|
26 [index < size] whileTrue: [ |
|
27 (rand next < 0.1) ifTrue: [ |
|
28 | subSize | |
|
29 subSize := rand nextInt: (size - index - 1) + 1. |
|
30 stream nextPutAll: ' ('. |
|
31 self expressionOfSize: subSize stream: stream. |
|
32 stream nextPutAll: ') '. |
|
33 index := index + subSize. |
|
34 ] ifFalse: [ |
|
35 stream nextPutAll: (rand nextInt: 10) asString. |
|
36 index := index + 1. |
|
37 ]. |
|
38 |
|
39 (index < size) ifTrue: [ |
|
40 (rand next < 0.5) |
|
41 ifTrue: [ stream nextPutAll: ' + ' ] |
|
42 ifFalse: [ stream nextPutAll: ' * ' ] |
|
43 ] |
|
44 ] |
|
45 ! |
|
46 |
|
47 expressionSourcesBig |
|
48 | sources | |
|
49 |
|
50 cache at: #expressionSourcesBig ifAbsentPut: [ |
|
51 sources := OrderedCollection new. |
|
52 |
|
53 2000 timesRepeat: [ |
|
54 sources add: (self expressionOfSize: 200). |
|
55 ]. |
|
56 sources |
|
57 ]. |
|
58 |
|
59 ^ cache at: #expressionSourcesBig |
|
60 |
|
61 ! |
|
62 |
|
63 expressionSourcesMedium |
|
64 | sources | |
|
65 |
|
66 cache at: #expressionSourcesMedium ifAbsentPut: [ |
|
67 sources := OrderedCollection new. |
|
68 |
|
69 1000 timesRepeat: [ |
|
70 sources add: (self expressionOfSize: 100). |
|
71 ]. |
|
72 sources |
|
73 ]. |
|
74 |
|
75 ^ cache at: #expressionSourcesMedium |
|
76 |
|
77 ! ! |
|
78 |
|
79 !PPCResources methodsFor:'initialization'! |
|
80 |
|
81 initialize |
|
82 super initialize. |
|
83 cache := IdentityDictionary new |
|
84 ! ! |
14 |
85 |
15 !PPCResources methodsFor:'java'! |
86 !PPCResources methodsFor:'java'! |
16 |
87 |
17 javaInDirectory: directory |
88 javaInDirectory: directory |
18 | files | |
89 | files | |
21 |
92 |
22 ^ files collect: [ :f | (FileStream fileNamed: f) contents ] |
93 ^ files collect: [ :f | (FileStream fileNamed: f) contents ] |
23 ! |
94 ! |
24 |
95 |
25 javaLangMath |
96 javaLangMath |
26 ^ (FileStream fileNamed: '../java-src/java/lang/Math.java') contents |
97 ^ (FileStream fileNamed: '../java-src/java/lang/Math.java') contents asString |
|
98 |
|
99 "Modified: / 10-05-2015 / 14:11:03 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
27 ! |
100 ! |
28 |
101 |
29 javaSourcesBig |
102 javaSourcesBig |
30 ^ self javaInDirectory: '../java-src/java/util'. |
103 ^ self javaInDirectory: '../java-src/java/util'. |
31 "^ self workingJavaInDirectory: '../java-src/java/util'" |
104 "^ self workingJavaInDirectory: '../java-src/java/util'" |
32 ! |
105 ! |
33 |
106 |
34 javaUtilTimer |
107 javaUtilTimer |
35 ^ (FileStream fileNamed: '../java-src/java/util/Timer.java') contents |
108 ^ (FileStream fileNamed: '../java-src/java/util/Timer.java') contents asString |
|
109 |
|
110 "Modified: / 10-05-2015 / 14:11:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
36 ! |
111 ! |
37 |
112 |
38 workingJavaInDirectory: directory |
113 workingJavaInDirectory: directory |
39 | sources parser | |
114 | sources parser | |
40 "return only such a files, that can be parsed by PPJavaSyntax" |
115 "return only such a files, that can be parsed by PPJavaSyntax" |
55 ^ files select: [ :f | f extension = extension ] |
130 ^ files select: [ :f | f extension = extension ] |
56 ! |
131 ! |
57 |
132 |
58 readDirectory: directory |
133 readDirectory: directory |
59 | file | |
134 | file | |
60 file := directory asFileReference. |
135 |
61 file exists ifTrue: [ |
136 ( (Smalltalk respondsTo: #isSmalltalkX) and:[ Smalltalk isSmalltalkX ] ) ifTrue:[ |
|
137 file := directory asFilename. |
|
138 file exists ifFalse:[ |
|
139 self error: 'Directory does not exist'. |
|
140 ]. |
|
141 ^ file recursiveDirectoryContentsAsFilenames select:[:each | each isRegularFile ] |
|
142 ] ifFalse:[ |
|
143 "Assuming Pharo..." |
|
144 |
|
145 file := directory asFileReference. |
|
146 file exists ifFalse: [ |
|
147 self error: 'Directory does not exist'. |
|
148 ]. |
62 ^ file allFiles |
149 ^ file allFiles |
63 ]. |
150 ] |
64 ^ #() |
151 |
|
152 "Modified: / 10-05-2015 / 07:54:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
65 ! ! |
153 ! ! |
66 |
154 |
67 !PPCResources methodsFor:'smalltalk'! |
155 !PPCResources methodsFor:'smalltalk'! |
68 |
156 |
69 smalltalkClassMethods |
157 smalltalkClassMethods |