private static void CompileAssignment(LightCompiler compiler, MSAst.Expression variable, Action<LightCompiler> compileValue) {
var instructions = compiler.Instructions;
ClosureExpression closure = variable as ClosureExpression;
if (closure != null) {
compiler.Compile(closure.ClosureCell);
}
LookupGlobalVariable lookup = variable as LookupGlobalVariable;
if (lookup != null) {
compiler.Compile(lookup.CodeContext);
instructions.EmitLoad(lookup.Name);
}
compileValue(compiler);
if (closure != null) {
instructions.EmitStoreField(ClosureExpression._cellField);
return;
}
if (lookup != null) {
instructions.EmitCall(typeof(PythonOps).GetMethod(lookup.IsLocal ? "SetLocal" : "SetGlobal"));
return;
}
MSAst.ParameterExpression functionValueParam = variable as MSAst.ParameterExpression;
if (functionValueParam != null) {
instructions.EmitStoreLocal(compiler.Locals.GetLocalIndex(functionValueParam));
return;
}
var globalVar = variable as PythonGlobalVariableExpression;
if (globalVar != null) {
instructions.Emit(new PythonSetGlobalInstruction(globalVar.Global));
instructions.EmitPop();
return;
}
Debug.Assert(false, "Unsupported variable type for light compiling function");
}