What about a preprocessor like the Java preprocessors ? The Truffle project
relies heavily on that for high performance Java and it's quite nice. It's
difficult to do that in Smalltalk right now.

I think if you want to do what are asking for you just need to write a
bytecode compiler extension.

I did something similar in the past to have precomputed constants through
AST manipulation at compilation time. You can find it here with examples:
http://smalltalkhub.com/#!/~ClementBera/NeoCompiler. Once the code is
loaded you need to recompile the examples (NeoCompilerExample
withAllSubclassesDo: #compileAll.). With it you can write code such as:
[ Smalltalk vm class ] Cvalue
And depending if the compiler allowsPrecompilation or not, the bytecode
compiler generates:
Smalltalk vm class
Or just a push literal with the precomputed value (the class VirtualMachine
).
In the end I decided not to use this, but you can use it and extend it to
support more than just constants (any AST manipulation is possible).
Just checked it works in Pharo 6.

On Fri, May 25, 2018 at 4:26 PM, Stephan Eggermont <step...@stack.nl> wrote:

> Debiller 777 <ozovozovozo...@gmail.com>
> wrote:
> > Well, I've already asked about adding new literals to pharo or
> Smalltalk in
> > general, however this time I have a better idea:
> > macros. Can they be added? Because if I understand correctly they may be
> > the only way to do that.
>
> Why do you think they would be a good idea? We have powerful
> meta-programming facilities that are well understood and somewhat supported
> by tooling. How do we get value out of macros?
>
> Stephan
>
>
>
>


-- 
Clément Béra
https://clementbera.github.io/
https://clementbera.wordpress.com/

Reply via email to