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

Add booleans #30

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Add booleans #30

wants to merge 2 commits into from

Conversation

Nirei
Copy link
Collaborator

@Nirei Nirei commented Jan 5, 2025

We implement a new boolean type represented by true and false tokens and some relations between integers (equal, lesser and greater) to take advantage of it. As it is this boolean type doesn't provide much value but it's a good candidate for some elementary typechecking.

@Nirei Nirei self-assigned this Jan 5, 2025
@Nirei Nirei added the enhancement New feature or request label Jan 5, 2025
Copy link
Owner

@TheVaultdweller13 TheVaultdweller13 left a comment

Choose a reason for hiding this comment

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

I find the instructions equal, lesser, and greater useful, but I have mixed feelings about adding the boolean type, at least until we have typing and more protection in place.

Right now, the stack is being used for everything, including the value -> pointer pair, and adding another data type, I think, could significantly increase the chances of messing things up and using something that isn't even an integer as a pointer.

Additionally, I think it would be more interesting to explore the possibility of creating constants (maybe the old assign could be used for this?) and, as in many assemblers, giving the user the freedom to define the constants TRUE/FALSE as 1/0.

That said, and seeing that the stack is starting to gain special relevance, I think it would be interesting to open an issue for creating a standard library called "stack_utils" that would allow operations and checks on the stack, such as viewing the first element, checking if the stack is empty, emptying it, etc.

@Nirei
Copy link
Collaborator Author

Nirei commented Jan 8, 2025

@TheVaultdweller13

at least until we have typing

The reason I want to add booleans is to have a meaningful type to work with while implementing the typechecker.

could significantly increase the chances of messing things up

In all fairness, you can attempt to store something at a string address right now so I don't think this is our biggest concern.

push "lol" # this works and it probably shouldn't
push "lmao"
store # stores lmao at address lol

I don't even know if this executes but it's a correct imperivm program, so I'd say adding booleans doesn't make it any more dangerous, but adding types would actually make it safe.

Additionally, I think it would be more interesting to explore the possibility of creating constants (maybe the old assign could be used for this?) and, as in many assemblers, giving the user the freedom to define the constants TRUE/FALSE as 1/0.

Constants are great but do nothing for typing. You cannot type something to be "of the type ot these two constants that I have here".

My vision for this project is that it's an strictly typechecked language. We cannot get that without types to check, thus this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants