-
Notifications
You must be signed in to change notification settings - Fork 5
Ranged Integers #66
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
base: master
Are you sure you want to change the base?
Ranged Integers #66
Conversation
Add test cases |
Add types to in code values / constants |
Cast module |
Fix this:
|
Well it seems that that on its own should never typecheck. Rather either the user should specify a cast, or add a |
Add lower bound to all ints too. |
The semantics of MIN and MAX should be: So int #(MIN: 3, MAX: 16) can have a value from 3-15 inclusive. It makes for better ergonomics. (powers of 2, clog2, etc) |
Oh also, BitsToInt will need to be expressed from the source bits, as we can't really make any statements about the value of these bits. We'll need a |
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.
Looks good, does it appear to behave correctly as you use it?
@@ -500,3 +500,130 @@ impl DelayedConstraint<InstantiationContext<'_, '_>> for SubmoduleTypecheckConst | |||
.error(submod_instr.get_most_relevant_span(), message); | |||
} | |||
} | |||
|
|||
#[derive(Debug)] | |||
struct BinaryOpTypecheckConstraint { |
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.
We'll also need UnaryOpTypecheckConstraint
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.
What exactly do the UnaryOperator::Sum/UnaryOperator::Product
do with arrays?
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.
Well, the sum of an array has as its bounds Size * MIN .. Size * (MAX-1)+1, as for the product, it should have bounds MIN ^ Size, (MAX - 1) ^ Size + 1
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.
Though this kind of intersects with #74 we'll have to figure out a better design for such large unary reductions at some point
Actually, thinking further about it, we should make both IntToBits and BitsToInt have a template argument in the number of bits. And then have #75 Deal with the integer cast |
Add a compiler intrinsic for casting ints |
Div & Modulo should error on is_zero |
Update Value::get_type to properly handle sized ints |
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.
Thorough analysis of the cases, well done!
/// Returns the inclusive bounds of an int. An int #(MIN: 0, MAX: 15) will return (0, 14) | ||
pub fn get_bounds(&self) -> (IBig, IBig) { | ||
let min = self.unwrap_named().template_args[UUID::from_hidden_value(0)] | ||
.unwrap_value() | ||
.unwrap_integer(); | ||
let max = self.unwrap_named().template_args[UUID::from_hidden_value(1)] | ||
.unwrap_value() | ||
.unwrap_integer(); | ||
(min.clone(), max - 1) | ||
} |
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 recently added FlatAlloc::cast_to_array
and FlatAlloc::map_to_array
. (https://github.com/pc2/sus-compiler/blob/master/src/alloc.rs#L622-L632) That would make this code a bit nicer
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.
As an example of it used: https://github.com/pc2/sus-compiler/blob/master/src/instantiation/execute.rs#L272
Thinking about it, arg.unwrap_value().unwrap_integer()
is used a lot in this kind of code, perhaps even adding a get_integer_template_args_array
method to ConcreteGlobalReference
would make code more compact still
Close #28