Skip to content

Commit 764e0af

Browse files
committed
Emit CallFunctionKw from compiler for kwarg calls
1 parent b466292 commit 764e0af

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

vm/src/bytecode.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ pub enum Instruction {
100100
CallFunction {
101101
count: usize,
102102
},
103+
CallFunctionKw {
104+
count: usize,
105+
},
103106
ForIter,
104107
ReturnValue,
105108
SetupLoop {

vm/src/compile.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -628,10 +628,25 @@ impl Compiler {
628628
ast::Expression::Call { function, args } => {
629629
self.compile_expression(&*function);
630630
let count = args.len();
631-
for (_, arg) in args {
632-
self.compile_expression(arg)
631+
let mut kwarg_names = vec![];
632+
for (kwarg, value) in args {
633+
if let Some(kwarg) = kwarg {
634+
kwarg_names.push(bytecode::Constant::String {
635+
value: kwarg.to_string(),
636+
});
637+
};
638+
self.compile_expression(value);
639+
}
640+
if kwarg_names.len() > 0 {
641+
self.emit(Instruction::LoadConst {
642+
value: bytecode::Constant::Tuple {
643+
elements: kwarg_names,
644+
},
645+
});
646+
self.emit(Instruction::CallFunctionKw { count });
647+
} else {
648+
self.emit(Instruction::CallFunction { count });
633649
}
634-
self.emit(Instruction::CallFunction { count: count });
635650
}
636651
ast::Expression::BoolOp { .. } => {
637652
self.compile_test(expression, None, None, EvalContext::Expression)

vm/src/vm.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,9 @@ impl VirtualMachine {
839839
}
840840
}
841841
}
842+
bytecode::Instruction::CallFunctionKw { count: _ } => {
843+
unimplemented!("keyword arg calls not yet implemented");
844+
}
842845
bytecode::Instruction::Jump { target } => {
843846
self.jump(target);
844847
None

0 commit comments

Comments
 (0)