Read in AST takes Assignable instead of Ident
This commit is contained in:
parent
bcd446c5d1
commit
ae1416e329
|
@ -144,7 +144,7 @@ pub enum StmtKind {
|
||||||
args: Vec<Expr>,
|
args: Vec<Expr>,
|
||||||
},
|
},
|
||||||
Print(Expr),
|
Print(Expr),
|
||||||
Read(Ident),
|
Read(Assignable),
|
||||||
Melo(Ident),
|
Melo(Ident),
|
||||||
Rlyeh,
|
Rlyeh,
|
||||||
Rickroll,
|
Rickroll,
|
||||||
|
|
|
@ -280,14 +280,21 @@ impl ExecEnv {
|
||||||
.write_all(include_str!("rickroll").as_bytes())
|
.write_all(include_str!("rickroll").as_bytes())
|
||||||
.expect("Failed to write to stdout");
|
.expect("Failed to write to stdout");
|
||||||
}
|
}
|
||||||
StmtKind::Read(ident) => {
|
StmtKind::Read(assignable) => {
|
||||||
let mut value = 0;
|
let mut value = 0;
|
||||||
for _ in 0..READ_BITS {
|
for _ in 0..READ_BITS {
|
||||||
value <<= 1;
|
value <<= 1;
|
||||||
value += self.get_bit()? as i32;
|
value += self.get_bit()? as i32;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.get_var_mut(ident)?.value.replace(Value::Int(value));
|
match assignable.kind {
|
||||||
|
AssignableKind::Variable => {
|
||||||
|
self.get_var_mut(&assignable.ident)?
|
||||||
|
.value
|
||||||
|
.replace(Value::Int(value));
|
||||||
|
}
|
||||||
|
AssignableKind::Index { .. } => todo!(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -370,12 +370,14 @@ impl<'source> Parser<'source> {
|
||||||
|
|
||||||
// Read input
|
// Read input
|
||||||
Token::Read => {
|
Token::Read => {
|
||||||
if let Some(Expr {
|
if let Some(Ok(assignable)) = buf.take().map(Assignable::from_expr) {
|
||||||
kind: ExprKind::Variable(ident),
|
self.require(Token::Semicolon)?;
|
||||||
span,
|
break StmtKind::Read(assignable);
|
||||||
}) = buf
|
} else {
|
||||||
{
|
return Err(Error::new(
|
||||||
break self.semi_terminated(StmtKind::Read(Ident::new(ident, span)))?;
|
ErrorKind::UnexpectedToken(Token::Read),
|
||||||
|
self.lexer.span(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue