> 
> A second iteration now makes it work correctly for assignments:
> 
>       https://github.com/pharo-project/pharo/pull/1397
> 
> Smalltalk compiler
>        bindings: {(#test -> Point)} asDictionary;
>        evaluate: 'test := 42’.

While #bindings: allows us now to add additional bindings or override global 
bindings from Smalltalk globals, there is another feature missing that would be 
nice: be able to set the global environment

I want to be able to tell the compiler: Do not use Smalltalk globals, but this 
SystemDictionary instead.

        https://github.com/pharo-project/pharo/pull/1406

with this, we can create a SystemDictionary with just one binding in it:

        environment := SystemDictionary new.
        environment at: #MyClass put: Point.

then we compile a method:

        method := Smalltalk compiler 
                                        environment: environment;
                                        compile: 'tt ^MyClass’.

and if we execute it, it shows that compilation used the environment:

        return := method valueWithReceiver: nil arguments: #().
        self assert: return equals: Point.

If we try to compile a ref to Object, we get a nil ref:

        method := Smalltalk compiler 
                                        environment: environment;
                                        compile: 'tt ^Object'.
        return := method valueWithReceiver: nil arguments: #().
        self assert: return equals: nil.

But, as the Undeclared mechanism is not aware of it, it puts an undeclared for 
Object there.

In the same direction, all objects the compiler creates come still from 
Smalltalk globals (CompiledMethod, all Literals…).

But all this can be improved, we do pass the environment down the compiler 
chain already so that it is even available in the Parser/Scanner. Thus we could 
e.g. create Literals as instances from the classes in the environment. But how 
exactly has to be seen.

        Marcus



Reply via email to