1
0
forked from M-Labs/nac3

support assignments

This commit is contained in:
Sebastien Bourdeauducq 2020-03-29 14:10:06 +08:00
parent 05ac6fa2c1
commit a43c7b8d4f

View File

@ -219,6 +219,21 @@ impl<'ctx> CodeGen<'ctx> {
use ast::StatementType::*;
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) } => {
if let Some(return_type) = return_type {
let value = self.compile_expression(value)?;