Compare commits

..

No commits in common. "211cca50b8537174a984ff58192969f594ab9241" and "be3c415a573afc7430b1e874ff7ec4f720518242" have entirely different histories.

6 changed files with 9 additions and 53 deletions

View File

@ -60,8 +60,8 @@ Big features that I want later but are not necessary:
Smaller features: Smaller features:
- ~~Hex-numbers~~ - ~~Hex-numbers~~
- Bitwise operations - Bitwise operations
- ~~Easier way to initialize arrays with a single value~~ - Easier way to initialize arrays with a single value
- ~~Void-returns (`return;` for void-returning functions)~~ - Void-returns (`return;` for void-returning functions)
- ~~Only include standard library at all if it is imported~~ - ~~Only include standard library at all if it is imported~~
- Lexical scopes for Debug Information - Lexical scopes for Debug Information

View File

@ -1,7 +0,0 @@
// Arithmetic, function calls and imports!
fn main() -> u16 {
let mut a = [5; 20];
return a[15];
}

View File

@ -57,7 +57,6 @@ pub enum ExpressionKind {
Deref(String), Deref(String),
Literal(Literal), Literal(Literal),
Array(Vec<Expression>), Array(Vec<Expression>),
ArrayShort(Box<Expression>, u64),
/// Array-indexed, e.g. <expr>[<expr>] /// Array-indexed, e.g. <expr>[<expr>]
Indexed(Box<Expression>, Box<Expression>), Indexed(Box<Expression>, Box<Expression>),
/// Struct-accessed, e.g. <expr>.<expr> /// Struct-accessed, e.g. <expr>.<expr>

View File

@ -250,38 +250,17 @@ impl Parse for PrimaryExpression {
} }
Token::BracketOpen => { Token::BracketOpen => {
stream.next(); // Consume stream.next(); // Consume
if let Ok(exp) = stream.parse() {
if let Some(Token::Semi) = stream.peek() {
stream.next(); // Consume colon
let Some(Token::DecimalValue(val)) = stream.next() else {
return Err(stream
.expecting_err("decimal value describing array length")?);
};
stream.expect(Token::BracketClose)?;
Expression(
Kind::ArrayShort(
Box::new(exp),
u64::from_str_radix(&val, 10).expect(
"Unable to parse array length to 64-bit decimal value",
),
),
stream.get_range().unwrap(),
)
} else {
let mut expressions = Vec::new(); let mut expressions = Vec::new();
if let Ok(exp) = stream.parse() {
expressions.push(exp); expressions.push(exp);
while let Some(Token::Comma) = stream.peek() { while let Some(Token::Comma) = stream.peek() {
stream.next(); // Consume comma stream.next(); // Consume comma
expressions.push(stream.parse()?); expressions.push(stream.parse()?);
} }
}
stream.expect(Token::BracketClose)?; stream.expect(Token::BracketClose)?;
Expression(Kind::Array(expressions), stream.get_range().unwrap()) Expression(Kind::Array(expressions), stream.get_range().unwrap())
} }
} else {
stream.expect(Token::BraceClose)?;
Expression(Kind::Array(Vec::new()), stream.get_range().unwrap())
}
}
_ => Err(stream.expecting_err("expression")?)?, _ => Err(stream.expecting_err("expression")?)?,
} }
} else { } else {

View File

@ -378,12 +378,6 @@ impl ast::Expression {
Box::new(expression.process(module_id)), Box::new(expression.process(module_id)),
ty.0.clone().into_mir(module_id), ty.0.clone().into_mir(module_id),
), ),
ast::ExpressionKind::ArrayShort(expression, len) => mir::ExprKind::Array(
vec![*expression.clone(); *len as usize]
.iter()
.map(|e| e.process(module_id))
.collect(),
),
}; };
mir::Expression(kind, self.1.as_meta(module_id)) mir::Expression(kind, self.1.as_meta(module_id))

View File

@ -182,12 +182,3 @@ fn custom_binop_compiles_well() {
Some(21), Some(21),
); );
} }
#[test]
fn array_short_compiles_well() {
test(
include_str!("../../examples/array_short.reid"),
"test",
Some(5),
);
}