Comments (1)
I looked at this a bit today with @alisomay and here are some notes from our discussion:
- The optimization opportunity is in reusing registers in the value stack, rather than pushing a new frame's worth of registers into the stack.
- The call stack (containing frame info) can be left alone for the time being, we wouldn't want to lose the stack trace in the case of an error, so at least the chunk and ip for each frame will be needed.
- There may be a compression optimization possible when the chunk and ip match in subsequent frames..
- A new
TailCall
instruction can be added which performs a tail call, reusing the current frame's registers.- In the case of a binary op, the RHS of the op would be the tail call, the LHS would have already been evaluated. The LHS result then needs to be cached, probably in register
0
, and then the tail call frame base would be register1
, with result register also1
. The op can then be executed following the tail call before the function exits.- In the case of a binary op and the current frame's frame base is unused, then it would be possible to cache the LHS result in the frame base rather than register
0
. How this would work exactly isn't clear (it would effectively be saying to the op that the LHS is in register-1
), but it would still be a win to cache in register0
so I think this doesn't have to be figured out to move forward.
- In the case of a binary op and the current frame's frame base is unused, then it would be possible to cache the LHS result in the frame base rather than register
- In the case of a binary op, the RHS of the op would be the tail call, the LHS would have already been evaluated. The LHS result then needs to be cached, probably in register
- To compile the
TailCall
instruction, the compiler could pass an 'allow tail call' flag around while compiling nodes. This flag would be set to true when compiling a return expression, and then set to false when a tail call should be explicitly disallowed (e.g. when compiling the LHS of a binary op).- The 'result register' which is passed around in the 'compile node' functions could be replaced with a context struct (similar to the one used by the parser) which can then be extended with the new tail call flag.
from koto.
Related Issues (20)
- Reverse iterators HOT 1
- `@as_bool` meta key HOT 1
- Add `iterator.cycle` HOT 2
- Single-threaded runtime
- Add REPL support for the Delete key
- Add `iterator.flatten`
- Arrow key movement broken in the REPL on Windows
- Run wasm tests on CI
- `num2`/`num4` improvements
- Add load/run functions to allow for running Koto code inside a script
- Function objects, `@||` meta key HOT 1
- Noob question. How do i print something without a newline? HOT 2
- KotoFile::id() should return a ValueString
- Add language support to Helix text editor HOT 2
- Remove packed numbers (Num2 / Num4)
- Add geometry and color libs HOT 1
- Remove Value's implementation of fmt::Display
- Stack overflow when displaying recursive objects
- `+=` and other assignment operations broken in the REPL
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 koto.