Refactor: plan_to_bind_one returns EvalPlan not tuple
This commit is contained in:
@ -43,7 +43,7 @@ impl EpBinding {
|
||||
LiteralIdentifier::Literal(litval) => match litval.value {
|
||||
// Arrays can be indexed by integers.
|
||||
LiteralValue::IInteger(i) => match self {
|
||||
EpBinding::Sequence { length_at, elements } => {
|
||||
EpBinding::Sequence { length_at: _, elements } => {
|
||||
let i = usize::try_from(i).map_err(|_| CompileError::InvalidIndex(i.to_string()))?;
|
||||
elements
|
||||
.get(i)
|
||||
|
||||
@ -231,7 +231,7 @@ impl Planner {
|
||||
binding: arg,
|
||||
} = match KclValueGroup::from(argument) {
|
||||
KclValueGroup::Single(value) => self.plan_to_compute_single(ctx, value)?,
|
||||
KclValueGroup::ArrayExpression(_) => todo!(),
|
||||
KclValueGroup::ArrayExpression(expr) => todo!(),
|
||||
KclValueGroup::ObjectExpression(_) => todo!(),
|
||||
};
|
||||
acc_instrs.extend(new_instructions);
|
||||
@ -411,9 +411,9 @@ impl Planner {
|
||||
.declarations
|
||||
.into_iter()
|
||||
.try_fold(Vec::new(), |mut acc, declaration| {
|
||||
let (instrs, binding) = self.plan_to_bind_one(&mut ctx, declaration.init)?;
|
||||
let EvalPlan { instructions, binding } = self.plan_to_bind_one(&mut ctx, declaration.init)?;
|
||||
self.binding_scope.bind(declaration.id.name, binding);
|
||||
acc.extend(instrs);
|
||||
acc.extend(instructions);
|
||||
Ok(acc)
|
||||
})
|
||||
}
|
||||
@ -422,13 +422,13 @@ impl Planner {
|
||||
&mut self,
|
||||
ctx: &mut Context,
|
||||
value_being_bound: ast::types::Value,
|
||||
) -> Result<(Vec<Instruction>, EpBinding), CompileError> {
|
||||
) -> Result<EvalPlan, CompileError> {
|
||||
match KclValueGroup::from(value_being_bound) {
|
||||
KclValueGroup::Single(init_value) => {
|
||||
// Simple! Just evaluate it, note where the final value will be stored in KCEP memory,
|
||||
// and bind it to the KCL identifier.
|
||||
let EvalPlan { instructions, binding } = self.plan_to_compute_single(ctx, init_value)?;
|
||||
Ok((instructions, binding))
|
||||
Ok(EvalPlan { instructions, binding })
|
||||
}
|
||||
KclValueGroup::ArrayExpression(expr) => {
|
||||
let length_at = self.next_addr.offset_by(1);
|
||||
@ -463,7 +463,8 @@ impl Planner {
|
||||
.elements
|
||||
.into_iter()
|
||||
.try_fold(Vec::new(), |mut seq, child_element| {
|
||||
let (instructions, binding) = self.plan_to_bind_one(ctx, child_element)?;
|
||||
let EvalPlan { instructions, binding } =
|
||||
self.plan_to_bind_one(ctx, child_element)?;
|
||||
acc_instrs.extend(instructions);
|
||||
seq.push(binding);
|
||||
Ok(seq)
|
||||
@ -481,7 +482,8 @@ impl Planner {
|
||||
.properties
|
||||
.into_iter()
|
||||
.try_fold(map, |mut map, property| {
|
||||
let (instructions, binding) = self.plan_to_bind_one(ctx, property.value)?;
|
||||
let EvalPlan { instructions, binding } =
|
||||
self.plan_to_bind_one(ctx, property.value)?;
|
||||
map.insert(property.key.name, binding);
|
||||
acc_instrs.extend(instructions);
|
||||
Ok(map)
|
||||
@ -494,13 +496,13 @@ impl Planner {
|
||||
},
|
||||
)?;
|
||||
instructions.extend(instrs);
|
||||
Ok((
|
||||
Ok(EvalPlan {
|
||||
instructions,
|
||||
EpBinding::Sequence {
|
||||
binding: EpBinding::Sequence {
|
||||
length_at,
|
||||
elements: bindings,
|
||||
},
|
||||
))
|
||||
})
|
||||
}
|
||||
KclValueGroup::ObjectExpression(expr) => {
|
||||
// Convert the object to a sequence of key-value pairs.
|
||||
@ -528,7 +530,8 @@ impl Planner {
|
||||
.elements
|
||||
.into_iter()
|
||||
.try_fold(Vec::with_capacity(n), |mut seq, child_element| {
|
||||
let (instructions, binding) = self.plan_to_bind_one(ctx, child_element)?;
|
||||
let EvalPlan { instructions, binding } =
|
||||
self.plan_to_bind_one(ctx, child_element)?;
|
||||
seq.push(binding);
|
||||
acc_instrs.extend(instructions);
|
||||
Ok(seq)
|
||||
@ -546,7 +549,8 @@ impl Planner {
|
||||
.properties
|
||||
.into_iter()
|
||||
.try_fold(HashMap::with_capacity(n), |mut map, property| {
|
||||
let (instructions, binding) = self.plan_to_bind_one(ctx, property.value)?;
|
||||
let EvalPlan { instructions, binding } =
|
||||
self.plan_to_bind_one(ctx, property.value)?;
|
||||
map.insert(property.key.name, binding);
|
||||
acc_instrs.extend(instructions);
|
||||
Ok(map)
|
||||
@ -558,7 +562,10 @@ impl Planner {
|
||||
Ok((acc_instrs, acc_bindings))
|
||||
},
|
||||
)?;
|
||||
Ok((instructions, EpBinding::Map(each_property_binding)))
|
||||
Ok(EvalPlan {
|
||||
instructions,
|
||||
binding: EpBinding::Map(each_property_binding),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user