Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3748-Compiler-add-the-concept-of-a-productionEnvironment-enable-for-CompiledMethod #3749

Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -23,6 +23,7 @@ Class {
'interactive',
'options',
'environment',
'productionEnvironment',
'parserClass',
'semanticAnalyzerClass',
'astTranslatorClass',
@@ -581,6 +582,16 @@ CompilationContext >> parserClass: anObject [
parserClass := anObject
]
{ #category : #accessing }
CompilationContext >> productionEnvironment [
^productionEnvironment ifNil: [ ^self environment ]
]
{ #category : #accessing }
CompilationContext >> productionEnvironment: aDictionary [
productionEnvironment := aDictionary
]
{ #category : #accessing }
CompilationContext >> requestor [
^ requestor
@@ -75,7 +75,8 @@ Class {
'forceLongForm',
'primNumber',
'encoderClass',
'inBlock'
'inBlock',
'compilationContext'
],
#category : #'OpalCompiler-Core-Bytecode'
}
@@ -163,6 +164,11 @@ IRBytecodeGenerator >> closureFrom: fromSeqId to: toSeqId copyNumCopiedValues: n
encoder genPushClosureCopyNumCopiedValues: numCopied numArgs: numArgs2 jumpSize: distance.
]

{ #category : #accessing }
IRBytecodeGenerator >> compilationContext: aCompilationContext [
compilationContext := aCompilationContext
]

{ #category : #results }
IRBytecodeGenerator >> compiledBlockWith: trailer [
| lits header cb |
@@ -203,8 +209,10 @@ IRBytecodeGenerator >> compiledMethodWith: trailer [

{ #category : #results }
IRBytecodeGenerator >> compiledMethodWith: trailer header: header literals: lits [
| cm |
cm := trailer createMethod: self bytecodes size class: CompiledMethod header: header.
| cm cmClass|
"we look up the class in the productionEnvironment"
cmClass := compilationContext productionEnvironment at: #CompiledMethod ifAbsent: [ CompiledMethod ].
This conversation was marked as resolved by MarcusDenker

This comment has been minimized.

Copy link
@dionisiydk

dionisiydk Jul 3, 2019

Contributor

Like here. Why "compilationContext environment at: #CompiledMethod" is not enough?

This comment has been minimized.

Copy link
@dionisiydk

dionisiydk Jul 3, 2019

Contributor

I think I see.
For example in TelePharo the remote playground doIt's are compiled locally using remote environment for globals. But method is created as local object using local CompiledMethod class.
At the end method is sent to remote side for execution.

In other scenario we would want to use different method class. For example we could copy CompiledMethod and modify its logic for experiment. Then we will need to use it to test compilation

This comment has been minimized.

Copy link
@MarcusDenker

MarcusDenker Jul 3, 2019

Author Member

yes, exactly.

This comment has been minimized.

Copy link
@dionisiydk

dionisiydk Jul 3, 2019

Contributor

Now I wonder what other objects you are going to retrieve from this productionEnvironment?
Or in other words why simple variable #compilerMethodClass is not enough?

This comment has been minimized.

Copy link
@MarcusDenker

MarcusDenker Jul 3, 2019

Author Member

The idea is that this might be extended to all the Literal objects that are part of the compiledMethod that is created: Symbol, String, Array, ....

cm := trailer createMethod: self bytecodes size class: cmClass header: header.
(WriteStream with: cm)
position: cm initialPC - 1;
nextPutAll: self bytecodes.
@@ -354,6 +362,7 @@ IRBytecodeGenerator >> initialize [
forceLongForm := false.
"starting label in case one is not provided by client"
self label: self newDummySeqId.
compilationContext := CompilationContext default.



@@ -35,7 +35,8 @@ IRTranslatorV2 >> compilationContext [
{ #category : #accessing }
IRTranslatorV2 >> compilationContext: aContext [
compilationContext := aContext.
gen := compilationContext bytecodeGeneratorClass newWithEncoderClass: compilationContext encoderClass
gen := compilationContext bytecodeGeneratorClass newWithEncoderClass: compilationContext encoderClass.
gen compilationContext: aContext.
]

{ #category : #results }
@@ -707,6 +707,11 @@ OpalCompiler >> parserClass [
^self compilationContext parserClass
]

{ #category : #accessing }
OpalCompiler >> productionEnvironment: anObject [
compilationContext productionEnvironment: anObject
]

{ #category : #accessing }
OpalCompiler >> receiver: anObject [
receiver := anObject.
@@ -0,0 +1,6 @@
Class {
#name : #MyCompiledMethodForTesting,
#superclass : #CompiledMethod,
#type : #compiledMethod,
#category : #'OpalCompiler-Tests-Semantic'
}
@@ -4,10 +4,13 @@ tests related to environment
Class {
#name : #OCEnvironmentScopeTest,
#superclass : #TestCase,
#instVars : [
'oldSystemAnnouncer'
],
#category : #'OpalCompiler-Tests-Semantic'
}

{ #category : #tests }
{ #category : #'tests - environment' }
OCEnvironmentScopeTest >> testCompileWithEnvironment [
| environment method return |
environment := SystemDictionary new.
@@ -25,7 +28,20 @@ OCEnvironmentScopeTest >> testCompileWithEnvironment [
self assert: return equals: nil.
]

{ #category : #tests }
{ #category : #'test - production - environment' }
OCEnvironmentScopeTest >> testCompileWithProductionEnvironment [
| environment method return |
environment := {#CompiledMethod -> MyCompiledMethodForTesting} asDictionary.
method := Smalltalk compiler
productionEnvironment: environment;
compile: 'tt ^1+2'.

self assert: method class equals: MyCompiledMethodForTesting.
return := method valueWithReceiver: nil arguments: #().
self assert: return equals: 3.
]

{ #category : #'tests - environment' }
OCEnvironmentScopeTest >> testCreateEnvironmentScope [
| new |
new := OCEnvironmentScope for: Smalltalk globals.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.