fix tests
This commit is contained in:
parent
241447a09c
commit
aad6622488
8 changed files with 239 additions and 243 deletions
|
@ -249,9 +249,7 @@ impl<'ast> From<pest::Parameter<'ast>> for absy::ParameterNode<'ast> {
|
||||||
)
|
)
|
||||||
.span(param.id.span);
|
.span(param.id.span);
|
||||||
|
|
||||||
absy::Parameter::new(variable)
|
absy::Parameter::new(variable, is_private).span(param.span)
|
||||||
.is_private(is_private)
|
|
||||||
.span(param.span)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -970,7 +968,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn arguments() {
|
fn arguments() {
|
||||||
let source = "def main(private field a, bool b) -> field: return 42";
|
let source = "def main(private field a, bool mut b) -> field: return 42";
|
||||||
let ast = pest::generate_ast(source).unwrap();
|
let ast = pest::generate_ast(source).unwrap();
|
||||||
|
|
||||||
let expected: absy::Module = absy::Module {
|
let expected: absy::Module = absy::Module {
|
||||||
|
@ -980,19 +978,12 @@ mod tests {
|
||||||
absy::Function {
|
absy::Function {
|
||||||
arguments: vec![
|
arguments: vec![
|
||||||
absy::Parameter::private(
|
absy::Parameter::private(
|
||||||
absy::Variable::new(
|
absy::Variable::immutable("a", UnresolvedType::FieldElement.mock())
|
||||||
&source[23..24],
|
.into(),
|
||||||
UnresolvedType::FieldElement.mock(),
|
|
||||||
)
|
|
||||||
.into(),
|
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
absy::Parameter::public(
|
absy::Parameter::public(
|
||||||
absy::Variable::new(
|
absy::Variable::mutable("b", UnresolvedType::Boolean.mock()).into(),
|
||||||
&source[31..32],
|
|
||||||
UnresolvedType::Boolean.mock(),
|
|
||||||
)
|
|
||||||
.into(),
|
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
],
|
],
|
||||||
|
@ -1032,7 +1023,7 @@ mod tests {
|
||||||
symbol: absy::Symbol::Here(absy::SymbolDefinition::Function(
|
symbol: absy::Symbol::Here(absy::SymbolDefinition::Function(
|
||||||
absy::Function {
|
absy::Function {
|
||||||
arguments: vec![absy::Parameter::private(
|
arguments: vec![absy::Parameter::private(
|
||||||
absy::Variable::new("a", ty.clone().mock()).into(),
|
absy::Variable::new("a", ty.clone().mock(), false).into(),
|
||||||
)
|
)
|
||||||
.into()],
|
.into()],
|
||||||
statements: vec![absy::Statement::Return(
|
statements: vec![absy::Statement::Return(
|
||||||
|
|
|
@ -8,16 +8,16 @@ pub struct Parameter<'ast> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'ast> Parameter<'ast> {
|
impl<'ast> Parameter<'ast> {
|
||||||
pub fn new(v: VariableNode<'ast>) -> Self {
|
pub fn new(v: VariableNode<'ast>, is_private: bool) -> Self {
|
||||||
Parameter {
|
Parameter { id: v, is_private }
|
||||||
id: v,
|
|
||||||
is_private: true,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_private(mut self, is_private: bool) -> Self {
|
pub fn private(v: VariableNode<'ast>) -> Self {
|
||||||
self.is_private = is_private;
|
Self::new(v, true)
|
||||||
self
|
}
|
||||||
|
|
||||||
|
pub fn public(v: VariableNode<'ast>) -> Self {
|
||||||
|
Self::new(v, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,14 @@ impl<'ast> Variable<'ast> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn immutable<S: Into<&'ast str>>(id: S, t: UnresolvedTypeNode<'ast>) -> Self {
|
||||||
|
Self::new(id, t, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn mutable<S: Into<&'ast str>>(id: S, t: UnresolvedTypeNode<'ast>) -> Self {
|
||||||
|
Self::new(id, t, true)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_type(&self) -> &UnresolvedType<'ast> {
|
pub fn get_type(&self) -> &UnresolvedType<'ast> {
|
||||||
&self._type.value
|
&self._type.value
|
||||||
}
|
}
|
||||||
|
|
|
@ -716,13 +716,12 @@ impl<'ast, T: Field> Checker<'ast, T> {
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
);
|
);
|
||||||
self.insert_into_scope(Variable::new(
|
self.insert_into_scope(Variable::immutable(
|
||||||
CoreIdentifier::Constant(CanonicalConstantIdentifier::new(
|
CoreIdentifier::Constant(CanonicalConstantIdentifier::new(
|
||||||
declaration.id,
|
declaration.id,
|
||||||
module_id.into(),
|
module_id.into(),
|
||||||
)),
|
)),
|
||||||
c.get_type(),
|
c.get_type(),
|
||||||
false,
|
|
||||||
));
|
));
|
||||||
assert!(state
|
assert!(state
|
||||||
.constants
|
.constants
|
||||||
|
@ -908,10 +907,10 @@ impl<'ast, T: Field> Checker<'ast, T> {
|
||||||
id.clone(),
|
id.clone(),
|
||||||
TypedConstantSymbol::There(imported_id)
|
TypedConstantSymbol::There(imported_id)
|
||||||
).into());
|
).into());
|
||||||
self.insert_into_scope(Variable::new(CoreIdentifier::Constant(CanonicalConstantIdentifier::new(
|
self.insert_into_scope(Variable::immutable(CoreIdentifier::Constant(CanonicalConstantIdentifier::new(
|
||||||
declaration.id,
|
declaration.id,
|
||||||
module_id.into(),
|
module_id.into(),
|
||||||
)), crate::typed_absy::types::try_from_g_type(ty.clone()).unwrap(), false));
|
)), crate::typed_absy::types::try_from_g_type(ty.clone()).unwrap()));
|
||||||
|
|
||||||
state
|
state
|
||||||
.constants
|
.constants
|
||||||
|
@ -1137,7 +1136,7 @@ impl<'ast, T: Field> Checker<'ast, T> {
|
||||||
|
|
||||||
// for declaration signatures, generics cannot be ignored
|
// for declaration signatures, generics cannot be ignored
|
||||||
|
|
||||||
let v = Variable::new(generic.name(), Type::Uint(UBitwidth::B32), false);
|
let v = Variable::immutable(generic.name(), Type::Uint(UBitwidth::B32));
|
||||||
|
|
||||||
generics.0.insert(
|
generics.0.insert(
|
||||||
generic.clone(),
|
generic.clone(),
|
||||||
|
@ -3820,7 +3819,7 @@ mod tests {
|
||||||
.mock()];
|
.mock()];
|
||||||
|
|
||||||
let arguments = vec![absy::Parameter {
|
let arguments = vec![absy::Parameter {
|
||||||
id: absy::Variable::new("a", UnresolvedType::FieldElement.mock()).mock(),
|
id: absy::Variable::immutable("a", UnresolvedType::FieldElement.mock()).mock(),
|
||||||
is_private: true,
|
is_private: true,
|
||||||
}
|
}
|
||||||
.mock()];
|
.mock()];
|
||||||
|
@ -4023,7 +4022,7 @@ mod tests {
|
||||||
let mut f0 = function0();
|
let mut f0 = function0();
|
||||||
|
|
||||||
f0.value.arguments = vec![absy::Parameter::private(
|
f0.value.arguments = vec![absy::Parameter::private(
|
||||||
absy::Variable::new(
|
absy::Variable::immutable(
|
||||||
"a",
|
"a",
|
||||||
UnresolvedType::array(
|
UnresolvedType::array(
|
||||||
UnresolvedType::FieldElement.mock(),
|
UnresolvedType::FieldElement.mock(),
|
||||||
|
@ -4044,7 +4043,7 @@ mod tests {
|
||||||
|
|
||||||
let mut f1 = function0();
|
let mut f1 = function0();
|
||||||
f1.value.arguments = vec![absy::Parameter::private(
|
f1.value.arguments = vec![absy::Parameter::private(
|
||||||
absy::Variable::new(
|
absy::Variable::immutable(
|
||||||
"a",
|
"a",
|
||||||
UnresolvedType::array(
|
UnresolvedType::array(
|
||||||
UnresolvedType::FieldElement.mock(),
|
UnresolvedType::FieldElement.mock(),
|
||||||
|
@ -4132,7 +4131,7 @@ mod tests {
|
||||||
let mut foo = function0();
|
let mut foo = function0();
|
||||||
|
|
||||||
foo.value.arguments = vec![absy::Parameter::private(
|
foo.value.arguments = vec![absy::Parameter::private(
|
||||||
absy::Variable::new(
|
absy::Variable::immutable(
|
||||||
"a",
|
"a",
|
||||||
UnresolvedType::array(
|
UnresolvedType::array(
|
||||||
UnresolvedType::FieldElement.mock(),
|
UnresolvedType::FieldElement.mock(),
|
||||||
|
@ -4494,8 +4493,7 @@ mod tests {
|
||||||
// field a = b
|
// field a = b
|
||||||
// b undefined
|
// b undefined
|
||||||
let statement: StatementNode = Statement::Definition(
|
let statement: StatementNode = Statement::Definition(
|
||||||
absy::Variable::new("a", UnresolvedType::FieldElement.mock()).mock(),
|
absy::Variable::immutable("a", UnresolvedType::FieldElement.mock()).mock(),
|
||||||
false,
|
|
||||||
Expression::Identifier("b").mock(),
|
Expression::Identifier("b").mock(),
|
||||||
)
|
)
|
||||||
.mock();
|
.mock();
|
||||||
|
@ -4514,25 +4512,15 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn defined_variable_in_statement() {
|
fn defined_variable_in_statement() {
|
||||||
// a = b
|
// field a = b
|
||||||
// b defined
|
// b defined
|
||||||
let statement: StatementNode = Statement::Assignment(
|
let statement: StatementNode = Statement::Definition(
|
||||||
Assignee::Identifier("a").mock(),
|
absy::Variable::immutable("a", UnresolvedType::FieldElement.mock()).mock(),
|
||||||
Expression::Identifier("b").mock(),
|
Expression::Identifier("b").mock(),
|
||||||
)
|
)
|
||||||
.mock();
|
.mock();
|
||||||
|
|
||||||
let mut scope = Scope::default();
|
let mut scope = Scope::default();
|
||||||
scope.insert(
|
|
||||||
ScopedIdentifier {
|
|
||||||
id: CoreIdentifier::Source("a"),
|
|
||||||
level: 1,
|
|
||||||
},
|
|
||||||
IdentifierInfo {
|
|
||||||
ty: Type::FieldElement,
|
|
||||||
is_mutable: true,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
scope.insert(
|
scope.insert(
|
||||||
ScopedIdentifier {
|
ScopedIdentifier {
|
||||||
id: CoreIdentifier::Source("b"),
|
id: CoreIdentifier::Source("b"),
|
||||||
|
@ -4565,8 +4553,7 @@ mod tests {
|
||||||
let foo_args = vec![];
|
let foo_args = vec![];
|
||||||
let foo_statements = vec![
|
let foo_statements = vec![
|
||||||
Statement::Definition(
|
Statement::Definition(
|
||||||
absy::Variable::new("a", UnresolvedType::FieldElement.mock()).mock(),
|
absy::Variable::immutable("a", UnresolvedType::FieldElement.mock()).mock(),
|
||||||
false,
|
|
||||||
Expression::IntConstant(1usize.into()).mock(),
|
Expression::IntConstant(1usize.into()).mock(),
|
||||||
)
|
)
|
||||||
.mock(),
|
.mock(),
|
||||||
|
@ -4647,8 +4634,7 @@ mod tests {
|
||||||
let foo_args = vec![];
|
let foo_args = vec![];
|
||||||
let foo_statements = vec![
|
let foo_statements = vec![
|
||||||
Statement::Definition(
|
Statement::Definition(
|
||||||
absy::Variable::new("a", UnresolvedType::FieldElement.mock()).mock(),
|
absy::Variable::immutable("a", UnresolvedType::FieldElement.mock()).mock(),
|
||||||
false,
|
|
||||||
Expression::IntConstant(1usize.into()).mock(),
|
Expression::IntConstant(1usize.into()).mock(),
|
||||||
)
|
)
|
||||||
.mock(),
|
.mock(),
|
||||||
|
@ -4671,8 +4657,7 @@ mod tests {
|
||||||
let bar_args = vec![];
|
let bar_args = vec![];
|
||||||
let bar_statements = vec![
|
let bar_statements = vec![
|
||||||
Statement::Definition(
|
Statement::Definition(
|
||||||
absy::Variable::new("a", UnresolvedType::FieldElement.mock()).mock(),
|
absy::Variable::immutable("a", UnresolvedType::FieldElement.mock()).mock(),
|
||||||
false,
|
|
||||||
Expression::IntConstant(2usize.into()).mock(),
|
Expression::IntConstant(2usize.into()).mock(),
|
||||||
)
|
)
|
||||||
.mock(),
|
.mock(),
|
||||||
|
@ -4744,7 +4729,7 @@ mod tests {
|
||||||
// should fail
|
// should fail
|
||||||
let foo_statements: Vec<StatementNode> = vec![
|
let foo_statements: Vec<StatementNode> = vec![
|
||||||
Statement::For(
|
Statement::For(
|
||||||
absy::Variable::new("i", UnresolvedType::Uint(32).mock()).mock(),
|
absy::Variable::immutable("i", UnresolvedType::Uint(32).mock()).mock(),
|
||||||
Expression::IntConstant(0usize.into()).mock(),
|
Expression::IntConstant(0usize.into()).mock(),
|
||||||
Expression::IntConstant(10usize.into()).mock(),
|
Expression::IntConstant(10usize.into()).mock(),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -4790,15 +4775,14 @@ mod tests {
|
||||||
// should pass
|
// should pass
|
||||||
|
|
||||||
let for_statements = vec![Statement::Definition(
|
let for_statements = vec![Statement::Definition(
|
||||||
absy::Variable::new("a", UnresolvedType::Uint(32).mock()).mock(),
|
absy::Variable::immutable("a", UnresolvedType::Uint(32).mock()).mock(),
|
||||||
false,
|
|
||||||
Expression::Identifier("i").mock(),
|
Expression::Identifier("i").mock(),
|
||||||
)
|
)
|
||||||
.mock()];
|
.mock()];
|
||||||
|
|
||||||
let foo_statements = vec![
|
let foo_statements = vec![
|
||||||
Statement::For(
|
Statement::For(
|
||||||
absy::Variable::new("i", UnresolvedType::Uint(32).mock()).mock(),
|
absy::Variable::immutable("i", UnresolvedType::Uint(32).mock()).mock(),
|
||||||
Expression::IntConstant(0usize.into()).mock(),
|
Expression::IntConstant(0usize.into()).mock(),
|
||||||
Expression::IntConstant(10usize.into()).mock(),
|
Expression::IntConstant(10usize.into()).mock(),
|
||||||
for_statements,
|
for_statements,
|
||||||
|
@ -4863,7 +4847,7 @@ mod tests {
|
||||||
let bar_statements: Vec<StatementNode> = vec![
|
let bar_statements: Vec<StatementNode> = vec![
|
||||||
Statement::MultipleDefinition(
|
Statement::MultipleDefinition(
|
||||||
vec![
|
vec![
|
||||||
absy::Variable::new("a", UnresolvedType::FieldElement.mock())
|
absy::Variable::immutable("a", UnresolvedType::FieldElement.mock())
|
||||||
.mock()
|
.mock()
|
||||||
.into(),
|
.into(),
|
||||||
],
|
],
|
||||||
|
@ -4986,7 +4970,7 @@ mod tests {
|
||||||
let bar_statements: Vec<StatementNode> = vec![
|
let bar_statements: Vec<StatementNode> = vec![
|
||||||
Statement::MultipleDefinition(
|
Statement::MultipleDefinition(
|
||||||
vec![
|
vec![
|
||||||
absy::Variable::new("a", UnresolvedType::FieldElement.mock())
|
absy::Variable::immutable("a", UnresolvedType::FieldElement.mock())
|
||||||
.mock()
|
.mock()
|
||||||
.into(),
|
.into(),
|
||||||
],
|
],
|
||||||
|
@ -5048,7 +5032,7 @@ mod tests {
|
||||||
|
|
||||||
let foo = Function {
|
let foo = Function {
|
||||||
arguments: vec![crate::absy::Parameter {
|
arguments: vec![crate::absy::Parameter {
|
||||||
id: absy::Variable::new("x", UnresolvedType::FieldElement.mock()).mock(),
|
id: absy::Variable::immutable("x", UnresolvedType::FieldElement.mock()).mock(),
|
||||||
is_private: false,
|
is_private: false,
|
||||||
}
|
}
|
||||||
.mock()],
|
.mock()],
|
||||||
|
@ -5065,10 +5049,10 @@ mod tests {
|
||||||
let main_statements: Vec<StatementNode> = vec![
|
let main_statements: Vec<StatementNode> = vec![
|
||||||
Statement::MultipleDefinition(
|
Statement::MultipleDefinition(
|
||||||
vec![
|
vec![
|
||||||
absy::Variable::new("a", UnresolvedType::FieldElement.mock())
|
absy::Variable::immutable("a", UnresolvedType::FieldElement.mock())
|
||||||
.mock()
|
.mock()
|
||||||
.into(),
|
.into(),
|
||||||
absy::Variable::new("b", UnresolvedType::FieldElement.mock())
|
absy::Variable::immutable("b", UnresolvedType::FieldElement.mock())
|
||||||
.mock()
|
.mock()
|
||||||
.into(),
|
.into(),
|
||||||
],
|
],
|
||||||
|
@ -5254,7 +5238,7 @@ mod tests {
|
||||||
|
|
||||||
let main_statements: Vec<StatementNode> = vec![
|
let main_statements: Vec<StatementNode> = vec![
|
||||||
Statement::Definition(
|
Statement::Definition(
|
||||||
absy::Variable::new(
|
absy::Variable::mutable(
|
||||||
"a",
|
"a",
|
||||||
UnresolvedType::array(
|
UnresolvedType::array(
|
||||||
UnresolvedType::FieldElement.mock(),
|
UnresolvedType::FieldElement.mock(),
|
||||||
|
@ -5263,7 +5247,6 @@ mod tests {
|
||||||
.mock(),
|
.mock(),
|
||||||
)
|
)
|
||||||
.mock(),
|
.mock(),
|
||||||
true,
|
|
||||||
Expression::InlineArray(vec![absy::SpreadOrExpression::Expression(
|
Expression::InlineArray(vec![absy::SpreadOrExpression::Expression(
|
||||||
Expression::IntConstant(0usize.into()).mock(),
|
Expression::IntConstant(0usize.into()).mock(),
|
||||||
)])
|
)])
|
||||||
|
@ -5425,10 +5408,10 @@ mod tests {
|
||||||
let bar_statements: Vec<StatementNode> = vec![
|
let bar_statements: Vec<StatementNode> = vec![
|
||||||
Statement::MultipleDefinition(
|
Statement::MultipleDefinition(
|
||||||
vec![
|
vec![
|
||||||
absy::Variable::new("a", UnresolvedType::FieldElement.mock())
|
absy::Variable::immutable("a", UnresolvedType::FieldElement.mock())
|
||||||
.mock()
|
.mock()
|
||||||
.into(),
|
.into(),
|
||||||
absy::Variable::new("b", UnresolvedType::FieldElement.mock())
|
absy::Variable::immutable("b", UnresolvedType::FieldElement.mock())
|
||||||
.mock()
|
.mock()
|
||||||
.into(),
|
.into(),
|
||||||
],
|
],
|
||||||
|
@ -5523,11 +5506,11 @@ mod tests {
|
||||||
let mut f = function0();
|
let mut f = function0();
|
||||||
f.value.arguments = vec![
|
f.value.arguments = vec![
|
||||||
absy::Parameter::private(
|
absy::Parameter::private(
|
||||||
absy::Variable::new("a", UnresolvedType::FieldElement.mock()).mock(),
|
absy::Variable::immutable("a", UnresolvedType::FieldElement.mock()).mock(),
|
||||||
)
|
)
|
||||||
.mock(),
|
.mock(),
|
||||||
absy::Parameter::private(
|
absy::Parameter::private(
|
||||||
absy::Variable::new("a", UnresolvedType::Boolean.mock()).mock(),
|
absy::Variable::immutable("a", UnresolvedType::Boolean.mock()).mock(),
|
||||||
)
|
)
|
||||||
.mock(),
|
.mock(),
|
||||||
];
|
];
|
||||||
|
@ -5566,7 +5549,7 @@ mod tests {
|
||||||
.mock()];
|
.mock()];
|
||||||
|
|
||||||
let main1_arguments = vec![crate::absy::Parameter {
|
let main1_arguments = vec![crate::absy::Parameter {
|
||||||
id: absy::Variable::new("a", UnresolvedType::FieldElement.mock()).mock(),
|
id: absy::Variable::immutable("a", UnresolvedType::FieldElement.mock()).mock(),
|
||||||
is_private: false,
|
is_private: false,
|
||||||
}
|
}
|
||||||
.mock()];
|
.mock()];
|
||||||
|
@ -5644,7 +5627,7 @@ mod tests {
|
||||||
// let mut checker: Checker<Bn128Field> = Checker::default();
|
// let mut checker: Checker<Bn128Field> = Checker::default();
|
||||||
// let _: Result<TypedStatement<Bn128Field>, Vec<ErrorInner>> = checker.check_statement(
|
// let _: Result<TypedStatement<Bn128Field>, Vec<ErrorInner>> = checker.check_statement(
|
||||||
// Statement::Definition(
|
// Statement::Definition(
|
||||||
// absy::Variable::new("a", UnresolvedType::FieldElement.mock()).mock(),
|
// absy::Variable::immutable("a", UnresolvedType::FieldElement.mock()).mock(),
|
||||||
// false,
|
// false,
|
||||||
// )
|
// )
|
||||||
// .mock(),
|
// .mock(),
|
||||||
|
@ -5654,7 +5637,7 @@ mod tests {
|
||||||
// let s2_checked: Result<TypedStatement<Bn128Field>, Vec<ErrorInner>> = checker
|
// let s2_checked: Result<TypedStatement<Bn128Field>, Vec<ErrorInner>> = checker
|
||||||
// .check_statement(
|
// .check_statement(
|
||||||
// Statement::Definition(
|
// Statement::Definition(
|
||||||
// absy::Variable::new("a", UnresolvedType::FieldElement.mock()).mock(),
|
// absy::Variable::immutable("a", UnresolvedType::FieldElement.mock()).mock(),
|
||||||
// false,
|
// false,
|
||||||
// )
|
// )
|
||||||
// .mock(),
|
// .mock(),
|
||||||
|
@ -5680,7 +5663,7 @@ mod tests {
|
||||||
// let mut checker: Checker<Bn128Field> = Checker::default();
|
// let mut checker: Checker<Bn128Field> = Checker::default();
|
||||||
// let _: Result<TypedStatement<Bn128Field>, Vec<ErrorInner>> = checker.check_statement(
|
// let _: Result<TypedStatement<Bn128Field>, Vec<ErrorInner>> = checker.check_statement(
|
||||||
// Statement::Definition(
|
// Statement::Definition(
|
||||||
// absy::Variable::new("a", UnresolvedType::FieldElement.mock()).mock(),
|
// absy::Variable::immutable("a", UnresolvedType::FieldElement.mock()).mock(),
|
||||||
// false,
|
// false,
|
||||||
// )
|
// )
|
||||||
// .mock(),
|
// .mock(),
|
||||||
|
@ -5690,7 +5673,7 @@ mod tests {
|
||||||
// let s2_checked: Result<TypedStatement<Bn128Field>, Vec<ErrorInner>> = checker
|
// let s2_checked: Result<TypedStatement<Bn128Field>, Vec<ErrorInner>> = checker
|
||||||
// .check_statement(
|
// .check_statement(
|
||||||
// Statement::Definition(
|
// Statement::Definition(
|
||||||
// absy::Variable::new("a", UnresolvedType::Boolean.mock()).mock(),
|
// absy::Variable::immutable("a", UnresolvedType::Boolean.mock()).mock(),
|
||||||
// false,
|
// false,
|
||||||
// )
|
// )
|
||||||
// .mock(),
|
// .mock(),
|
||||||
|
@ -6445,11 +6428,7 @@ mod tests {
|
||||||
let mut foo_field = function0();
|
let mut foo_field = function0();
|
||||||
|
|
||||||
foo_field.value.arguments = vec![absy::Parameter::private(
|
foo_field.value.arguments = vec![absy::Parameter::private(
|
||||||
absy::Variable {
|
absy::Variable::immutable("a", UnresolvedType::FieldElement.mock()).mock(),
|
||||||
id: "a",
|
|
||||||
_type: UnresolvedType::FieldElement.mock(),
|
|
||||||
}
|
|
||||||
.mock(),
|
|
||||||
)
|
)
|
||||||
.mock()];
|
.mock()];
|
||||||
foo_field.value.statements = vec![Statement::Return(
|
foo_field.value.statements = vec![Statement::Return(
|
||||||
|
@ -6466,11 +6445,7 @@ mod tests {
|
||||||
let mut foo_u32 = function0();
|
let mut foo_u32 = function0();
|
||||||
|
|
||||||
foo_u32.value.arguments = vec![absy::Parameter::private(
|
foo_u32.value.arguments = vec![absy::Parameter::private(
|
||||||
absy::Variable {
|
absy::Variable::immutable("a", UnresolvedType::Uint(32).mock()).mock(),
|
||||||
id: "a",
|
|
||||||
_type: UnresolvedType::Uint(32).mock(),
|
|
||||||
}
|
|
||||||
.mock(),
|
|
||||||
)
|
)
|
||||||
.mock()];
|
.mock()];
|
||||||
foo_u32.value.statements = vec![Statement::Return(
|
foo_u32.value.statements = vec![Statement::Return(
|
||||||
|
@ -6540,136 +6515,153 @@ mod tests {
|
||||||
mod assignee {
|
mod assignee {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn identifier() {
|
fn identifier() {
|
||||||
// // a = 42
|
// a = 42
|
||||||
// let a = Assignee::Identifier("a").mock();
|
let a = Assignee::Identifier("a").mock();
|
||||||
|
|
||||||
// let mut checker: Checker<Bn128Field> = Checker::default();
|
let mut checker: Checker<Bn128Field> = Checker::default();
|
||||||
// checker.enter_scope();
|
checker.enter_scope();
|
||||||
|
|
||||||
// checker
|
checker
|
||||||
// .check_statement(
|
.check_statement(
|
||||||
// Statement::Definition(
|
Statement::Definition(
|
||||||
// absy::Variable::new("a", UnresolvedType::FieldElement.mock()).mock(),
|
absy::Variable::mutable("a", UnresolvedType::FieldElement.mock()).mock(),
|
||||||
// false,
|
Expression::FieldConstant(42u32.into()).mock(),
|
||||||
// )
|
)
|
||||||
// .mock(),
|
.mock(),
|
||||||
// &*MODULE_ID,
|
&*MODULE_ID,
|
||||||
// &TypeMap::new(),
|
&TypeMap::new(),
|
||||||
// )
|
)
|
||||||
// .unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// assert_eq!(
|
assert_eq!(
|
||||||
// checker.check_assignee(a, &*MODULE_ID, &TypeMap::new()),
|
checker.check_assignee(a, &*MODULE_ID, &TypeMap::new()),
|
||||||
// Ok(TypedAssignee::Identifier(
|
Ok(TypedAssignee::Identifier(typed_absy::Variable::new(
|
||||||
// typed_absy::Variable::field_element("a")
|
"a",
|
||||||
// ))
|
Type::FieldElement,
|
||||||
// );
|
true
|
||||||
// }
|
)))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn array_element() {
|
fn array_element() {
|
||||||
// // field[33] a
|
// field[3] a = [1, 2, 3]
|
||||||
// // a[2] = 42
|
// a[2] = 42
|
||||||
// let a = Assignee::Select(
|
let a = Assignee::Select(
|
||||||
// box Assignee::Identifier("a").mock(),
|
box Assignee::Identifier("a").mock(),
|
||||||
// box RangeOrExpression::Expression(Expression::IntConstant(2usize.into()).mock()),
|
box RangeOrExpression::Expression(Expression::IntConstant(2usize.into()).mock()),
|
||||||
// )
|
)
|
||||||
// .mock();
|
.mock();
|
||||||
|
|
||||||
// let mut checker: Checker<Bn128Field> = Checker::default();
|
let mut checker: Checker<Bn128Field> = Checker::default();
|
||||||
// checker.enter_scope();
|
checker.enter_scope();
|
||||||
|
|
||||||
// checker
|
checker
|
||||||
// .check_statement(
|
.check_statement(
|
||||||
// Statement::Definition(
|
Statement::Definition(
|
||||||
// absy::Variable::new(
|
absy::Variable::mutable(
|
||||||
// "a",
|
"a",
|
||||||
// UnresolvedType::array(
|
UnresolvedType::array(
|
||||||
// UnresolvedType::FieldElement.mock(),
|
UnresolvedType::FieldElement.mock(),
|
||||||
// Expression::IntConstant(33usize.into()).mock(),
|
Expression::IntConstant(3usize.into()).mock(),
|
||||||
// )
|
)
|
||||||
// .mock(),
|
.mock(),
|
||||||
// )
|
)
|
||||||
// .mock(),
|
.mock(),
|
||||||
// false,
|
Expression::InlineArray(
|
||||||
// )
|
(1..4)
|
||||||
// .mock(),
|
.map(|i| {
|
||||||
// &*MODULE_ID,
|
Expression::FieldConstant(BigUint::from(i as u32))
|
||||||
// &TypeMap::new(),
|
.mock()
|
||||||
// )
|
.into()
|
||||||
// .unwrap();
|
})
|
||||||
|
.collect(),
|
||||||
|
)
|
||||||
|
.mock(),
|
||||||
|
)
|
||||||
|
.mock(),
|
||||||
|
&*MODULE_ID,
|
||||||
|
&TypeMap::new(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// assert_eq!(
|
assert_eq!(
|
||||||
// checker.check_assignee(a, &*MODULE_ID, &TypeMap::new()),
|
checker.check_assignee(a, &*MODULE_ID, &TypeMap::new()),
|
||||||
// Ok(TypedAssignee::Select(
|
Ok(TypedAssignee::Select(
|
||||||
// box TypedAssignee::Identifier(typed_absy::Variable::field_array(
|
box TypedAssignee::Identifier(typed_absy::Variable::new(
|
||||||
// "a",
|
"a",
|
||||||
// 33u32.into()
|
Type::array((Type::FieldElement, 3u32)),
|
||||||
// )),
|
true,
|
||||||
// box 2u32.into()
|
)),
|
||||||
// ))
|
box 2u32.into()
|
||||||
// );
|
))
|
||||||
// }
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn array_of_array_element() {
|
fn array_of_array_element() {
|
||||||
// // field[33][42] a
|
// field[1][1] a = [[1]]
|
||||||
// // a[1][2]
|
// a[0][0]
|
||||||
// let a: AssigneeNode = Assignee::Select(
|
let a: AssigneeNode = Assignee::Select(
|
||||||
// box Assignee::Select(
|
box Assignee::Select(
|
||||||
// box Assignee::Identifier("a").mock(),
|
box Assignee::Identifier("a").mock(),
|
||||||
// box RangeOrExpression::Expression(
|
box RangeOrExpression::Expression(
|
||||||
// Expression::IntConstant(1usize.into()).mock(),
|
Expression::IntConstant(0usize.into()).mock(),
|
||||||
// ),
|
),
|
||||||
// )
|
)
|
||||||
// .mock(),
|
.mock(),
|
||||||
// box RangeOrExpression::Expression(Expression::IntConstant(2usize.into()).mock()),
|
box RangeOrExpression::Expression(Expression::IntConstant(0usize.into()).mock()),
|
||||||
// )
|
)
|
||||||
// .mock();
|
.mock();
|
||||||
|
|
||||||
// let mut checker: Checker<Bn128Field> = Checker::default();
|
let mut checker: Checker<Bn128Field> = Checker::default();
|
||||||
// checker.enter_scope();
|
checker.enter_scope();
|
||||||
|
|
||||||
// checker
|
checker
|
||||||
// .check_statement(
|
.check_statement(
|
||||||
// Statement::Definition(
|
Statement::Definition(
|
||||||
// absy::Variable::new(
|
absy::Variable::mutable(
|
||||||
// "a",
|
"a",
|
||||||
// UnresolvedType::array(
|
UnresolvedType::array(
|
||||||
// UnresolvedType::array(
|
UnresolvedType::array(
|
||||||
// UnresolvedType::FieldElement.mock(),
|
UnresolvedType::FieldElement.mock(),
|
||||||
// Expression::IntConstant(33usize.into()).mock(),
|
Expression::IntConstant(1usize.into()).mock(),
|
||||||
// )
|
)
|
||||||
// .mock(),
|
.mock(),
|
||||||
// Expression::IntConstant(42usize.into()).mock(),
|
Expression::IntConstant(1usize.into()).mock(),
|
||||||
// )
|
)
|
||||||
// .mock(),
|
.mock(),
|
||||||
// )
|
)
|
||||||
// .mock(),
|
.mock(),
|
||||||
// false,
|
Expression::InlineArray(vec![Expression::InlineArray(vec![
|
||||||
// )
|
Expression::IntConstant(1usize.into()).mock().into(),
|
||||||
// .mock(),
|
])
|
||||||
// &*MODULE_ID,
|
.mock()
|
||||||
// &TypeMap::new(),
|
.into()])
|
||||||
// )
|
.mock(),
|
||||||
// .unwrap();
|
)
|
||||||
|
.mock(),
|
||||||
|
&*MODULE_ID,
|
||||||
|
&TypeMap::new(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// assert_eq!(
|
assert_eq!(
|
||||||
// checker.check_assignee(a, &*MODULE_ID, &TypeMap::new()),
|
checker.check_assignee(a, &*MODULE_ID, &TypeMap::new()),
|
||||||
// Ok(TypedAssignee::Select(
|
Ok(TypedAssignee::Select(
|
||||||
// box TypedAssignee::Select(
|
box TypedAssignee::Select(
|
||||||
// box TypedAssignee::Identifier(typed_absy::Variable::array(
|
box TypedAssignee::Identifier(typed_absy::Variable::new(
|
||||||
// "a",
|
"a",
|
||||||
// Type::array((Type::FieldElement, 33u32)),
|
Type::array((Type::array((Type::FieldElement, 1u32)), 1u32)),
|
||||||
// 42u32,
|
true,
|
||||||
// )),
|
)),
|
||||||
// box 1u32.into()
|
box 0u32.into()
|
||||||
// ),
|
),
|
||||||
// box 2u32.into()
|
box 0u32.into()
|
||||||
// ))
|
))
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::typed_absy::{
|
use crate::typed_absy::{
|
||||||
folder::*, BlockExpression, BooleanExpression, Conditional, ConditionalExpression,
|
folder::*, BlockExpression, BooleanExpression, Conditional, ConditionalExpression,
|
||||||
ConditionalOrExpression, CoreIdentifier, DeclarationType, Expr, Identifier, Type, TypedProgram,
|
ConditionalOrExpression, CoreIdentifier, Expr, Identifier, Type, TypedProgram, TypedStatement,
|
||||||
TypedStatement, Variable,
|
Variable,
|
||||||
};
|
};
|
||||||
use zokrates_field::Field;
|
use zokrates_field::Field;
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ impl<'ast, T: Field> Folder<'ast, T> for ConditionRedefiner<'ast, T> {
|
||||||
condition => {
|
condition => {
|
||||||
let condition_id = Identifier::from(CoreIdentifier::Condition(self.index));
|
let condition_id = Identifier::from(CoreIdentifier::Condition(self.index));
|
||||||
self.buffer.push(TypedStatement::Definition(
|
self.buffer.push(TypedStatement::Definition(
|
||||||
Variable::new(condition_id.clone(), Type::Boolean, false).into(),
|
Variable::immutable(condition_id.clone(), Type::Boolean).into(),
|
||||||
condition.into(),
|
condition.into(),
|
||||||
));
|
));
|
||||||
self.index += 1;
|
self.index += 1;
|
||||||
|
@ -164,7 +164,7 @@ mod tests {
|
||||||
let expected = vec![
|
let expected = vec![
|
||||||
// define condition
|
// define condition
|
||||||
TypedStatement::Definition(
|
TypedStatement::Definition(
|
||||||
Variable::new(CoreIdentifier::Condition(0), Type::Boolean).into(),
|
Variable::immutable(CoreIdentifier::Condition(0), Type::Boolean).into(),
|
||||||
condition.into(),
|
condition.into(),
|
||||||
),
|
),
|
||||||
// rewrite statement
|
// rewrite statement
|
||||||
|
@ -224,11 +224,11 @@ mod tests {
|
||||||
let expected = vec![
|
let expected = vec![
|
||||||
// define conditions
|
// define conditions
|
||||||
TypedStatement::Definition(
|
TypedStatement::Definition(
|
||||||
Variable::new(CoreIdentifier::Condition(0), Type::Boolean).into(),
|
Variable::immutable(CoreIdentifier::Condition(0), Type::Boolean).into(),
|
||||||
condition_0.into(),
|
condition_0.into(),
|
||||||
),
|
),
|
||||||
TypedStatement::Definition(
|
TypedStatement::Definition(
|
||||||
Variable::new(CoreIdentifier::Condition(1), Type::Boolean).into(),
|
Variable::immutable(CoreIdentifier::Condition(1), Type::Boolean).into(),
|
||||||
condition_1.into(),
|
condition_1.into(),
|
||||||
),
|
),
|
||||||
// rewrite statement
|
// rewrite statement
|
||||||
|
@ -332,7 +332,7 @@ mod tests {
|
||||||
let expected = vec![
|
let expected = vec![
|
||||||
// define conditions
|
// define conditions
|
||||||
TypedStatement::Definition(
|
TypedStatement::Definition(
|
||||||
Variable::new(CoreIdentifier::Condition(0), Type::Boolean).into(),
|
Variable::immutable(CoreIdentifier::Condition(0), Type::Boolean).into(),
|
||||||
condition_0.into(),
|
condition_0.into(),
|
||||||
),
|
),
|
||||||
// rewrite statement
|
// rewrite statement
|
||||||
|
@ -347,7 +347,8 @@ mod tests {
|
||||||
FieldElementExpression::Number(Bn128Field::from(1)).into(),
|
FieldElementExpression::Number(Bn128Field::from(1)).into(),
|
||||||
),
|
),
|
||||||
TypedStatement::Definition(
|
TypedStatement::Definition(
|
||||||
Variable::new(CoreIdentifier::Condition(1), Type::Boolean).into(),
|
Variable::immutable(CoreIdentifier::Condition(1), Type::Boolean)
|
||||||
|
.into(),
|
||||||
condition_1.into(),
|
condition_1.into(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -365,7 +366,8 @@ mod tests {
|
||||||
FieldElementExpression::Number(Bn128Field::from(2)).into(),
|
FieldElementExpression::Number(Bn128Field::from(2)).into(),
|
||||||
),
|
),
|
||||||
TypedStatement::Definition(
|
TypedStatement::Definition(
|
||||||
Variable::new(CoreIdentifier::Condition(2), Type::Boolean).into(),
|
Variable::immutable(CoreIdentifier::Condition(2), Type::Boolean)
|
||||||
|
.into(),
|
||||||
condition_2.into(),
|
condition_2.into(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
|
@ -200,7 +200,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn detect_non_constant_bound() {
|
fn detect_non_constant_bound() {
|
||||||
let loops: Vec<TypedStatement<Bn128Field>> = vec![TypedStatement::For(
|
let loops: Vec<TypedStatement<Bn128Field>> = vec![TypedStatement::For(
|
||||||
Variable::uint("i", UBitwidth::B32),
|
Variable::new("i", Type::Uint(UBitwidth::B32), false),
|
||||||
UExpressionInner::Identifier("i".into()).annotate(UBitwidth::B32),
|
UExpressionInner::Identifier("i".into()).annotate(UBitwidth::B32),
|
||||||
2u32.into(),
|
2u32.into(),
|
||||||
vec![],
|
vec![],
|
||||||
|
@ -464,7 +464,7 @@ mod tests {
|
||||||
let array_of_array_ty = Type::array((Type::array((Type::FieldElement, 2u32)), 2u32));
|
let array_of_array_ty = Type::array((Type::array((Type::FieldElement, 2u32)), 2u32));
|
||||||
|
|
||||||
let s = TypedStatement::Definition(
|
let s = TypedStatement::Definition(
|
||||||
TypedAssignee::Identifier(Variable::new("a", array_of_array_ty.clone())),
|
TypedAssignee::Identifier(Variable::new("a", array_of_array_ty.clone(), true)),
|
||||||
ArrayExpressionInner::Value(
|
ArrayExpressionInner::Value(
|
||||||
vec![
|
vec![
|
||||||
ArrayExpressionInner::Value(
|
ArrayExpressionInner::Value(
|
||||||
|
@ -498,6 +498,7 @@ mod tests {
|
||||||
TypedAssignee::Identifier(Variable::new(
|
TypedAssignee::Identifier(Variable::new(
|
||||||
Identifier::from("a").version(0),
|
Identifier::from("a").version(0),
|
||||||
array_of_array_ty.clone(),
|
array_of_array_ty.clone(),
|
||||||
|
true,
|
||||||
)),
|
)),
|
||||||
ArrayExpressionInner::Value(
|
ArrayExpressionInner::Value(
|
||||||
vec![
|
vec![
|
||||||
|
@ -529,7 +530,11 @@ mod tests {
|
||||||
|
|
||||||
let s: TypedStatement<Bn128Field> = TypedStatement::Definition(
|
let s: TypedStatement<Bn128Field> = TypedStatement::Definition(
|
||||||
TypedAssignee::Select(
|
TypedAssignee::Select(
|
||||||
box TypedAssignee::Identifier(Variable::new("a", array_of_array_ty.clone())),
|
box TypedAssignee::Identifier(Variable::new(
|
||||||
|
"a",
|
||||||
|
array_of_array_ty.clone(),
|
||||||
|
true,
|
||||||
|
)),
|
||||||
box UExpression::from(1u32),
|
box UExpression::from(1u32),
|
||||||
),
|
),
|
||||||
ArrayExpressionInner::Value(
|
ArrayExpressionInner::Value(
|
||||||
|
|
|
@ -33,6 +33,7 @@ mod tests {
|
||||||
use crate::typed_absy::types::{
|
use crate::typed_absy::types::{
|
||||||
ConcreteArrayType, ConcreteFunctionKey, ConcreteStructMember, ConcreteStructType, UBitwidth,
|
ConcreteArrayType, ConcreteFunctionKey, ConcreteStructMember, ConcreteStructType, UBitwidth,
|
||||||
};
|
};
|
||||||
|
use crate::typed_absy::DeclarationType;
|
||||||
use crate::typed_absy::{
|
use crate::typed_absy::{
|
||||||
parameter::DeclarationParameter, variable::DeclarationVariable, ConcreteTupleType,
|
parameter::DeclarationParameter, variable::DeclarationVariable, ConcreteTupleType,
|
||||||
ConcreteType, TypedFunction, TypedFunctionSymbol, TypedFunctionSymbolDeclaration,
|
ConcreteType, TypedFunction, TypedFunctionSymbol, TypedFunctionSymbolDeclaration,
|
||||||
|
@ -48,11 +49,11 @@ mod tests {
|
||||||
TypedFunctionSymbol::Here(TypedFunction {
|
TypedFunctionSymbol::Here(TypedFunction {
|
||||||
arguments: vec![
|
arguments: vec![
|
||||||
DeclarationParameter {
|
DeclarationParameter {
|
||||||
id: DeclarationVariable::field_element("a"),
|
id: DeclarationVariable::new("a", DeclarationType::FieldElement, true),
|
||||||
private: true,
|
private: true,
|
||||||
},
|
},
|
||||||
DeclarationParameter {
|
DeclarationParameter {
|
||||||
id: DeclarationVariable::boolean("b"),
|
id: DeclarationVariable::new("b", DeclarationType::Boolean, false),
|
||||||
private: false,
|
private: false,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
@ -5,7 +5,7 @@ use crate::typed_absy::UExpression;
|
||||||
use crate::typed_absy::{TryFrom, TryInto};
|
use crate::typed_absy::{TryFrom, TryInto};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Hash, Eq, PartialOrd, Ord)]
|
#[derive(Clone, PartialEq, Hash, Eq, PartialOrd, Ord, Debug)]
|
||||||
pub struct GVariable<'ast, S> {
|
pub struct GVariable<'ast, S> {
|
||||||
pub id: Identifier<'ast>,
|
pub id: Identifier<'ast>,
|
||||||
pub _type: GType<S>,
|
pub _type: GType<S>,
|
||||||
|
@ -55,30 +55,33 @@ pub fn try_from_g_variable<T: TryInto<U>, U>(
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'ast, S: Clone> GVariable<'ast, S> {
|
impl<'ast, S: Clone> GVariable<'ast, S> {
|
||||||
// pub fn field_element<I: Into<Identifier<'ast>>>(id: I) -> Self {
|
pub fn field_element<I: Into<Identifier<'ast>>>(id: I) -> Self {
|
||||||
// Self::new(id, GType::FieldElement)
|
Self::immutable(id, GType::FieldElement)
|
||||||
// }
|
}
|
||||||
|
|
||||||
// pub fn boolean<I: Into<Identifier<'ast>>>(id: I) -> Self {
|
pub fn boolean<I: Into<Identifier<'ast>>>(id: I) -> Self {
|
||||||
// Self::new(id, GType::Boolean)
|
Self::immutable(id, GType::Boolean)
|
||||||
// }
|
}
|
||||||
|
|
||||||
// pub fn uint<I: Into<Identifier<'ast>>, W: Into<UBitwidth>>(id: I, bitwidth: W) -> Self {
|
pub fn uint<I: Into<Identifier<'ast>>, W: Into<UBitwidth>>(id: I, bitwidth: W) -> Self {
|
||||||
// Self::new(id, GType::uint(bitwidth))
|
Self::immutable(id, GType::uint(bitwidth))
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[cfg(test)]
|
pub fn array<I: Into<Identifier<'ast>>, U: Into<S>>(id: I, ty: GType<S>, size: U) -> Self {
|
||||||
// pub fn field_array<I: Into<Identifier<'ast>>>(id: I, size: S) -> Self {
|
Self::immutable(id, GType::array((ty, size.into())))
|
||||||
// Self::array(id, GType::FieldElement, size)
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn array<I: Into<Identifier<'ast>>, U: Into<S>>(id: I, ty: GType<S>, size: U) -> Self {
|
pub fn struc<I: Into<Identifier<'ast>>>(id: I, ty: GStructType<S>) -> Self {
|
||||||
// Self::new(id, GType::array((ty, size.into())))
|
Self::immutable(id, GType::Struct(ty))
|
||||||
// }
|
}
|
||||||
|
|
||||||
// pub fn struc<I: Into<Identifier<'ast>>>(id: I, ty: GStructType<S>) -> Self {
|
pub fn immutable<I: Into<Identifier<'ast>>>(id: I, _type: GType<S>) -> Self {
|
||||||
// Self::new(id, GType::Struct(ty))
|
Self::new(id, _type, false)
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
pub fn mutable<I: Into<Identifier<'ast>>>(id: I, _type: GType<S>) -> Self {
|
||||||
|
Self::new(id, _type, true)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn new<I: Into<Identifier<'ast>>>(id: I, _type: GType<S>, is_mutable: bool) -> Self {
|
pub fn new<I: Into<Identifier<'ast>>>(id: I, _type: GType<S>, is_mutable: bool) -> Self {
|
||||||
GVariable {
|
GVariable {
|
||||||
|
@ -98,9 +101,3 @@ impl<'ast, S: fmt::Display> fmt::Display for GVariable<'ast, S> {
|
||||||
write!(f, "{} {}", self._type, self.id,)
|
write!(f, "{} {}", self._type, self.id,)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'ast, S: fmt::Debug> fmt::Debug for GVariable<'ast, S> {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
write!(f, "Variable(type: {:?}, id: {:?})", self._type, self.id,)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue