Skip to content

Instantly share code, notes, and snippets.

@scascketta
Created August 26, 2024 05:59
Show Gist options
  • Save scascketta/15a6b76820d53508f64dca166875b90e to your computer and use it in GitHub Desktop.
Save scascketta/15a6b76820d53508f64dca166875b90e to your computer and use it in GitHub Desktop.

Conversation begins at https://discord.com/channels/267624335836053506/846434317021741086/850821189097226260

well mypyc compiles to C code. you can inspect it in build/__native.c search for something like "fudebopeva.py", "<module>", 42 and you'll find the code it generates for line 42 so it's doing this

    cpy_r_r147 = CPyStatics[17]; /* 'DEFAULT_TOKEN' */
    cpy_r_r148 = CPyDict_GetItem(cpy_r_r146, cpy_r_r147);

which looks a lot like it's looking up DEFAULT_TOKEN in the globals dict then if it's successful it turns the PyObject into a tagged integer and I just realized that's why I got confused, all the integer values are multiplied by 2 because the last bit is used as a tag ... so then it does

    cpy_r_r150.f0 = 8;
    cpy_r_r150.f1 = cpy_r_r149;

8 = 4 = PERCENT so that's how it makes the pair (PERCENT, DEFAULT_TOKEN)

@scascketta
Copy link
Author

@scascketta
Copy link
Author

Try tweaking the separate param of mypycify

@scascketta
Copy link
Author

Might have to expect some breakages of new interpreter versions, but not necessarily going to block new builds mypyc/mypyc#995

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment