forked from M-Labs/nac3
1
0
Fork 0

support assignments

This commit is contained in:
Sebastien Bourdeauducq 2020-03-29 14:10:06 +08:00
parent 05ac6fa2c1
commit a43c7b8d4f
1 changed files with 15 additions and 0 deletions

View File

@ -219,6 +219,21 @@ impl<'ctx> CodeGen<'ctx> {
use ast::StatementType::*; use ast::StatementType::*;
match &statement.node { match &statement.node {
Assign { targets, value } => {
let value = self.compile_expression(value)?;
for target in targets.iter() {
self.set_source_location(target.location);
if let ast::ExpressionType::Identifier { name } = &target.node {
if let Some(existing) = self.namespace.insert(name.clone(), value) {
if existing.get_type() != value.get_type() {
return Err(self.compile_error(CompileErrorKind::IncompatibleTypes));
}
}
} else {
return Err(self.compile_error(CompileErrorKind::Unsupported("assignment target must be an identifier")))
}
}
}
Return { value: Some(value) } => { Return { value: Some(value) } => {
if let Some(return_type) = return_type { if let Some(return_type) = return_type {
let value = self.compile_expression(value)?; let value = self.compile_expression(value)?;