Coder Social home page Coder Social logo

Comments (3)

smarr avatar smarr commented on September 13, 2024

At least as an intermediate solution, the bytecode interpreter, needs a slightly adapted design to store the stack.

It is pretty much the same as the design for the AST-based interpreter, but we reserve space for the stack at the end of the Frame. The design of Inner remains unchanged.

Frame for Bytecode Interpreter

+-----------+
| Inner     | (Optional: for args/vars accessed from inner scopes, and non-local returns)
+-----------+
| Receiver  |
+-----------+
| Arg 1     |
| ...       |
| Arg n     |
+-----------+
| Local 1   |
| ...       |
| Local n   |  <-- initial StackPtr
+-----------+
| Stack     |
| ...       |
+-----------+
| StackPtr  |
+-----------+

To not have to pass around where to find the stack pointer, it's encoded in the last slot. The main reason here is not to have to change the common parts between AST and BC frames. Though, performance-wise it might not be optimal, because it's not a constant offset. The semantics of the stack pointer is that it points to the current element. For an empty stack, i.e., the initial StackPtr this means it points to the element before the first stack element.

In the long term, I hope the stack won't need to be part of the frame anymore. In TruffleSOM, it already works nicely to keep the stack simply in the interpreter loop and never escape it from there. The hope is that a compiler has an easier time to simply eliminate the array for the stack. For PySOM's bytecode interpreter, I'll have to see whether this works out and is worth it.

from pysom.

smarr avatar smarr commented on September 13, 2024

RPython Implementation Note

To make the RPython type system happy, everything stored in the Frame needs to be type erased (see rlib.rerased).
This is needed to be able to store a list together with the AbstractObject SOM objects, and the int for the StackPtr in the same list.

Since the Inner only stores AbstractObject instances, it doesn't need erasure.

For simplicity, the OnStack marker is simply a trueObject or falseObject, which should boil down to simply pointer comparisons.

from pysom.

smarr avatar smarr commented on September 13, 2024

Performance results for the AST interpreter changes:

https://rebench.stefan-marr.de/compare/RPySOM/3fd5865e788069ccf94775fc033242061ef1a2a2/41f23dc5073d8a8b21222e7c687739dee581cb6a#micro-steady-RPySOM-ast-jit

from pysom.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.