Compiler: add the concept of a Production Environment

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Compiler: add the concept of a Production Environment

Marcus Denker-4
Hi,

We added support for setting a “production environment” for the compiler:

When compiling, there might be the case that the result of the compiler (the compiledMethod) should not be an instance of the class CompiledMethod from the environment
in which we compile, but from some other environment.

(e.g. imagine you have multiple environments and want to cross cross compile)

This PR adds the concept of a productionEnvironment and enables it for CompiledMethod.
(other use cases might make sense, too, for example all the literals in the CompiledMethod, this is future work but can be done similarly by handing the context into the Scanner)

This is our test for CompiledMethod:

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.

As one can see, the produces compiled method of the Compiler is an instance of our class.

PR needs a Review: https://github.com/pharo-project/pharo/pull/3749/files