Comments (8)
In the main document you mention constant propagation.
But there's no constant propagation, only constant folding and dead code elimination, i.e. (byte-optimize '(let ((a 1)) (+ 2 a))
does not get compiled to a single constant 3. It doesn't work with lexical scoping enabled and it cannot work with dynamic scoping.
The example you showed ( (+ 2 3)
optimizing to 5 ) happens because the +
function has some specialized optimizing logic attached to it.
I wonder if it's possible to introduce a limited form of constant propagation for functions compiled with lexical scope enabled... It's a bit inconvenient using source-to-source transformations only, without a proper CFG, but should be doable.
from elisp-bytecode.
But there's no constant propagation, only constant folding and dead code elimination
Okay. Please correct what I wrote in a pull request. You have looked at this in more detail than I have.
I wonder if it's possible to introduce a limited form of constant propagation for functions compiled with lexical scope enabled... It's a bit inconvenient using source-to-source transformations only, without a proper CFG,
I have code written in Python to create a CFG and give some basic summary information about basic blocks. That is in the https://github.com/rocky/elisp-decompile project though.
from elisp-bytecode.
Okay. Please correct what I wrote in a pull request.
In fact, I am thinking about it right now. :-)
I was writing an article about Emacs Lisp implementation, both the interpreter and the compiler. Right now it's a huge draft describing relevant subsystems. But it's really hard to put together a coherent narrative using that kind of material, and I am still not sure if I want to publish it.
I wonder if can reuse some of the work done to improve your manual.
You have looked at this in more detail than I have.
I think that's only relatively speaking :-) I have looked into the optimizer throughly but it's not like I know a lot about the VM itself.
But I think the part of the manual related to optimizations should be restructured. E.g., in byteopt.el there's a very clear separation between the source-to-source transformation framework and the peephole optimizer (just a single function really). The peephole part has a very typical implementation, while the source-to-source transformations are ad hoc, and very, ehm, "lispish".
written in Python
While it's definitely interesting to take a look at a CFG, a Python implementation makes it impossible to use it for, say, data flow analysis within the compiler :-(
from elisp-bytecode.
@vkazanov, maybe this it outside the scope of your article, but perhaps it would be interesting to compare Emacs Lisp with Maclisp. As far as I can see, they are quite similar. E.g. both have obarray for looking up interned symbols.
from elisp-bytecode.
@larsbrinkhoff When writing articles I usually try to keep a target in mind. Here I am aiming to improve my understanding Lisp optimisation approaches and use it to improve the current Emacs Lisp optimizer.
I don't know much about Maclisp, apart from what they say on Wikipedia. Is it's code worth looking at?
obarray for looking up interned symbols
I think that's a very popular approach in lisp implementations, no?
from elisp-bytecode.
I don't think looking at Maclisp will help your understanding of the Emacs Lisp implementation.
from elisp-bytecode.
While it's definitely interesting to take a look at a CFG, a Python implementation makes it impossible to use it for, say, data flow analysis within the compiler :-(
The code to create a CFG in Python isn't that complicated or long (espcially compared to the rest of the decomplier with its J Earely algorithm parser). I believe it is straightforward to port this portion into Emacs Lisp. However given all the other things needed, I'm probably not going to be the one to do it.
from elisp-bytecode.
For me the question is not whether it's hard to build a CFG or not :-) the real problem is getting cfg-based optimizations into Emacs itself. Byte compilation is already relatively slow, adding machinery will only slow it down.
OTOH, this a path to many interesting possibilities... Proper constant propagation is really hard to do within the current framework. I had a chat with compiler people - they mostly mention newer SSA or traditional CFG-based approaches.
But that's a long discussion. Let's add some material into this book first! :-)
from elisp-bytecode.
Related Issues (12)
- Are/were the relative goto instructions ever emitted? HOT 7
- Is opcode 40 (unbind0) a nop?
- Add links into Emacs Manual...
- Document obsolete instructions
- Page numbers
- Contribute this to the emacs repository? HOT 1
- Typos HOT 1
- byte-opt.el commentary attribution HOT 5
- switch instruction doesn't jump to an offset HOT 3
- `goto` has no stack effects HOT 1
- `call` opcode documentation incorrect? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elisp-bytecode.