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):
return 1
def test2(bool b) -> (bool):
return b
def main() -> (field):
a = test2(true)
return a
struct Foo {
bool x
}
def main() -> (bool):
Foo f = Foo {x: true}
return f.x

View File

@ -634,21 +634,7 @@ impl ResolvedProgram {
ResolvedValue::Return(
statements
.into_iter()
.map(|expression| match 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),
})
.map(|expression| self.enforce_expression(cs, expression))
.collect::<Vec<ResolvedValue>>(),
)
}

View File

@ -165,7 +165,7 @@ pub struct Program {
pub id: String,
pub structs: HashMap<Variable, Struct>,
pub functions: HashMap<Variable, Function>,
pub statements: Vec<Statement>,
// pub statements: Vec<Statement>,
pub arguments: 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();
file.structs.into_iter().for_each(|struct_def| {
let struct_definition = types::Struct::from(struct_def);
structs.insert(struct_definition.variable.clone(), struct_definition);
structs.insert(
types::Variable::from(struct_def.variable.clone()),
types::Struct::from(struct_def),
);
});
file.functions.into_iter().for_each(|function_def| {
let function_definition = types::Function::from(function_def);
functions.insert(function_definition.variable.clone(), function_definition);
functions.insert(
types::Variable::from(function_def.variable.clone()),
types::Function::from(function_def),
);
});
let statements: Vec<types::Statement> = file
.statements
.into_iter()
.map(|statement| types::Statement::from(statement))
.collect();
// let statements: Vec<types::Statement> = file
// .statements
// .into_iter()
// .map(|statement| types::Statement::from(statement))
// .collect();
types::Program {
id: "main".into(),
structs,
functions,
statements,
// statements,
arguments: vec![],
returns: vec![],
}