diff --git a/vm/src/bytecode.rs b/vm/src/bytecode.rs index 4d58d6601..b61eb0b38 100644 --- a/vm/src/bytecode.rs +++ b/vm/src/bytecode.rs @@ -100,6 +100,9 @@ pub enum Instruction { CallFunction { count: usize, }, + CallFunctionKw { + count: usize, + }, ForIter, ReturnValue, SetupLoop { diff --git a/vm/src/compile.rs b/vm/src/compile.rs index 0e81562a2..b460e6f91 100644 --- a/vm/src/compile.rs +++ b/vm/src/compile.rs @@ -628,10 +628,25 @@ impl Compiler { ast::Expression::Call { function, args } => { self.compile_expression(&*function); let count = args.len(); - for (_, arg) in args { - self.compile_expression(arg) + let mut kwarg_names = vec![]; + for (kwarg, value) in args { + if let Some(kwarg) = kwarg { + kwarg_names.push(bytecode::Constant::String { + value: kwarg.to_string(), + }); + }; + self.compile_expression(value); + } + if kwarg_names.len() > 0 { + self.emit(Instruction::LoadConst { + value: bytecode::Constant::Tuple { + elements: kwarg_names, + }, + }); + self.emit(Instruction::CallFunctionKw { count }); + } else { + self.emit(Instruction::CallFunction { count }); } - self.emit(Instruction::CallFunction { count: count }); } ast::Expression::BoolOp { .. } => { self.compile_test(expression, None, None, EvalContext::Expression) diff --git a/vm/src/vm.rs b/vm/src/vm.rs index 86be94b33..fac5e0008 100644 --- a/vm/src/vm.rs +++ b/vm/src/vm.rs @@ -839,6 +839,9 @@ impl VirtualMachine { } } } + bytecode::Instruction::CallFunctionKw { count: _ } => { + unimplemented!("keyword arg calls not yet implemented"); + } bytecode::Instruction::Jump { target } => { self.jump(target); None