Skip to content

Conversation

whoami730
Copy link
Contributor

@whoami730 whoami730 commented Sep 1, 2025

  • Parses cell & free vars from locals+names for Py 3.11+
  • Support new opcode COPY_FREE_VARS and MAKE_CELL with tests


if (mod->verCompare(2, 1) >= 0 && mod->verCompare(3, 11) < 0)
m_freeVars = LoadObject(stream, mod).cast<PycSequence>();
else if (mod->verCompare(3, 11) >= 0)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think given the complicated structure this whole function should be rewritten appropriately.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly seems quite hard to rewrite this function. I think default initializations would be quite useful here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default initializations themselves are not trivial :| It's annoying as well. I shall skip simplifying this logic at the moment.

pyc_output << "\n";
}

PycCode::nonlocals_t non_locals = code->getNonLocals();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Easier to duplicate from globals instead of handling both together. Can be changed if need be.

@whoami730
Copy link
Contributor Author

Requesting review @greenozon @zrax

m_names = LoadObject(stream, mod).cast<PycSequence>();

// Represents localsplusnames for py 3.11+
if (mod->verCompare(1, 3) >= 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment is misleading

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

umm so this variable is being used for two different purposes - corresponds to locals before 3.11 and localsplusnames after 3.11. More like locals has been repurposed in cpython to include non local and global variables as well.

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.

2 participants