private void EmitStelem(ILProcessor processor, TypeReference elementType, IAstExpression element, CilCompilationContext context) { if (elementType.IsPrimitive) { if (!StelemCodes.ContainsKey(elementType.MetadataType)) { throw new NotImplementedException("ListInitializerCompiler.EmitStelem: Element metadata type " + elementType.MetadataType + " is not yet supported."); } context.Compile(element); processor.Emit(StelemCodes[elementType.MetadataType]); return; } if (elementType.IsValueType) { processor.Emit(OpCodes.Ldelema, elementType); context.Compile(element); processor.Emit(OpCodes.Stobj, elementType); return; } context.Compile(element); processor.Emit(OpCodes.Stelem_Ref); }
public override void Compile(ILProcessor processor, BinaryExpression binary, CilCompilationContext context) { var builtIn = binary.Operator as AstBuiltInOperator; if (builtIn != null) { context.Compile(binary.Left); context.Compile(binary.Right); EmitBuiltInOperator(processor, builtIn); return; } context.Compile(binary.Left); context.Compile(binary.Right); processor.Emit(OpCodes.Call, context.ConvertReference(binary.Operator)); }
private void CompileFieldOrPropertyAssignment(ILProcessor processor, AstPropertyExpression property, IAstExpression value, CilCompilationContext context) { processor.Emit(OpCodes.Ldarg_0); context.Compile(value); var fieldOrProperty = context.ConvertReference(property.Reference); var field = fieldOrProperty.As <FieldReference>(); if (field == null) { throw new NotImplementedException("AssignmentCompiler: Assignment to " + fieldOrProperty + " is not yet supported."); } processor.Emit(OpCodes.Stfld, field); }
public override void Compile(ILProcessor processor, AstVariableDefinition variable, CilCompilationContext context) { var variableDefinition = context.DefineVariable(variable.Name, variable.Type); context.MapDefinition(variable, variableDefinition); if (variable.AssignedValue == null) { return; } context.Compile(variable.AssignedValue); processor.Emit(OpCodes.Stloc, variableDefinition); }
public static void CompileTarget(ILProcessor processor, IAstExpression target, IAstMethodReference function, CilCompilationContext context) { context.Compile(target); if (function.Location == MethodLocation.Extension) return; var targetType = context.ConvertReference(target.ExpressionType); if (!targetType.IsValueType) return; var variable = context.DefineVariable("x", targetType); processor.Emit(OpCodes.Stloc, variable); processor.Emit(OpCodes.Ldloca_S, variable); }
public override void Compile(ILProcessor processor, AstFunctionReferenceExpression reference, CilCompilationContext context) { if (reference.Target != null && !(reference.Target is IAstTypeReference)) { context.Compile(reference.Target); } else { processor.Emit(OpCodes.Ldnull); } var delegateType = context.ConvertReference(reference.ExpressionType); var delegateConstructor = context.Method.Module.Import(delegateType.Resolve().Methods.Single(m => m.Name == ".ctor")); delegateConstructor.DeclaringType = delegateType; // fixes issue with delegateType.Resolve() eliminating generic arguments processor.Emit(OpCodes.Ldftn, context.ConvertReference(reference.Function)); processor.Emit(OpCodes.Newobj, delegateConstructor); }
public static void CompileTarget(ILProcessor processor, IAstExpression target, IAstMethodReference function, CilCompilationContext context) { context.Compile(target); if (function.Location == MethodLocation.Extension) { return; } var targetType = context.ConvertReference(target.ExpressionType); if (!targetType.IsValueType) { return; } var variable = context.DefineVariable("x", targetType); processor.Emit(OpCodes.Stloc, variable); processor.Emit(OpCodes.Ldloca_S, variable); }
public override void Compile(ILProcessor processor, AstPropertyExpression expression, CilCompilationContext context) { if (expression.Target != null) { context.Compile(expression.Target); } var fieldOrProperty = context.ConvertReference(expression.Reference); var field = fieldOrProperty.As <FieldReference>(); if (field != null) { processor.Emit(OpCodes.Ldfld, field); return; } var property = (PropertyReferenceContainer)fieldOrProperty; processor.Emit(OpCodes.Call, property.GetMethod); }
public override void Compile(ILProcessor processor, CallExpression call, CilCompilationContext context) { var function = call.Callee as AstFunctionReferenceExpression; if (function == null) { throw new NotImplementedException("CallCompiler: " + call.Callee.GetType().Name + " is not yet supported as call.Callee."); } if (function.Target != null && !(function.Target is IAstTypeReference)) { CallCompilerHelper.CompileTarget(processor, (IAstExpression)function.Target, function.Function, context); } foreach (var argument in call.Arguments) { context.Compile(argument); } processor.Emit(OpCodes.Call, context.ConvertReference(function.Function)); }