Bump KCVM, integrating InstructionKind (#1847)

This commit is contained in:
Adam Chalmers
2024-03-21 16:17:48 -05:00
committed by GitHub
parent 09b55259ab
commit c09d6ee6bd
6 changed files with 356 additions and 352 deletions

View File

@ -2015,7 +2015,7 @@ dependencies = [
[[package]]
name = "kittycad-execution-plan"
version = "0.1.1"
source = "git+https://github.com/KittyCAD/modeling-api?branch=main#80998dea69706b56fdcb5ba94c88e6bddc2c7946"
source = "git+https://github.com/KittyCAD/modeling-api?branch=main#9cfc1863ddf1287f8a33943ab6b201239068068f"
dependencies = [
"bytes",
"gltf-json",
@ -2037,7 +2037,7 @@ dependencies = [
[[package]]
name = "kittycad-execution-plan-macros"
version = "0.1.9"
source = "git+https://github.com/KittyCAD/modeling-api?branch=main#80998dea69706b56fdcb5ba94c88e6bddc2c7946"
source = "git+https://github.com/KittyCAD/modeling-api?branch=main#9cfc1863ddf1287f8a33943ab6b201239068068f"
dependencies = [
"proc-macro2",
"quote",
@ -2047,7 +2047,7 @@ dependencies = [
[[package]]
name = "kittycad-execution-plan-traits"
version = "0.1.14"
source = "git+https://github.com/KittyCAD/modeling-api?branch=main#80998dea69706b56fdcb5ba94c88e6bddc2c7946"
source = "git+https://github.com/KittyCAD/modeling-api?branch=main#9cfc1863ddf1287f8a33943ab6b201239068068f"
dependencies = [
"serde",
"thiserror",
@ -2056,8 +2056,8 @@ dependencies = [
[[package]]
name = "kittycad-modeling-cmds"
version = "0.2.3"
source = "git+https://github.com/KittyCAD/modeling-api?branch=main#80998dea69706b56fdcb5ba94c88e6bddc2c7946"
version = "0.2.5"
source = "git+https://github.com/KittyCAD/modeling-api?branch=main#9cfc1863ddf1287f8a33943ab6b201239068068f"
dependencies = [
"anyhow",
"chrono",
@ -2084,8 +2084,8 @@ dependencies = [
[[package]]
name = "kittycad-modeling-cmds-macros"
version = "0.1.4"
source = "git+https://github.com/KittyCAD/modeling-api?branch=main#80998dea69706b56fdcb5ba94c88e6bddc2c7946"
version = "0.1.5"
source = "git+https://github.com/KittyCAD/modeling-api?branch=main#9cfc1863ddf1287f8a33943ab6b201239068068f"
dependencies = [
"proc-macro2",
"quote",
@ -2095,7 +2095,7 @@ dependencies = [
[[package]]
name = "kittycad-modeling-session"
version = "0.1.1"
source = "git+https://github.com/KittyCAD/modeling-api?branch=main#80998dea69706b56fdcb5ba94c88e6bddc2c7946"
source = "git+https://github.com/KittyCAD/modeling-api?branch=main#9cfc1863ddf1287f8a33943ab6b201239068068f"
dependencies = [
"futures",
"kittycad",

View File

@ -12,7 +12,7 @@ use kcl_lib::{
ast::types::{BodyItem, FunctionExpressionParts, KclNone, LiteralValue, Program},
};
use kcl_value_group::into_single_value;
use kittycad_execution_plan::{self as ep, Destination, Instruction};
use kittycad_execution_plan::{self as ep, Destination, Instruction, InstructionKind};
use kittycad_execution_plan_traits as ept;
use kittycad_execution_plan_traits::{Address, NumericPrimitive};
use kittycad_modeling_session::Session;
@ -88,10 +88,10 @@ impl Planner {
SingleValue::None(KclNone { start: _, end: _ }) => {
let address = self.next_addr.offset_by(1);
Ok(EvalPlan {
instructions: vec![Instruction::SetPrimitive {
instructions: vec![Instruction::from(InstructionKind::SetPrimitive {
address,
value: ept::Primitive::Nil,
}],
})],
binding: EpBinding::Single(address),
})
}
@ -118,10 +118,10 @@ impl Planner {
let size = 1;
let address = self.next_addr.offset_by(size);
Ok(EvalPlan {
instructions: vec![Instruction::SetPrimitive {
instructions: vec![Instruction::from(InstructionKind::SetPrimitive {
address,
value: kcep_val,
}],
})],
binding: EpBinding::Single(address),
})
}
@ -138,10 +138,10 @@ impl Planner {
if let Some(b) = b {
let address = self.next_addr.offset_by(1);
return Ok(EvalPlan {
instructions: vec![Instruction::SetPrimitive {
instructions: vec![Instruction::from(InstructionKind::SetPrimitive {
address,
value: ept::Primitive::Bool(b),
}],
})],
binding: EpBinding::Single(address),
});
}
@ -167,7 +167,7 @@ impl Planner {
};
let destination = self.next_addr.offset_by(1);
let mut plan = operand.instructions;
plan.push(Instruction::UnaryArithmetic {
plan.push(Instruction::from(InstructionKind::UnaryArithmetic {
arithmetic: ep::UnaryArithmetic {
operation: match expr.operator {
ast::types::UnaryOperator::Neg => ep::UnaryOperation::Neg,
@ -176,7 +176,7 @@ impl Planner {
operand: ep::Operand::Reference(binding),
},
destination: Destination::Address(destination),
});
}));
Ok(EvalPlan {
instructions: plan,
binding: EpBinding::Single(destination),
@ -199,7 +199,7 @@ impl Planner {
let mut plan = Vec::with_capacity(l.instructions.len() + r.instructions.len() + 1);
plan.extend(l.instructions);
plan.extend(r.instructions);
plan.push(Instruction::BinaryArithmetic {
plan.push(Instruction::from(InstructionKind::BinaryArithmetic {
arithmetic: ep::BinaryArithmetic {
operation: match expr.operator {
ast::types::BinaryOperator::Add => ep::BinaryOperation::Add,
@ -213,7 +213,7 @@ impl Planner {
operand1: ep::Operand::Reference(r_binding),
},
destination: Destination::Address(destination),
});
}));
Ok(EvalPlan {
instructions: plan,
binding: EpBinding::Single(destination),
@ -395,10 +395,10 @@ impl Planner {
};
// Find the address of the member, push to stack.
instructions.push(Instruction::AddrOfMember {
instructions.push(Instruction::from(InstructionKind::AddrOfMember {
member: addr_of_member,
start: structure_start,
});
}));
// If there's another member after this one, its starting object is the
// address we just pushed to the stack.
structure_start = ep::Operand::StackPop;
@ -407,10 +407,10 @@ impl Planner {
// The final address is on the stack.
// Move it to addressable memory.
let final_prop_addr = self.next_addr.offset_by(1);
instructions.push(Instruction::CopyLen {
instructions.push(Instruction::from(InstructionKind::CopyLen {
source_range: ep::Operand::StackPop,
destination_range: ep::Operand::Literal(final_prop_addr.into()),
});
}));
Ok(EvalPlan {
instructions,
@ -503,10 +503,10 @@ impl Planner {
if let Some(length_at) = length_at {
let length_of_this_element = (self.next_addr - length_at) - 1;
// Append element's length
acc_instrs.push(Instruction::SetPrimitive {
acc_instrs.push(Instruction::from(InstructionKind::SetPrimitive {
address: length_at,
value: length_of_this_element.into(),
});
}));
}
// Append element's value
acc_instrs.extend(instrs_for_this_element);
@ -516,14 +516,14 @@ impl Planner {
// The array's overall instructions are:
// - Write a length header
// - Write everything to calculate its elements.
let mut instructions = vec![Instruction::SetPrimitive {
let mut instructions = vec![Instruction::from(InstructionKind::SetPrimitive {
address: length_at,
value: ept::ObjectHeader {
properties: keys,
size: (self.next_addr - length_at) - 1,
}
.into(),
}];
})];
instructions.extend(instructions_for_each_element);
let binding = EpBinding::Map {
length_at,
@ -560,10 +560,10 @@ impl Planner {
if let Some(length_at) = length_at {
let length_of_this_element = (self.next_addr - length_at) - 1;
// Append element's length
acc_instrs.push(Instruction::SetPrimitive {
acc_instrs.push(Instruction::from(InstructionKind::SetPrimitive {
address: length_at,
value: length_of_this_element.into(),
});
}));
}
// Append element's value
acc_instrs.extend(instrs_for_this_element);
@ -573,14 +573,14 @@ impl Planner {
// The array's overall instructions are:
// - Write a length header
// - Write everything to calculate its elements.
let mut instructions = vec![Instruction::SetPrimitive {
let mut instructions = vec![Instruction::from(InstructionKind::SetPrimitive {
address: length_at,
value: ept::ListHeader {
count: element_count,
size: (self.next_addr - length_at) - 1,
}
.into(),
}];
})];
instructions.extend(instructions_for_each_element);
let binding = EpBinding::Sequence {
length_at,

View File

@ -3,7 +3,8 @@
//! But some other stdlib functions will be written in KCL.
use kittycad_execution_plan::{
BinaryArithmetic, BinaryOperation, Destination, Instruction, Operand, UnaryArithmetic, UnaryOperation,
BinaryArithmetic, BinaryOperation, Destination, Instruction, InstructionKind, Operand, UnaryArithmetic,
UnaryOperation,
};
use kittycad_execution_plan_traits::Address;
@ -59,13 +60,13 @@ macro_rules! define_unary {
let destination = ctx.next_address.offset_by(1);
let instructions = vec![
Instruction::UnaryArithmetic {
Instruction::from(InstructionKind::UnaryArithmetic {
arithmetic: UnaryArithmetic {
operation: UnaryOperation::$h,
operand: Operand::Reference(arg0)
},
destination: Destination::Address(destination)
}
})
];
Ok(EvalPlan {
@ -144,14 +145,14 @@ macro_rules! define_binary {
};
let destination = ctx.next_address.offset_by(1);
Ok(EvalPlan {
instructions: vec![Instruction::BinaryArithmetic {
instructions: vec![Instruction::from(InstructionKind::BinaryArithmetic {
arithmetic: BinaryArithmetic {
operation: BinaryOperation::$h,
operand0: Operand::Reference(arg0),
operand1: Operand::Reference(arg1),
},
destination: Destination::Address(destination),
}],
})],
binding: EpBinding::Single(destination),
})
}

View File

@ -1,4 +1,4 @@
use kittycad_execution_plan::{api_request::ApiRequest, Destination, Instruction};
use kittycad_execution_plan::{api_request::ApiRequest, Destination, Instruction, InstructionKind};
use kittycad_execution_plan_traits::{Address, InMemory};
use kittycad_modeling_cmds::{id::ModelingCmdId, ModelingCmdEndpoint};
@ -6,12 +6,12 @@ use crate::{binding_scope::EpBinding, error::CompileError};
/// Emit instructions for an API call with no parameters.
pub fn no_arg_api_call(instrs: &mut Vec<Instruction>, endpoint: ModelingCmdEndpoint, cmd_id: ModelingCmdId) {
instrs.push(Instruction::ApiRequest(ApiRequest {
instrs.push(Instruction::from(InstructionKind::ApiRequest(ApiRequest {
endpoint,
store_response: None,
arguments: vec![],
cmd_id,
}))
})))
}
/// Emit instructions for an API call with the given parameters.
@ -26,13 +26,13 @@ pub fn stack_api_call<const N: usize>(
data: [Vec<kittycad_execution_plan_traits::Primitive>; N],
) {
let arguments = vec![InMemory::StackPop; data.len()];
instrs.extend(data.map(|data| Instruction::StackPush { data }));
instrs.push(Instruction::ApiRequest(ApiRequest {
instrs.extend(data.map(|data| Instruction::from(InstructionKind::StackPush { data })));
instrs.push(Instruction::from(InstructionKind::ApiRequest(ApiRequest {
endpoint,
store_response,
arguments,
cmd_id,
}))
})))
}
pub fn sg_binding(
@ -182,20 +182,20 @@ pub fn arg_point2d(
let start_y = start + 1;
let start_z = start + 2;
instructions.extend([
Instruction::Copy {
Instruction::from(InstructionKind::Copy {
source: single_binding(elements[0].clone(), fn_name, "number", arg_number)?,
destination: Destination::Address(start_x),
length: 1,
},
Instruction::Copy {
}),
Instruction::from(InstructionKind::Copy {
source: single_binding(elements[1].clone(), fn_name, "number", arg_number)?,
destination: Destination::Address(start_y),
length: 1,
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: start_z,
value: 0.0.into(),
},
}),
]);
ctx.next_address.offset_by(1); // After we pushed 0.0 here, just above.
Ok(start)

View File

@ -1,7 +1,7 @@
use kittycad_execution_plan::{
api_request::ApiRequest,
sketch_types::{self, Axes, BasePath, Plane, SketchGroup},
BinaryArithmetic, BinaryOperation, Destination, Instruction, Operand,
BinaryArithmetic, BinaryOperation, Destination, Instruction, InstructionKind, Operand,
};
use kittycad_execution_plan_traits::{Address, InMemory, Primitive, Value};
use kittycad_modeling_cmds::{
@ -55,14 +55,14 @@ impl Callable for Close {
let cmd_id = Uuid::new_v4().into();
instructions.extend([
// Push the path ID onto the stack.
Instruction::SketchGroupCopyFrom {
Instruction::from(InstructionKind::SketchGroupCopyFrom {
destination: Destination::StackPush,
length: 1,
source: sg,
offset: SketchGroup::path_id_offset(),
},
}),
// Call the 'extrude' API request.
Instruction::ApiRequest(ApiRequest {
Instruction::from(InstructionKind::ApiRequest(ApiRequest {
endpoint: ModelingCmdEndpoint::ClosePath,
store_response: None,
arguments: vec![
@ -70,7 +70,7 @@ impl Callable for Close {
InMemory::StackPop,
],
cmd_id,
}),
})),
]);
Ok(EvalPlan {
@ -113,18 +113,18 @@ impl Callable for Extrude {
let cmd_id = Uuid::new_v4().into();
instructions.extend([
// Push the `cap` bool onto the stack.
Instruction::StackPush {
Instruction::from(InstructionKind::StackPush {
data: vec![true.into()],
},
}),
// Push the path ID onto the stack.
Instruction::SketchGroupCopyFrom {
Instruction::from(InstructionKind::SketchGroupCopyFrom {
destination: Destination::StackPush,
length: 1,
source: sg,
offset: SketchGroup::path_id_offset(),
},
}),
// Call the 'extrude' API request.
Instruction::ApiRequest(ApiRequest {
Instruction::from(InstructionKind::ApiRequest(ApiRequest {
endpoint: ModelingCmdEndpoint::Extrude,
store_response: None,
arguments: vec![
@ -136,7 +136,7 @@ impl Callable for Extrude {
InMemory::StackPop,
],
cmd_id,
}),
})),
]);
// TODO: make an ExtrudeGroup and store it.
@ -279,10 +279,10 @@ impl LineBare {
None => {
// Write an empty string and use that.
let empty_string_addr = ctx.next_address.offset_by(1);
instructions.push(Instruction::SetPrimitive {
instructions.push(Instruction::from(InstructionKind::SetPrimitive {
address: empty_string_addr,
value: String::new().into(),
});
}));
EpBinding::Single(empty_string_addr)
}
};
@ -314,19 +314,20 @@ impl LineBare {
return Err(CompileError::InvalidOperand("Must pass a sequence here."));
};
instructions.extend([
Instruction::Copy {
// X
// X
Instruction::from(InstructionKind::Copy {
source: el0,
length: 1,
destination: Destination::StackPush,
},
Instruction::Copy {
// Y
}),
// Y
Instruction::from(InstructionKind::Copy {
source: el1,
length: 1,
destination: Destination::StackExtend,
},
Instruction::StackExtend { data: vec![0.0.into()] }, // Z
}),
// Z
Instruction::from(InstructionKind::StackExtend { data: vec![0.0.into()] }),
]);
}
LineBareOptions { at: At::AbsoluteX, .. } | LineBareOptions { at: At::RelativeX, .. } => {
@ -334,18 +335,18 @@ impl LineBare {
return Err(CompileError::InvalidOperand("Must pass a single value here."));
};
instructions.extend([
Instruction::Copy {
Instruction::from(InstructionKind::Copy {
// X
source: addr,
length: 1,
destination: Destination::StackPush,
},
Instruction::StackExtend {
}),
Instruction::from(InstructionKind::StackExtend {
data: vec![Primitive::from(0.0)],
}, // Y
Instruction::StackExtend {
}), // Y
Instruction::from(InstructionKind::StackExtend {
data: vec![Primitive::from(0.0)],
}, // Z
}), // Z
]);
}
LineBareOptions { at: At::AbsoluteY, .. } | LineBareOptions { at: At::RelativeY, .. } => {
@ -353,18 +354,20 @@ impl LineBare {
return Err(CompileError::InvalidOperand("Must pass a single value here."));
};
instructions.extend([
Instruction::StackPush {
// X
Instruction::from(InstructionKind::StackPush {
data: vec![Primitive::from(0.0)],
}, // X
Instruction::Copy {
// Y
}),
// Y
Instruction::from(InstructionKind::Copy {
source: addr,
length: 1,
destination: Destination::StackExtend,
},
Instruction::StackExtend {
}),
// Z
Instruction::from(InstructionKind::StackExtend {
data: vec![Primitive::from(0.0)],
}, // Z
}),
]);
}
}
@ -372,28 +375,28 @@ impl LineBare {
instructions.extend([
// Append the new path segment to memory.
// First comes its tag.
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: start_of_line,
value: "Line".to_owned().into(),
},
}),
// Then its end
Instruction::StackPop {
Instruction::from(InstructionKind::StackPop {
destination: Some(Destination::Address(start_of_line + 1)),
},
}),
// Then its `relative` field.
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: start_of_line + 1 + length_of_3d_point,
value: opts.at.is_relative().into(),
},
}),
// Push the path ID onto the stack.
Instruction::SketchGroupCopyFrom {
Instruction::from(InstructionKind::SketchGroupCopyFrom {
destination: Destination::StackPush,
length: 1,
source: sg,
offset: SketchGroup::path_id_offset(),
},
}),
// Send the ExtendPath request
Instruction::ApiRequest(ApiRequest {
Instruction::from(InstructionKind::ApiRequest(ApiRequest {
endpoint: ModelingCmdEndpoint::ExtendPath,
store_response: None,
arguments: vec![
@ -403,18 +406,18 @@ impl LineBare {
InMemory::Address(start_of_line),
],
cmd_id: id.into(),
}),
})),
// Push the new segment in SketchGroup format.
// Path tag.
Instruction::StackPush {
Instruction::from(InstructionKind::StackPush {
data: vec![Primitive::from("ToPoint".to_owned())],
},
}),
// `BasePath::from` point.
// Place them in the secondary stack to prepare ToPoint structure.
Instruction::SketchGroupGetLastPoint {
Instruction::from(InstructionKind::SketchGroupGetLastPoint {
source: sg,
destination: Destination::StackExtend,
},
}),
]);
// Reserve space for the segment last point
@ -422,10 +425,10 @@ impl LineBare {
instructions.extend([
// Copy to the primary stack as well to be worked with.
Instruction::SketchGroupGetLastPoint {
Instruction::from(InstructionKind::SketchGroupGetLastPoint {
source: sg,
destination: Destination::Address(to_point_from),
},
}),
]);
// `BasePath::to` point.
@ -441,38 +444,38 @@ impl LineBare {
// ToPoint { from: { x1, y1 }, to: { x1 + x2, y1 + y2 } }
LineBareOptions { at: At::RelativeXY, .. } => {
instructions.extend([
Instruction::BinaryArithmetic {
Instruction::from(InstructionKind::BinaryArithmetic {
arithmetic: BinaryArithmetic {
operation: BinaryOperation::Add,
operand0: Operand::Reference(to_point_from + 0),
operand1: Operand::Reference(el0),
},
destination: Destination::StackExtend,
},
Instruction::BinaryArithmetic {
}),
Instruction::from(InstructionKind::BinaryArithmetic {
arithmetic: BinaryArithmetic {
operation: BinaryOperation::Add,
operand0: Operand::Reference(to_point_from + 1),
operand1: Operand::Reference(el1),
},
destination: Destination::StackExtend,
},
}),
]);
}
// ToPoint { from: { x1, y1 }, to: { x2, y2 } }
LineBareOptions { at: At::AbsoluteXY, .. } => {
// Otherwise just directly copy the new points.
instructions.extend([
Instruction::Copy {
Instruction::from(InstructionKind::Copy {
source: el0,
length: 1,
destination: Destination::StackExtend,
},
Instruction::Copy {
}),
Instruction::from(InstructionKind::Copy {
source: el1,
length: 1,
destination: Destination::StackExtend,
},
}),
]);
}
_ => {
@ -487,67 +490,67 @@ impl LineBare {
// ToPoint { from: { x1, y1 }, to: { x1 + x2, y1 } }
LineBareOptions { at: At::RelativeX } => {
instructions.extend([
Instruction::BinaryArithmetic {
Instruction::from(InstructionKind::BinaryArithmetic {
arithmetic: BinaryArithmetic {
operation: BinaryOperation::Add,
operand0: Operand::Reference(to_point_from + 0),
operand1: Operand::Reference(addr),
},
destination: Destination::StackExtend,
},
Instruction::Copy {
}),
Instruction::from(InstructionKind::Copy {
source: to_point_from + 1,
length: 1,
destination: Destination::StackExtend,
},
}),
]);
}
// ToPoint { from: { x1, y1 }, to: { x2, y1 } }
LineBareOptions { at: At::AbsoluteX } => {
instructions.extend([
Instruction::Copy {
Instruction::from(InstructionKind::Copy {
source: addr,
length: 1,
destination: Destination::StackExtend,
},
Instruction::Copy {
}),
Instruction::from(InstructionKind::Copy {
source: to_point_from + 1,
length: 1,
destination: Destination::StackExtend,
},
}),
]);
}
// ToPoint { from: { x1, y1 }, to: { x1, y1 + y2 } }
LineBareOptions { at: At::RelativeY } => {
instructions.extend([
Instruction::Copy {
Instruction::from(InstructionKind::Copy {
source: to_point_from + 0,
length: 1,
destination: Destination::StackExtend,
},
Instruction::BinaryArithmetic {
}),
Instruction::from(InstructionKind::BinaryArithmetic {
arithmetic: BinaryArithmetic {
operation: BinaryOperation::Add,
operand0: Operand::Reference(to_point_from + 1),
operand1: Operand::Reference(addr),
},
destination: Destination::StackExtend,
},
}),
]);
}
// ToPoint { from: { x1, y1 }, to: { x1, y2 } }
LineBareOptions { at: At::AbsoluteY } => {
instructions.extend([
Instruction::Copy {
Instruction::from(InstructionKind::Copy {
source: to_point_from + 0,
length: 1,
destination: Destination::StackExtend,
},
Instruction::Copy {
}),
Instruction::from(InstructionKind::Copy {
source: addr,
length: 1,
destination: Destination::StackExtend,
},
}),
]);
}
_ => {
@ -564,17 +567,17 @@ impl LineBare {
instructions.extend([
// `BasePath::name` string.
Instruction::Copy {
Instruction::from(InstructionKind::Copy {
source: tag,
length: 1,
destination: Destination::StackExtend,
},
}),
// Update the SketchGroup with its new segment.
Instruction::SketchGroupAddSegment {
Instruction::from(InstructionKind::SketchGroupAddSegment {
destination: new_sg_index,
segment: InMemory::StackPop,
source: sg,
},
}),
]);
Ok(EvalPlan {
@ -655,15 +658,15 @@ impl Callable for StartSketchAt {
no_arg_api_call(&mut instructions, ModelingCmdEndpoint::StartPath, path_id.into());
// Move the path pen to the given point.
instructions.push(Instruction::StackPush {
instructions.push(Instruction::from(InstructionKind::StackPush {
data: vec![path_id.into()],
});
instructions.push(Instruction::ApiRequest(ApiRequest {
}));
instructions.push(Instruction::from(InstructionKind::ApiRequest(ApiRequest {
endpoint: ModelingCmdEndpoint::MovePathPen,
store_response: None,
arguments: vec![InMemory::StackPop, InMemory::Address(start_point)],
cmd_id: Uuid::new_v4().into(),
}));
})));
// Starting a sketch creates a sketch group.
// Updating the sketch will update this sketch group later.
@ -695,17 +698,17 @@ impl Callable for StartSketchAt {
};
let sketch_group_index = ctx.assign_sketch_group();
instructions.extend([
Instruction::SketchGroupSet {
Instruction::from(InstructionKind::SketchGroupSet {
sketch_group,
destination: sketch_group_index,
},
}),
// As mentioned above: Copy the existing data over the `path_first`.
Instruction::SketchGroupSetBasePath {
Instruction::from(InstructionKind::SketchGroupSetBasePath {
source: sketch_group_index,
from: InMemory::Address(start_point),
to: InMemory::Address(start_point),
name: tag.map(InMemory::Address),
},
}),
]);
Ok(EvalPlan {
@ -750,10 +753,10 @@ impl Callable for TangentialArcTo {
None => {
// Write an empty string and use that.
let empty_string_addr = ctx.next_address.offset_by(1);
instructions.push(Instruction::SetPrimitive {
instructions.push(Instruction::from(InstructionKind::SetPrimitive {
address: empty_string_addr,
value: String::new().into(),
});
}));
EpBinding::Single(empty_string_addr)
}
};
@ -770,37 +773,37 @@ impl Callable for TangentialArcTo {
let new_sg_index = ctx.assign_sketch_group();
instructions.extend([
// Push the `to` 2D point onto the stack.
Instruction::Copy {
Instruction::from(InstructionKind::Copy {
source: to,
length: 2,
destination: Destination::StackPush,
},
}),
// Make it a 3D point.
Instruction::StackExtend { data: vec![0.0.into()] },
Instruction::from(InstructionKind::StackExtend { data: vec![0.0.into()] }),
// Append the new path segment to memory.
// First comes its tag.
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: start_of_tangential_arc,
value: "TangentialArcTo".to_owned().into(),
},
}),
// Then its to
Instruction::StackPop {
Instruction::from(InstructionKind::StackPop {
destination: Some(Destination::Address(start_of_tangential_arc + 1)),
},
}),
// Then its `angle_snap_increment` field.
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: start_of_tangential_arc + 1 + length_of_3d_point,
value: Primitive::from("None".to_owned()),
},
}),
// Push the path ID onto the stack.
Instruction::SketchGroupCopyFrom {
Instruction::from(InstructionKind::SketchGroupCopyFrom {
destination: Destination::StackPush,
length: 1,
source: sg,
offset: SketchGroup::path_id_offset(),
},
}),
// Send the ExtendPath request
Instruction::ApiRequest(ApiRequest {
Instruction::from(InstructionKind::ApiRequest(ApiRequest {
endpoint: ModelingCmdEndpoint::ExtendPath,
store_response: None,
arguments: vec![
@ -810,35 +813,35 @@ impl Callable for TangentialArcTo {
InMemory::Address(start_of_tangential_arc),
],
cmd_id: id.into(),
}),
})),
// Push the new segment in SketchGroup format.
// Path tag.
Instruction::StackPush {
Instruction::from(InstructionKind::StackPush {
data: vec![Primitive::from("ToPoint".to_owned())],
},
}),
// `BasePath::from` point.
Instruction::SketchGroupGetLastPoint {
Instruction::from(InstructionKind::SketchGroupGetLastPoint {
source: sg,
destination: Destination::StackExtend,
},
}),
// `BasePath::to` point.
Instruction::Copy {
Instruction::from(InstructionKind::Copy {
source: start_of_tangential_arc + 1,
length: 2,
destination: Destination::StackExtend,
},
}),
// `BasePath::name` string.
Instruction::Copy {
Instruction::from(InstructionKind::Copy {
source: tag,
length: 1,
destination: Destination::StackExtend,
},
}),
// Update the SketchGroup with its new segment.
Instruction::SketchGroupAddSegment {
Instruction::from(InstructionKind::SketchGroupAddSegment {
destination: new_sg_index,
segment: InMemory::StackPop,
source: sg,
},
}),
]);
Ok(EvalPlan {

View File

@ -34,14 +34,14 @@ fn assignments() {
assert_eq!(
plan,
vec![
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO,
value: 1i64.into(),
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO.offset(1),
value: 2i64.into(),
}
}),
]
);
}
@ -54,7 +54,7 @@ fn bind_array_simple() {
plan,
vec![
// Array length
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO,
value: ListHeader {
// The list has 3 elements
@ -64,34 +64,34 @@ fn bind_array_simple() {
size: 6
}
.into()
},
}),
// Elem 0
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 1,
value: 1usize.into()
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 2,
value: 44i64.into(),
},
}),
// Elem 1
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 3,
value: 1usize.into()
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 4,
value: 55i64.into(),
},
}),
// Elem 2
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 5,
value: 1usize.into()
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 6,
value: "sixty-six".to_owned().into(),
}
}),
]
);
}
@ -104,7 +104,7 @@ fn bind_nested_array() {
plan,
vec![
// Outer array length
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO,
value: ListHeader {
count: 2,
@ -112,42 +112,42 @@ fn bind_nested_array() {
size: 2 + 2 + 2 + 1,
}
.into(),
},
}),
// Outer array element 0 length
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 1,
value: 1usize.into(),
},
}),
// Outer array element 0 value
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 2,
value: 44i64.into(),
},
}),
// Outer array element 1 length (i.e. inner array header)
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 3,
value: ListHeader { count: 2, size: 4 }.into(),
},
}),
// Inner array elem0 length
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 4,
value: 1usize.into(),
},
}),
// Inner array elem0 value
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 5,
value: 55i64.into(),
},
}),
// Inner array elem1 length
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 6,
value: 1usize.into(),
},
}),
// Inner array elem1 value
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 7,
value: "sixty-six".to_owned().into(),
},
}),
]
);
}
@ -160,43 +160,43 @@ fn bind_arrays_with_objects_elements() {
plan,
vec![
// List header
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO,
value: ListHeader { count: 2, size: 7 }.into()
},
}),
// Array contents
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 1,
value: 1usize.into(),
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 2,
value: 44i64.into(),
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 3,
value: ObjectHeader {
size: 4,
properties: vec!["a".to_owned(), "b".to_owned(),]
}
.into(),
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 4,
value: 1usize.into(),
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 5,
value: 55i64.into()
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 6,
value: 1usize.into(),
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 7,
value: "sixty-six".to_owned().into()
},
}),
]
);
}
@ -227,10 +227,10 @@ fn assign_bool() {
let (plan, scope, _) = must_plan(&program);
assert_eq!(
plan,
vec![Instruction::SetPrimitive {
vec![Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO,
value: val.into(),
}]
})]
);
assert_eq!(scope.get("x"), Some(&EpBinding::Single(Address::ZERO)));
}
@ -244,10 +244,10 @@ fn aliases() {
let (plan, _scope, _) = must_plan(program);
assert_eq!(
plan,
vec![Instruction::SetPrimitive {
vec![Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO,
value: 1i64.into(),
}]
})]
);
}
@ -258,22 +258,22 @@ fn use_native_function_add() {
assert_eq!(
plan,
vec![
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO,
value: 1i64.into()
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO.offset(1),
value: 2i64.into()
},
Instruction::BinaryArithmetic {
}),
Instruction::from(InstructionKind::BinaryArithmetic {
arithmetic: ep::BinaryArithmetic {
operation: ep::BinaryOperation::Add,
operand0: ep::Operand::Reference(Address::ZERO),
operand1: ep::Operand::Reference(Address::ZERO.offset(1))
},
destination: Destination::Address(Address::ZERO.offset(2)),
}
}),
]
);
}
@ -284,10 +284,10 @@ fn use_native_function_id() {
let (plan, _scope, _) = must_plan(program);
assert_eq!(
plan,
vec![Instruction::SetPrimitive {
vec![Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO,
value: 2i64.into()
}]
})]
);
}
@ -395,70 +395,70 @@ async fn computed_array_index() {
vec![
// Setting the array
// First, the length of the array (number of elements).
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO,
value: ListHeader { count: 3, size: 6 }.into()
},
}),
// Elem 0 length
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 1,
value: 1usize.into()
},
}),
// Elem 0 value
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 2,
value: "a".to_owned().into()
},
}),
// Elem 1 length
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 3,
value: 1usize.into()
},
}),
// Elem 1 value
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 4,
value: "b".to_owned().into()
},
}),
// Elem 2 length
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 5,
value: 1usize.into()
},
}),
// Elem 2 value
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 6,
value: "c".to_owned().into()
},
}),
// Calculate the index (1+1)
// First, the left operand
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 7,
value: 1i64.to_owned().into()
},
}),
// Then the right operand
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 8,
value: 1i64.to_owned().into()
},
}),
// Then index, which is left operand + right operand
Instruction::BinaryArithmetic {
Instruction::from(InstructionKind::BinaryArithmetic {
arithmetic: ep::BinaryArithmetic {
operation: ep::BinaryOperation::Add,
operand0: ep::Operand::Reference(Address::ZERO + 7),
operand1: ep::Operand::Reference(Address::ZERO + 8)
},
destination: Destination::Address(Address::ZERO + 9)
},
}),
// Get the element at the index
Instruction::AddrOfMember {
Instruction::from(InstructionKind::AddrOfMember {
start: ep::Operand::Literal(Address::ZERO.into()),
member: ep::Operand::Reference(Address::ZERO + 9)
},
}),
// Write it to the next free address.
Instruction::CopyLen {
Instruction::from(InstructionKind::CopyLen {
source_range: ep::Operand::StackPop,
destination_range: ep::Operand::Literal(expected_address_of_prop.into()),
},
}),
]
);
// Now let's run the program and check what's actually in the memory afterwards.
@ -537,17 +537,17 @@ fn compile_flipped_sign() {
let y = -x";
let (plan, _scope, _) = must_plan(program);
let expected = vec![
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO,
value: 3i64.into(),
},
Instruction::UnaryArithmetic {
}),
Instruction::from(InstructionKind::UnaryArithmetic {
arithmetic: UnaryArithmetic {
operation: ep::UnaryOperation::Neg,
operand: ep::Operand::Reference(Address::ZERO),
},
destination: Destination::Address(Address::ZERO + 1),
},
}),
];
assert_eq!(plan, expected);
}
@ -559,22 +559,22 @@ fn add_literals() {
assert_eq!(
plan,
vec![
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO,
value: 1i64.into()
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO.offset(1),
value: 2i64.into()
},
Instruction::BinaryArithmetic {
}),
Instruction::from(InstructionKind::BinaryArithmetic {
arithmetic: ep::BinaryArithmetic {
operation: ep::BinaryOperation::Add,
operand0: ep::Operand::Reference(Address::ZERO),
operand1: ep::Operand::Reference(Address::ZERO.offset(1)),
},
destination: Destination::Address(Address::ZERO.offset(2)),
}
}),
]
);
}
@ -591,22 +591,22 @@ fn add_vars() {
assert_eq!(
plan,
vec![
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: addr0,
value: 1i64.into(),
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: addr1,
value: 2i64.into(),
},
Instruction::BinaryArithmetic {
}),
Instruction::from(InstructionKind::BinaryArithmetic {
arithmetic: ep::BinaryArithmetic {
operation: ep::BinaryOperation::Add,
operand0: ep::Operand::Reference(addr0),
operand1: ep::Operand::Reference(addr1),
},
destination: Destination::Address(Address::ZERO.offset(2)),
}
}),
]
);
}
@ -627,36 +627,36 @@ fn composite_binary_exprs() {
assert_eq!(
plan,
vec![
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: addr0,
value: 1i64.into(),
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: addr1,
value: 2i64.into(),
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: addr2,
value: 3i64.into(),
},
}),
// Adds 1 + 2
Instruction::BinaryArithmetic {
Instruction::from(InstructionKind::BinaryArithmetic {
arithmetic: ep::BinaryArithmetic {
operation: ep::BinaryOperation::Add,
operand0: ep::Operand::Reference(addr0),
operand1: ep::Operand::Reference(addr1),
},
destination: Destination::Address(addr3),
},
}),
// Adds `x` + 3, where `x` is (1 + 2)
Instruction::BinaryArithmetic {
Instruction::from(InstructionKind::BinaryArithmetic {
arithmetic: ep::BinaryArithmetic {
operation: ep::BinaryOperation::Add,
operand0: ep::Operand::Reference(addr3),
operand1: ep::Operand::Reference(addr2),
},
destination: Destination::Address(Address::ZERO.offset(4)),
}
}),
]
);
}
@ -669,10 +669,10 @@ fn use_kcl_functions_zero_params() {
);
assert_eq!(
plan,
vec![Instruction::SetPrimitive {
vec![Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO,
value: 123i64.into()
}]
})]
);
match scope.get("x").unwrap() {
EpBinding::Single(addr) => {
@ -696,26 +696,26 @@ fn use_kcl_functions_with_optional_params() {
assert_eq!(
plan,
vec![
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO,
value: 1i64.into(),
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 1,
value: 888i64.into(),
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 2,
value: 3i64.into(),
},
Instruction::BinaryArithmetic {
}),
Instruction::from(InstructionKind::BinaryArithmetic {
arithmetic: ep::BinaryArithmetic {
operation: ep::BinaryOperation::Mul,
operand0: ep::Operand::Reference(Address::ZERO),
operand1: ep::Operand::Reference(Address::ZERO + 2)
},
destination: Destination::Address(destination),
}
}),
],
"failed test {i}"
);
@ -763,10 +763,10 @@ fn use_kcl_function_as_return_value() {
}
assert_eq!(
plan,
vec![Instruction::SetPrimitive {
vec![Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO,
value: 222i64.into()
}]
})]
)
}
@ -798,10 +798,10 @@ fn use_kcl_function_as_param() {
}
assert_eq!(
plan,
vec![Instruction::SetPrimitive {
vec![Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO,
value: 222i64.into()
}]
})]
)
}
@ -821,22 +821,22 @@ fn use_kcl_functions_with_params() {
assert_eq!(
plan,
vec![
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO,
value: 1i64.into(),
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 1,
value: 3i64.into(),
},
Instruction::BinaryArithmetic {
}),
Instruction::from(InstructionKind::BinaryArithmetic {
arithmetic: ep::BinaryArithmetic {
operation: ep::BinaryOperation::Mul,
operand0: ep::Operand::Reference(Address::ZERO),
operand1: ep::Operand::Reference(Address::ZERO.offset(1))
},
destination: Destination::Address(destination),
}
}),
],
"failed test {i}"
);
@ -914,53 +914,53 @@ fn store_object() {
let program = "const x0 = {a: 1, b: 2, c: {d: 3}}";
let (actual, bindings, _) = must_plan(program);
let expected = vec![
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO,
value: ObjectHeader {
properties: vec!["a".to_owned(), "b".to_owned(), "c".to_owned()],
size: 7,
}
.into(),
},
}),
// Key a header
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 1,
value: 1usize.into(),
},
}),
// Key a value
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 2,
value: 1i64.into(),
},
}),
// Key b header
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 3,
value: 1usize.into(),
},
}),
// Key b value
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 4,
value: 2i64.into(),
},
}),
// Inner object (i.e. key c) header
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 5,
value: ObjectHeader {
properties: vec!["d".to_owned()],
size: 2,
}
.into(),
},
}),
// Key d header
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 6,
value: 1usize.into(),
},
}),
// Key d value
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 7,
value: 3i64.into(),
},
}),
];
assert_eq!(actual, expected);
let actual = bindings.get("x0").unwrap();
@ -986,43 +986,43 @@ fn store_object_with_array_property() {
let program = "const x0 = {a: 1, b: [2, 3]}";
let (actual, bindings, _) = must_plan(program);
let expected = vec![
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO,
value: ObjectHeader {
properties: vec!["a".to_owned(), "b".to_owned()],
size: 7,
}
.into(),
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 1,
value: 1usize.into(),
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 2,
value: 1i64.into(),
},
}),
// Array header
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 3,
value: ListHeader { count: 2, size: 4 }.into(),
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 4,
value: 1usize.into(),
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 5,
value: 2i64.into(),
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 6,
value: 1usize.into(),
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 7,
value: 3i64.into(),
},
}),
];
assert_eq!(actual, expected);
assert_eq!(
@ -1366,22 +1366,22 @@ fn objects_as_parameters() {
let (plan, scope, _) = must_plan(program);
let expected_plan = vec![
// Object contents
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO,
value: ObjectHeader {
properties: vec!["x".to_owned()],
size: 2,
}
.into(),
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 1,
value: 1usize.into(),
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 2,
value: 1i64.into(),
},
}),
];
assert_eq!(plan, expected_plan);
assert_eq!(
@ -1403,35 +1403,35 @@ fn arrays_as_parameters() {
const INDEX_OF_C: usize = 6;
let expected_plan = vec![
// Array length
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO,
value: ListHeader { count: 3, size: 6 }.into(),
},
}),
// Array contents
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 1,
value: 1usize.into(),
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + INDEX_OF_A,
value: "a".to_owned().into(),
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 3,
value: 1usize.into(),
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + INDEX_OF_B,
value: "b".to_owned().into(),
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + 5,
value: 1usize.into(),
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: Address::ZERO + INDEX_OF_C,
value: "c".to_owned().into(),
},
}),
];
assert_eq!(plan, expected_plan);
assert_eq!(
@ -1464,36 +1464,36 @@ fn mod_and_pow() {
assert_eq!(
plan,
vec![
Instruction::SetPrimitive {
Instruction::from(InstructionKind::SetPrimitive {
address: addr0,
value: 2i64.into(),
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: addr1,
value: 3i64.into(),
},
}),
// x ^ 3, where x = 2
Instruction::BinaryArithmetic {
Instruction::from(InstructionKind::BinaryArithmetic {
arithmetic: ep::BinaryArithmetic {
operation: ep::BinaryOperation::Pow,
operand0: ep::Operand::Reference(addr0),
operand1: ep::Operand::Reference(addr1),
},
destination: Destination::Address(addr2),
},
Instruction::SetPrimitive {
}),
Instruction::from(InstructionKind::SetPrimitive {
address: addr3,
value: 5i64.into(),
},
}),
// y % 5, where y is 2^3
Instruction::BinaryArithmetic {
Instruction::from(InstructionKind::BinaryArithmetic {
arithmetic: ep::BinaryArithmetic {
operation: ep::BinaryOperation::Mod,
operand0: ep::Operand::Reference(addr2),
operand1: ep::Operand::Reference(addr3),
},
destination: Destination::Address(addr4),
}
}),
]
);
}