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

Compile time constant evaluation #241

Open
wants to merge 8 commits into
base: refactor-1.6
Choose a base branch
from

Conversation

chromapid
Copy link

@chromapid chromapid commented Dec 21, 2021

Hello,

This implements compile time constant evaluation as specified in #139. Anywhere an integer is permitted, there can instead be an expression that acts on any combination of these. Operations include shifts, rotations, arithmetic, and bitwise operations. The issue was fairly open-ended, so I took a bit of creative liberty in some of the features it has and how it operates. The token-based parsing system is fairly flexible, so it would not be a large problem to modify it to fit a different syntax.

The DUP factor does not support expressions right now as the amount of space the directive takes up can be dependent on labels, which depend on positions. However, the value to be repeated does support it.

The in-game editor does not recognize it as valid syntax, but it compiles successfully and seems to run perfectly in game. On that note, I added some tests in src/test/java/net/simon987/mar/server/assembly/TokenTest.java. I commented out a couple existing test cases as they conflicted with constant expressions.

There were some minor fixes I made here and there to get it the typescript to compile successfully in src/main/typescript/World.ts and src/main/typescript/phaser.d.ts. These are independent changes and may be reverted with no effect if they cause problems with different typescript versions (I am using v4.5.4 from npm).

@kevinramharak
Copy link
Collaborator

Thank you for implementing this feature. Do you know what needs to be added to the frontend to complete this feature?

@chromapid
Copy link
Author

The frontend needs to be able to understand that operation trees that act on constants should be considered a single, valid operator (except for before DUP, but that could potentially change). I don't know how the checks are implemented front-end so I can't really give anything more specific than that.

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