-
Notifications
You must be signed in to change notification settings - Fork 0
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
rewrite code generation #21
Merged
Merged
Conversation
This file contains 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
This should help to better understand the structure of the compiler
this file is replaced by `inc/assembly/registers.h`
functionality is replaced in `src/generation/arch/x86-64/assembly/registers.c`
for future implementations
to match the structure of the `src` directory
limitations: - only `number`, `boolean`, `character` literals are supported - not all binary expression will work as expected --> will be fixed later
+ fix char literal generation
when dividing, RAX contains the quotient and RDX contains the remainder. RDX also contains the high bits of the dividend (RDX:RAX). The problem was, that the compiler did not know that RDX could be non zero. This lead to the problem, where RDX should be zero, but is set to the remainder of an other division, which results in the wrong result or an FloatingPoint exception -> crash of the program Implemented Solution: clear RDX before every division with XOR (xor rdx, rdx) Better solution: the compiler should know if RDX could be non zero and then clear RDX before the division
previously an error was throw when a variable was declared which had the same identifier as a variable in the parent scope. This is now fixed
the null terminator was missing
…/luvascript-compiler into lucalewin/remake-code-generation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
documentation
Improvements or additions to documentation
enhancement
New feature or request
feature request
fix
includes a fix to an issue
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.
Reason
The previous method of code generation was messy. It was pretty hard to implement new features like #11 or #12.
Therefore I decided to rewrite the code generation for x86-64 machines completely.
Difference between the old and new generation
The old method was based on functions returning the code they generated which would then be concatenated with the code in the current function. This and using some badly written utility functions resulted in a lot of memory leaks.
The new method uses an additional data structure to store the generated instructions during the generation. After the generation finishes, the data structure will be stringified, which requires a lot less string concatenation.
String Literals
The main reason to work on this was to resolve #11. As previously stated it was nearly impossible to implement it in the old code generation system. Therefore the new system was designed to be able to support local string literals.
This old example
can now be rewritten in a much simpler form
which previously was impossible.
String Table
This is now possible because of the implementation of a String Table which stores all string literals that are defined.
The String Table also holds an array of labels to allow multiple variables to reference the same string literal. It also makes sure that if a string literal is defined multiple times, it will only be generated once.
Example:
The string literal "Test" is defined twice, but in the generated assembly code:
it is only generated once.
Tests
This pull request also contains new tests for conditional expressions and string literals.
But there are also two tests (one new, one old) that currently fail. I'm going to fix them with another pull request.
Tags
#11 #12