mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-23 02:01:54 +03:00
remove unsized arrays
This commit is contained in:
parent
f2c4d8d078
commit
10bea676a8
@ -23,8 +23,6 @@ use std::{fmt, ops::Deref};
|
||||
/// A single array dimension.
|
||||
#[derive(Clone, Deserialize, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum Dimension {
|
||||
/// The dimension is `_`, that is unspecified and syntactically unknown.
|
||||
Unspecified,
|
||||
/// The dimension was specified, e.g., `5` elements.
|
||||
Number(PositiveNumber),
|
||||
}
|
||||
@ -32,7 +30,6 @@ pub enum Dimension {
|
||||
impl fmt::Display for Dimension {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
Self::Unspecified => write!(f, "_"),
|
||||
Self::Number(num) => write!(f, "{}", num),
|
||||
}
|
||||
}
|
||||
@ -42,7 +39,6 @@ impl Dimension {
|
||||
/// } Returns `Some(n)` unless the dimension is [`Unspecified`].
|
||||
pub fn as_specified(&self) -> Option<&PositiveNumber> {
|
||||
match self {
|
||||
Self::Unspecified => None,
|
||||
Self::Number(n) => Some(n),
|
||||
}
|
||||
}
|
||||
@ -71,11 +67,6 @@ impl ArrayDimensions {
|
||||
Self(smallvec![dim])
|
||||
}
|
||||
|
||||
/// Returns true if the dimensions are not [`Unspecified`].
|
||||
pub fn is_specified(&self) -> bool {
|
||||
!self.contains(&Dimension::Unspecified)
|
||||
}
|
||||
|
||||
/// Returns `true` if there is an array dimension equal to zero.
|
||||
pub fn is_zero(&self) -> bool {
|
||||
self.iter().any(|d| d.is_zero())
|
||||
@ -96,7 +87,7 @@ impl ArrayDimensions {
|
||||
}
|
||||
}
|
||||
|
||||
/// Custom Serializer for ArrayDimensios is required to ignore internal ArrayDimension nodes in the AST.
|
||||
/// Custom Serializer for ArrayDimensions is required to ignore internal ArrayDimension nodes in the AST.
|
||||
impl Serialize for ArrayDimensions {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@ -106,7 +97,6 @@ impl Serialize for ArrayDimensions {
|
||||
for dim in self.0.iter() {
|
||||
match dim {
|
||||
Dimension::Number(num) => seq.serialize_element(&num)?,
|
||||
Dimension::Unspecified => seq.serialize_element(&PositiveNumber { value: "0".into() })?,
|
||||
}
|
||||
}
|
||||
seq.end()
|
||||
|
@ -132,14 +132,10 @@ impl TryFrom<(Type, Expression)> for InputValue {
|
||||
|
||||
Self::Tuple(elements)
|
||||
}
|
||||
(Type::Array(element_type, dimensions), Expression::ArrayInline(array_inline)) => {
|
||||
(Type::Array(element_type, _dimensions), Expression::ArrayInline(array_inline)) => {
|
||||
let mut elements = Vec::with_capacity(array_inline.elements.len());
|
||||
let span = array_inline.span().clone();
|
||||
|
||||
if !dimensions.is_specified() {
|
||||
return Err(InputError::array_dimensions_must_be_specified(&span).into());
|
||||
}
|
||||
|
||||
for element in array_inline.elements.into_iter() {
|
||||
if let SpreadOrExpression::Expression(value_expression) = element {
|
||||
elements.push(Self::try_from((*element_type.clone(), value_expression))?);
|
||||
|
@ -89,11 +89,6 @@ impl Type {
|
||||
let mut left_dims = left_dims.to_owned();
|
||||
let mut right_dims = right_dims.to_owned();
|
||||
|
||||
// Unable to compare arrays with unspecified sizes.
|
||||
if !left_dims.is_specified() || !right_dims.is_specified() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove the first element from both dimensions.
|
||||
let left_first = left_dims.remove_first();
|
||||
let right_first = right_dims.remove_first();
|
||||
|
@ -84,8 +84,6 @@ impl ParserContext<'_> {
|
||||
fn parse_array_dimension(&mut self) -> Option<Dimension> {
|
||||
if let Some((int, _)) = self.eat_int() {
|
||||
Some(Dimension::Number(int))
|
||||
} else if self.eat(Token::Underscore).is_some() {
|
||||
Some(Dimension::Unspecified)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -1013,7 +1013,7 @@ An array type consists of an element type
|
||||
and an indication of dimensions.
|
||||
There is either a single dimension,
|
||||
or a tuple of one or more dimensions.
|
||||
Each dimension is either a natural or is unspecified.
|
||||
Each dimension is natural.
|
||||
|
||||
<a name="array-type"></a>
|
||||
```abnf
|
||||
|
@ -650,7 +650,7 @@ tuple-type = "(" [ type 1*( "," type ) ] ")"
|
||||
; and an indication of dimensions.
|
||||
; There is either a single dimension,
|
||||
; or a tuple of one or more dimensions.
|
||||
; Each dimension is either a natural or is unspecified.
|
||||
; Each dimension is natural.
|
||||
|
||||
array-type = "[" type ";" array-type-dimensions "]"
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
[main]
|
||||
a: u32 = 1;
|
||||
b: u32 = 2;
|
||||
y: bool = true;
|
||||
|
||||
[registers]
|
||||
r0: u32 = 0;
|
||||
r0: bool = false;
|
||||
|
@ -1,5 +1,11 @@
|
||||
// The 'hello-world' main function.
|
||||
function main(a: u32, b: u32) -> u32 {
|
||||
let c: u32 = a + b;
|
||||
return c;
|
||||
type str = [char; _];
|
||||
|
||||
function main(y: bool) -> bool {
|
||||
let s = "abc";
|
||||
return (first_el(s) == 'a') == y;
|
||||
}
|
||||
|
||||
function first_el(s: str) -> char {
|
||||
return s[0];
|
||||
}
|
||||
|
@ -312,12 +312,4 @@ create_errors!(
|
||||
msg: format!("Tried to assign to static member `{}`", member),
|
||||
help: None,
|
||||
}
|
||||
|
||||
/// For when arrays with unspecified size are used in main.
|
||||
@formatted
|
||||
input_array_size_must_be_specified {
|
||||
args: (),
|
||||
msg: "arrays in main function input must have known size",
|
||||
help: None,
|
||||
}
|
||||
);
|
||||
|
@ -46,14 +46,6 @@ create_errors!(
|
||||
help: None,
|
||||
}
|
||||
|
||||
/// For when [`ArrayDimensions`] are not specified.
|
||||
@formatted
|
||||
array_dimensions_must_be_specified {
|
||||
args: (),
|
||||
msg: "array dimensions must be specified",
|
||||
help: None,
|
||||
}
|
||||
|
||||
/// For when array init is using spread.
|
||||
@formatted
|
||||
array_spread_is_not_allowed {
|
||||
|
Loading…
Reference in New Issue
Block a user