mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Emit CallFunctionKw from compiler for kwarg calls
This commit is contained in:
@@ -100,6 +100,9 @@ pub enum Instruction {
|
||||
CallFunction {
|
||||
count: usize,
|
||||
},
|
||||
CallFunctionKw {
|
||||
count: usize,
|
||||
},
|
||||
ForIter,
|
||||
ReturnValue,
|
||||
SetupLoop {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user