Compare commits
No commits in common. "211cca50b8537174a984ff58192969f594ab9241" and "be3c415a573afc7430b1e874ff7ec4f720518242" have entirely different histories.
211cca50b8
...
be3c415a57
@ -60,8 +60,8 @@ Big features that I want later but are not necessary:
|
||||
Smaller features:
|
||||
- ~~Hex-numbers~~
|
||||
- Bitwise operations
|
||||
- ~~Easier way to initialize arrays with a single value~~
|
||||
- ~~Void-returns (`return;` for void-returning functions)~~
|
||||
- Easier way to initialize arrays with a single value
|
||||
- Void-returns (`return;` for void-returning functions)
|
||||
- ~~Only include standard library at all if it is imported~~
|
||||
- Lexical scopes for Debug Information
|
||||
|
||||
|
@ -1,7 +0,0 @@
|
||||
// Arithmetic, function calls and imports!
|
||||
|
||||
fn main() -> u16 {
|
||||
let mut a = [5; 20];
|
||||
|
||||
return a[15];
|
||||
}
|
@ -57,7 +57,6 @@ pub enum ExpressionKind {
|
||||
Deref(String),
|
||||
Literal(Literal),
|
||||
Array(Vec<Expression>),
|
||||
ArrayShort(Box<Expression>, u64),
|
||||
/// Array-indexed, e.g. <expr>[<expr>]
|
||||
Indexed(Box<Expression>, Box<Expression>),
|
||||
/// Struct-accessed, e.g. <expr>.<expr>
|
||||
|
@ -250,37 +250,16 @@ impl Parse for PrimaryExpression {
|
||||
}
|
||||
Token::BracketOpen => {
|
||||
stream.next(); // Consume
|
||||
let mut expressions = Vec::new();
|
||||
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();
|
||||
expressions.push(exp);
|
||||
while let Some(Token::Comma) = stream.peek() {
|
||||
stream.next(); // Consume comma
|
||||
expressions.push(stream.parse()?);
|
||||
}
|
||||
stream.expect(Token::BracketClose)?;
|
||||
Expression(Kind::Array(expressions), stream.get_range().unwrap())
|
||||
expressions.push(exp);
|
||||
while let Some(Token::Comma) = stream.peek() {
|
||||
stream.next(); // Consume comma
|
||||
expressions.push(stream.parse()?);
|
||||
}
|
||||
} else {
|
||||
stream.expect(Token::BraceClose)?;
|
||||
Expression(Kind::Array(Vec::new()), stream.get_range().unwrap())
|
||||
}
|
||||
stream.expect(Token::BracketClose)?;
|
||||
Expression(Kind::Array(expressions), stream.get_range().unwrap())
|
||||
}
|
||||
_ => Err(stream.expecting_err("expression")?)?,
|
||||
}
|
||||
|
@ -378,12 +378,6 @@ impl ast::Expression {
|
||||
Box::new(expression.process(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))
|
||||
|
@ -182,12 +182,3 @@ fn custom_binop_compiles_well() {
|
||||
Some(21),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn array_short_compiles_well() {
|
||||
test(
|
||||
include_str!("../../examples/array_short.reid"),
|
||||
"test",
|
||||
Some(5),
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user