Function isolation, local vars, byte arrays + elif fix - #1
Open
Landen-Martin wants to merge 2 commits into
Open
Conversation
Implement a Python to NASM compiler for 64-bit architecture.
Implement checksum and classify functions for data processing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
1. register isolation on calls
x64 has no pushad/popad so I do it by hand. Every function prologue pushes rbx-r15 and
visit_Returnpops em back (rax is left alone for the return value).Before this, calling a function that used e.g. rbx internally would trash the caller's rbx with no warning. Now:
cost is some stack churn + a few bytes per call, but for the code this thing generates its worth it.
2. local vars
names that arent regs64 now get a stack slot instead of failing to compile.
find_locals()walks the function body at compile time and assigns each one an offset from rbp:slot is found via
locals_map, reset per function. const/reg/call assignment into a local all work.3. byte array init
gets pushed onto the stack as little-endian qwords (zero padded to a multiple of 8) and the target reg points at the first byte. handy for building buffers / small string tables without a data section.
4. elif fix
the no-else branch of
visit_Ifusedgeneric_visit(node)which also walksnode.orelse— so anelif(nested If inside orelse) got compiled twice and the labels were wrong. now the body is visited explicitly like the else path already did, and elif chains fall out of the existing orelse handling for free.5. cleanup
indentation was all over the place (mixed 4/8/20 spaces from the elif blocks), reformatted everything. no logic changes there.
example
added
example/check-class.pyshowing all of the above: checksum loop over a stack array, elif chain, callee that clobbers regs but doesn't matter now.known limits
rax = tag) is not wired up yet, only writes. move through a reg for nowThis is my first pull request. So I may get things Wrong.