Merge branch 'main' into cmd-bar-make-variable

This commit is contained in:
Frank Noirot
2024-02-21 14:10:11 -05:00
parent b866f3601c
commit ac43530feb
4 changed files with 58 additions and 10 deletions

View File

@ -1986,7 +1986,7 @@ dependencies = [
[[package]]
name = "kittycad-execution-plan"
version = "0.1.0"
source = "git+https://github.com/KittyCAD/modeling-api?branch=main#632b75a0242400fa34373d7973b9149b0e08aa3f"
source = "git+https://github.com/KittyCAD/modeling-api?branch=main#08f05d91062380fe3a69f4baa1f1301532d31977"
dependencies = [
"bytes",
"insta",
@ -2036,8 +2036,8 @@ dependencies = [
[[package]]
name = "kittycad-modeling-cmds"
version = "0.1.17"
source = "git+https://github.com/KittyCAD/modeling-api?branch=main#632b75a0242400fa34373d7973b9149b0e08aa3f"
version = "0.1.18"
source = "git+https://github.com/KittyCAD/modeling-api?branch=main#08f05d91062380fe3a69f4baa1f1301532d31977"
dependencies = [
"anyhow",
"chrono",
@ -2064,7 +2064,7 @@ dependencies = [
[[package]]
name = "kittycad-modeling-session"
version = "0.1.0"
source = "git+https://github.com/KittyCAD/modeling-api?branch=main#632b75a0242400fa34373d7973b9149b0e08aa3f"
source = "git+https://github.com/KittyCAD/modeling-api?branch=main#08f05d91062380fe3a69f4baa1f1301532d31977"
dependencies = [
"futures",
"kittycad",

View File

@ -202,12 +202,8 @@ impl Planner {
ast::types::BinaryOperator::Sub => ep::BinaryOperation::Sub,
ast::types::BinaryOperator::Mul => ep::BinaryOperation::Mul,
ast::types::BinaryOperator::Div => ep::BinaryOperation::Div,
ast::types::BinaryOperator::Mod => {
todo!("execution plan instruction set doesn't support Mod yet")
}
ast::types::BinaryOperator::Pow => {
todo!("execution plan instruction set doesn't support Pow yet")
}
ast::types::BinaryOperator::Mod => ep::BinaryOperation::Mod,
ast::types::BinaryOperator::Pow => ep::BinaryOperation::Pow,
},
operand0: ep::Operand::Reference(l_binding),
operand1: ep::Operand::Reference(r_binding),

View File

@ -1145,3 +1145,54 @@ fn arrays_as_parameters() {
}
)
}
#[test]
fn mod_and_pow() {
let program = "
let x = 2
let y = x^3
let z = y % 5
";
let (plan, _bindings) = must_plan(program);
let addr0 = Address::ZERO;
let addr1 = Address::ZERO.offset(1);
let addr2 = Address::ZERO.offset(2);
let addr3 = Address::ZERO.offset(3);
let addr4 = Address::ZERO.offset(4);
print!("{:?}", plan);
assert_eq!(
plan,
vec![
Instruction::SetPrimitive {
address: addr0,
value: 2i64.into(),
},
Instruction::SetPrimitive {
address: addr1,
value: 3i64.into(),
},
// x ^ 3, where x = 2
Instruction::BinaryArithmetic {
arithmetic: ep::BinaryArithmetic {
operation: ep::BinaryOperation::Pow,
operand0: ep::Operand::Reference(addr0),
operand1: ep::Operand::Reference(addr1),
},
destination: Destination::Address(addr2),
},
Instruction::SetPrimitive {
address: addr3,
value: 5i64.into(),
},
// y % 5, where y is 2^3
Instruction::BinaryArithmetic {
arithmetic: ep::BinaryArithmetic {
operation: ep::BinaryOperation::Mod,
operand0: ep::Operand::Reference(addr2),
operand1: ep::Operand::Reference(addr3),
},
destination: Destination::Address(addr4),
}
]
);
}

View File

@ -267,6 +267,7 @@ fn binary_operator(i: TokenSlice) -> PResult<BinaryOperator> {
"/" => BinaryOperator::Div,
"*" => BinaryOperator::Mul,
"%" => BinaryOperator::Mod,
"^" => BinaryOperator::Pow,
_ => {
return Err(KclError::Syntax(KclErrorDetails {
source_ranges: token.as_source_ranges(),