mirror of
https://github.com/AleoHQ/leo.git
synced 2024-12-24 18:12:28 +03:00
second header pass for circuit members
This commit is contained in:
parent
696825eb6a
commit
99db18167a
@ -53,7 +53,7 @@ impl<'a> Node for Circuit<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Circuit<'a> {
|
impl<'a> Circuit<'a> {
|
||||||
pub(super) fn init(scope: &'a Scope<'a>, value: &leo_ast::Circuit) -> Result<&'a Circuit<'a>, AsgConvertError> {
|
pub(super) fn init(scope: &'a Scope<'a>, value: &leo_ast::Circuit) -> &'a Circuit<'a> {
|
||||||
let new_scope = scope.make_subscope();
|
let new_scope = scope.make_subscope();
|
||||||
|
|
||||||
let circuit = scope.context.alloc_circuit(Circuit {
|
let circuit = scope.context.alloc_circuit(Circuit {
|
||||||
@ -66,6 +66,19 @@ impl<'a> Circuit<'a> {
|
|||||||
});
|
});
|
||||||
new_scope.circuit_self.replace(Some(circuit));
|
new_scope.circuit_self.replace(Some(circuit));
|
||||||
|
|
||||||
|
circuit
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) fn init_member(
|
||||||
|
scope: &'a Scope<'a>,
|
||||||
|
value: &leo_ast::Circuit,
|
||||||
|
) -> Result<&'a Circuit<'a>, AsgConvertError> {
|
||||||
|
let new_scope = scope.make_subscope();
|
||||||
|
let circuits = scope.circuits.borrow();
|
||||||
|
|
||||||
|
let circuit = circuits.get(&value.circuit_name.name).unwrap();
|
||||||
|
new_scope.circuit_self.replace(Some(circuit));
|
||||||
|
|
||||||
let mut members = circuit.members.borrow_mut();
|
let mut members = circuit.members.borrow_mut();
|
||||||
for member in value.members.iter() {
|
for member in value.members.iter() {
|
||||||
match member {
|
match member {
|
||||||
|
@ -238,7 +238,15 @@ impl<'a> Program<'a> {
|
|||||||
// Prepare header-like scope entries.
|
// Prepare header-like scope entries.
|
||||||
for (name, circuit) in program.circuits.iter() {
|
for (name, circuit) in program.circuits.iter() {
|
||||||
assert_eq!(name.name, circuit.circuit_name.name);
|
assert_eq!(name.name, circuit.circuit_name.name);
|
||||||
let asg_circuit = Circuit::init(scope, circuit)?;
|
let asg_circuit = Circuit::init(scope, circuit);
|
||||||
|
|
||||||
|
scope.circuits.borrow_mut().insert(name.name.clone(), asg_circuit);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Second pass for circuit members.
|
||||||
|
for (name, circuit) in program.circuits.iter() {
|
||||||
|
assert_eq!(name.name, circuit.circuit_name.name);
|
||||||
|
let asg_circuit = Circuit::init_member(scope, circuit)?;
|
||||||
|
|
||||||
scope.circuits.borrow_mut().insert(name.name.clone(), asg_circuit);
|
scope.circuits.borrow_mut().insert(name.name.clone(), asg_circuit);
|
||||||
}
|
}
|
||||||
|
@ -194,26 +194,18 @@ impl<'a> Scope<'a> {
|
|||||||
.map(|x| self.resolve_ast_type(x))
|
.map(|x| self.resolve_ast_type(x))
|
||||||
.collect::<Result<Vec<_>, AsgConvertError>>()?,
|
.collect::<Result<Vec<_>, AsgConvertError>>()?,
|
||||||
),
|
),
|
||||||
|
Circuit(name) if name.name == "Self" => Type::Circuit(
|
||||||
|
self.resolve_circuit_self()
|
||||||
|
.ok_or_else(|| AsgConvertError::unresolved_circuit(&name.name, &name.span))?,
|
||||||
|
),
|
||||||
SelfType => Type::Circuit(
|
SelfType => Type::Circuit(
|
||||||
self.resolve_circuit_self()
|
self.resolve_circuit_self()
|
||||||
.ok_or_else(AsgConvertError::reference_self_outside_circuit)?,
|
.ok_or_else(AsgConvertError::reference_self_outside_circuit)?,
|
||||||
),
|
),
|
||||||
Circuit(name) => {
|
Circuit(name) => Type::Circuit(
|
||||||
// match current_circuit_name {
|
|
||||||
// Some(cname) if name.name == cname.name => {
|
|
||||||
// return Ok(Type::Circuit(
|
|
||||||
// self.resolve_circuit_self()
|
|
||||||
// .ok_or_else(|| AsgConvertError::unresolved_circuit(&name.name, &name.span))?,
|
|
||||||
// ));
|
|
||||||
// }
|
|
||||||
// _ => {}
|
|
||||||
// }
|
|
||||||
|
|
||||||
Type::Circuit(
|
|
||||||
self.resolve_circuit(&name.name)
|
self.resolve_circuit(&name.name)
|
||||||
.ok_or_else(|| AsgConvertError::unresolved_circuit(&name.name, &name.span))?,
|
.ok_or_else(|| AsgConvertError::unresolved_circuit(&name.name, &name.span))?,
|
||||||
)
|
),
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user