[go: up one dir, main page]

Skip to content

Implement flat closures for bytecodes virtual machine

Until now we've maintained lexenv as an immutable list - a structure that is friendly for environments. The demerit of capturing it in closures is that we maintain references to many objects that otherwise could have been garbage collected. Moreover, access to individual elements in the closure was O(n) because we need to traverse the list to find the nth-local, while now it is a matter of an array access.

For the method overview see: https://www.european-lisp-symposium.org/static/proceedings/2023.pdf#page=64 https://andykeep.com/pubs/scheme-12a.pdf

That said cl-bench does not indicate any significant performance improvement. In a matter of fact some tests are slower"

  • compilation and fasl loading -- that is expected since we use a more sophisticated mechanism
  • CLOS/methodcalls and CLOS/method+after -- this is probably because creating a closure introduces additional step to decide the source

Having that in mind, I think that we should merge this because of GC and simpler access model.

This pull request is a draft, because the next step is to make local variables to be stored on the stack instead of consing a new list. When that is done, I'll change the pull request status, although the part until now should be fine for review.

Other changes in this branch:

  • fix set-closure-env wrt self-referencing objects (we were putting the compiler in infinite loop before)
  • allow recompiling flet/labels defined functions even when they accessed local macros over the function boundary
  • simplify the stepper logic by moving it as a hook to trace.lsp (opcodes do minimal job necessary)
  • introduce new opcodes for cons_car and cons_cdr primops, simplify function calls in the interpreter
  • move (SETF FOO) functions to symbol object (instead of maintaining a global hash table)

Merge request reports

Loading