Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ENVIRONMENT #200

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

shawwn
Copy link
Contributor

@shawwn shawwn commented Sep 17, 2018

environment is now a table rather than a list of tables. The parent
frame of the current environment is (get environment '%parent).

When implementing an interpreter for Lumen, I noticed that the current
design makes it costly to store lexical environments. Each closure
would need to store (cut environment), i.e. a clone of the
environment array.

Performance is almost identical: the new design is less than 1% slower
on LuaJIT, Lua, and Node.

I'm not sure this PR is worth merging. I dislike that the name
"%parent" is now reserved. If someone tries to define a macro or
special form named "%parent", it will break.

The good part is find-environment and current-environment. These
functions hide the details of Lumen's environment frames.

I'll submit this for now and think it over.

An idea to investigate: a get-properties function which takes an
arbitrary object or function and returns a table. That'd make it easy
to annotate environment frames, e.g. marking a frame as "the toplevel
of the current function", or "the module toplevel," etc). It'd be
similar to elisp's symbol-plist, but for objects/functions rather
than symbols.

ENVIRONMENT is now a table rather than a list of tables. The parent
frame of the current environment is `(get environment '%parent)`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant