-
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
Add booleans #30
base: main
Are you sure you want to change the base?
Add booleans #30
Conversation
There was a problem hiding this 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.
The reason I want to add booleans is to have a meaningful type to work with while implementing the typechecker.
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.
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.
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. |
We implement a new boolean type represented by
true
andfalse
tokens and some relations between integers (equal
,lesser
andgreater
) 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.