compiler/benchmarks/PPCBenchmarkResources.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 01 May 2015 14:39:47 +0200
changeset 445 eb33780df2f9
parent 438 20598d7ce9fa
child 450 914c2567c987
permissions -rw-r--r--
Portability: Inlined #asLegalSelector since Smalltalk/X does not support it

"{ Package: 'stx:goodies/petitparser/compiler/benchmarks' }"

"{ NameSpace: Smalltalk }"

Object subclass:#PPCBenchmarkResources
	instanceVariableNames:''
	classVariableNames:'javaCache'
	poolDictionaries:''
	category:'PetitCompiler-Benchmarks-Core'
!


!PPCBenchmarkResources methodsFor:'as yet unclassified'!

changesSized: size
	| string changes |
	changes := PharoFilesOpener default changesFileOrNil contents.
	string :=  changes copyFrom: 1 to: size.
	^ string
	
!

javaInDirectory: directory
	| files |
	files := self readDirectory: directory.
	files := self files: files withExtension: 'java'.
	
	^ files collect: [ :f | (FileStream fileNamed: f) contents ]
!

javaLangMath
	^ (FileStream fileNamed: '../java-src/java/lang/Math.java') contents
!

javaSourcesBig
	^ self javaInDirectory: '../java-src/java/util'.
	"^ self workingJavaInDirectory: '../java-src/java/util'"
!

smalltalkInDirectory: directory
	| files |
	files := self readDirectory: directory.
	files := self files: files withExtension: 'st'.
	
	^ files collect: [ :f | (FileStream fileNamed: f) contents ]
!

smalltalkObjectMethods
	^ Object allMethods collect: [ :m | m sourceCode ].
!

smalltalkSourcesBig
	^ self smalltalkInDirectory: '../smalltalk-src/'
!

smalltalkSourcesBig_old
	^ ((Smalltalk allClasses copyFrom: 1 to: 30) collect: [ :c |
			c allMethods collect: [ :m | m sourceCode ]
	  ]) gather: [:each | each ].
!

workingJavaInDirectory: directory
	| sources parser |
	"return only such a files, that can be parsed by PPJavaSyntax"

	javaCache ifNil: [ javaCache := Dictionary new ].
	
	^ javaCache at: directory ifAbsentPut: [ 
		sources := self javaInDirectory: directory.
		parser := PPJavaSyntax new.
	
		sources select: [ :source | ([parser parse: source ] on: Error do: [ PPFailure new ]) isPetitFailure not ]	
	]
! !

!PPCBenchmarkResources methodsFor:'private utilities'!

files: files withExtension: extension
	^ files select: [ :f | f extension = extension ] 
!

readDirectory: directory
	| file |
	file := directory asFileReference.
	file exists ifTrue: [ 
		^ file allFiles
	].
	^ #()
! !

!PPCBenchmarkResources class methodsFor:'documentation'!

version_HG

    ^ '$Changeset: <not expanded> $'
! !