clean up output

This commit is contained in:
collin 2020-04-15 22:17:44 -07:00
parent ac48138621
commit 833590ad40
4 changed files with 22 additions and 35 deletions

View File

@ -1,9 +1,6 @@
def test(field x) -> (field): struct Foo {
return 1 bool x
}
def test2(bool b) -> (bool): def main() -> (bool):
return b Foo f = Foo {x: true}
return f.x
def main() -> (field):
a = test2(true)
return a

View File

@ -634,21 +634,7 @@ impl ResolvedProgram {
ResolvedValue::Return( ResolvedValue::Return(
statements statements
.into_iter() .into_iter()
.map(|expression| match expression { .map(|expression| self.enforce_expression(cs, expression))
Expression::Boolean(boolean_expression) => {
self.enforce_boolean_expression(cs, boolean_expression)
}
Expression::FieldElement(field_expression) => {
self.enforce_field_expression(cs, field_expression)
}
Expression::Variable(variable) => {
self.resolved_variables.get_mut(&variable).unwrap().clone()
}
Expression::Struct(_v, _m) => {
unimplemented!("return struct not impl");
}
expr => unimplemented!("expression {} can't be returned yet", expr),
})
.collect::<Vec<ResolvedValue>>(), .collect::<Vec<ResolvedValue>>(),
) )
} }

View File

@ -165,7 +165,7 @@ pub struct Program {
pub id: String, pub id: String,
pub structs: HashMap<Variable, Struct>, pub structs: HashMap<Variable, Struct>,
pub functions: HashMap<Variable, Function>, pub functions: HashMap<Variable, Function>,
pub statements: Vec<Statement>, // pub statements: Vec<Statement>,
pub arguments: Vec<Variable>, pub arguments: Vec<Variable>,
pub returns: Vec<Variable>, pub returns: Vec<Variable>,
} }

View File

@ -703,25 +703,29 @@ impl<'ast> From<ast::File<'ast>> for types::Program {
let mut functions = HashMap::new(); let mut functions = HashMap::new();
file.structs.into_iter().for_each(|struct_def| { file.structs.into_iter().for_each(|struct_def| {
let struct_definition = types::Struct::from(struct_def); structs.insert(
structs.insert(struct_definition.variable.clone(), struct_definition); types::Variable::from(struct_def.variable.clone()),
types::Struct::from(struct_def),
);
}); });
file.functions.into_iter().for_each(|function_def| { file.functions.into_iter().for_each(|function_def| {
let function_definition = types::Function::from(function_def); functions.insert(
functions.insert(function_definition.variable.clone(), function_definition); types::Variable::from(function_def.variable.clone()),
types::Function::from(function_def),
);
}); });
let statements: Vec<types::Statement> = file // let statements: Vec<types::Statement> = file
.statements // .statements
.into_iter() // .into_iter()
.map(|statement| types::Statement::from(statement)) // .map(|statement| types::Statement::from(statement))
.collect(); // .collect();
types::Program { types::Program {
id: "main".into(), id: "main".into(),
structs, structs,
functions, functions,
statements, // statements,
arguments: vec![], arguments: vec![],
returns: vec![], returns: vec![],
} }