mirror of
https://github.com/AleoHQ/leo.git
synced 2024-12-24 01:54:23 +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> {
|
||||
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 circuit = scope.context.alloc_circuit(Circuit {
|
||||
@ -66,6 +66,19 @@ impl<'a> Circuit<'a> {
|
||||
});
|
||||
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();
|
||||
for member in value.members.iter() {
|
||||
match member {
|
||||
|
@ -238,7 +238,15 @@ impl<'a> Program<'a> {
|
||||
// Prepare header-like scope entries.
|
||||
for (name, circuit) in program.circuits.iter() {
|
||||
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);
|
||||
}
|
||||
|
@ -194,26 +194,18 @@ impl<'a> Scope<'a> {
|
||||
.map(|x| self.resolve_ast_type(x))
|
||||
.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(
|
||||
self.resolve_circuit_self()
|
||||
.ok_or_else(AsgConvertError::reference_self_outside_circuit)?,
|
||||
),
|
||||
Circuit(name) => {
|
||||
// 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(
|
||||
Circuit(name) => Type::Circuit(
|
||||
self.resolve_circuit(&name.name)
|
||||
.ok_or_else(|| AsgConvertError::unresolved_circuit(&name.name, &name.span))?,
|
||||
)
|
||||
}
|
||||
),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user