Emit CallFunctionKw from compiler for kwarg calls

This commit is contained in:
Daniel Watkins
2018-08-29 18:50:11 -04:00
parent b4662925b7
commit 764e0af433
3 changed files with 24 additions and 3 deletions

View File

@@ -100,6 +100,9 @@ pub enum Instruction {
CallFunction {
count: usize,
},
CallFunctionKw {
count: usize,
},
ForIter,
ReturnValue,
SetupLoop {

View File

@@ -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)

View File

@@ -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