1
0
Fork 0
mirror of synced 2025-09-24 04:40:05 +00:00

fix positions in imports, fix flatten test

This commit is contained in:
schaeff 2019-05-21 15:57:46 +02:00
parent 68dcaa1b15
commit b795feb7aa
3 changed files with 58 additions and 65 deletions

View file

@ -32,6 +32,10 @@ pub trait NodeValue: fmt::Display + Sized + PartialEq {
Node::new(start, start.col(delta), self)
}
fn start_end(self, start: Position, end: Position) -> Node<Self> {
Node::new(start, end, self)
}
#[cfg(test)]
fn mock(self) -> Node<Self> {
Node::new(Position::mock(), Position::mock(), self)

View file

@ -1234,60 +1234,60 @@ impl<T: Field> Flattener<T> {
}
}
// #[cfg(test)]
// mod tests {
// use super::*;
// use crate::types::Signature;
// use crate::types::Type;
// use zokrates_field::field::FieldPrime;
#[cfg(test)]
mod tests {
use super::*;
use crate::types::Signature;
use crate::types::Type;
use zokrates_field::field::FieldPrime;
// #[test]
// fn multiple_definition() {
// // def foo()
// // return 1, 2
// // def main()
// // a, b = foo()
#[test]
fn multiple_definition() {
// def foo()
// return 1, 2
// def main()
// a, b = foo()
// let mut flattener = Flattener::new();
// let mut functions_flattened = vec![FlatFunction {
// id: "foo".to_string(),
// arguments: vec![],
// statements: vec![FlatStatement::Return(FlatExpressionList {
// expressions: vec![
// FlatExpression::Number(FieldPrime::from(1)),
// FlatExpression::Number(FieldPrime::from(2)),
// ],
// })],
// signature: Signature::new()
// .inputs(vec![])
// .outputs(vec![Type::FieldElement, Type::FieldElement]),
// }];
// let mut statements_flattened = vec![];
// let statement = TypedStatement::MultipleDefinition(
// vec![
// Variable::field_element("a".to_string()),
// Variable::field_element("b".to_string()),
// ],
// TypedExpressionList::FunctionCall(
// "foo".to_string(),
// vec![],
// vec![Type::FieldElement, Type::FieldElement],
// ),
// );
let mut flattener = Flattener::new();
let foo = TypedFunction {
arguments: vec![],
statements: vec![TypedStatement::Return(vec![
FieldElementExpression::Number(FieldPrime::from(1)).into(),
FieldElementExpression::Number(FieldPrime::from(2)).into(),
],
)],
signature: Signature::new()
.inputs(vec![])
.outputs(vec![Type::FieldElement, Type::FieldElement]),
};
let mut statements_flattened = vec![];
let statement = TypedStatement::MultipleDefinition(
vec![
Variable::field_element("a".to_string()),
Variable::field_element("b".to_string()),
],
TypedExpressionList::FunctionCall(
FunctionKey::with_id("foo").signature(Signature::new().outputs(vec![Type::FieldElement, Type::FieldElement])),
vec![],
vec![Type::FieldElement, Type::FieldElement],
),
);
// flattener.flatten_statement(
// &mut functions_flattened,
// &mut statements_flattened,
// statement,
// );
let symbols = vec![(FunctionKey::with_id("foo").signature(Signature::new().outputs(vec![Type::FieldElement, Type::FieldElement])), TypedFunctionSymbol::Here(foo))].into_iter().collect();
// let a = FlatVariable::new(0);
flattener.flatten_statement(
&symbols,
&mut statements_flattened,
statement,
);
// assert_eq!(
// statements_flattened[0],
// FlatStatement::Definition(a, FlatExpression::Number(FieldPrime::from(1)))
// );
// }
let a = FlatVariable::new(0);
assert_eq!(
statements_flattened[0],
FlatStatement::Definition(a, FlatExpression::Number(FieldPrime::from(1)))
);
}
// #[test]
// fn multiple_definition2() {
@ -2147,4 +2147,4 @@ impl<T: Field> Flattener<T> {
// FlatVariable::new(2)
// );
// }
// }
}

View file

@ -7,7 +7,6 @@
use crate::absy::*;
use crate::compile::compile_module;
use crate::compile::{CompileErrorInner, CompileErrors};
use crate::flat_absy::*;
use crate::parser::Position;
use std::collections::HashMap;
use std::fmt;
@ -15,16 +14,6 @@ use std::io;
use std::io::BufRead;
use zokrates_field::field::Field;
pub struct CompiledImport<T: Field> {
pub flat_func: FlatFunction<T>,
}
impl<T: Field> CompiledImport<T> {
fn new(prog: FlatProg<T>, alias: String) -> CompiledImport<T> {
unimplemented!("refactor imported flattened funcs")
}
}
#[derive(PartialEq, Debug)]
pub struct Error {
pos: Option<(Position, Position)>,
@ -151,7 +140,7 @@ impl Importer {
id: alias.clone(),
symbol: FunctionSymbol::Flat(compiled),
}
.at(0, 0, 0),
.start_end(pos.0, pos.1),
);
}
s => {
@ -178,7 +167,7 @@ impl Importer {
id: alias.clone(),
symbol: FunctionSymbol::Flat(compiled),
}
.at(0, 0, 0),
.start_end(pos.0, pos.1),
);
}
s => {
@ -214,10 +203,10 @@ impl Importer {
"main",
import.source.clone(),
)
.at(0, 0, 0),
.start_end(pos.0, pos.1),
),
}
.at(0, 0, 0),
.start_end(pos.0, pos.1),
);
}
Err(err) => {