public static void EmitStore(this ILocalRef localRef, IBlockContext context)
        {
            switch (localRef.LocalIndex)
            {
            case 0:
                context.IL.Emit(OpCodes.Stloc_0);
                return;

            case 1:
                context.IL.Emit(OpCodes.Stloc_1);
                return;

            case 2:
                context.IL.Emit(OpCodes.Stloc_2);
                return;

            case 3:
                context.IL.Emit(OpCodes.Stloc_3);
                return;

            case { } n when n < 256:
                context.IL.Emit(OpCodes.Stloc_S, localRef);
                return;

            default:
                context.IL.Emit(OpCodes.Stloc, localRef);
                return;
            }
        }
 public DeclaredVariable(string name, bool isConst, RealizedType type, ILocalRef localRef)
 {
     Name          = name;
     IsConst       = isConst;
     Type          = type;
     this.localRef = localRef;
 }
Beispiel #3
0
 public void Emit(OpCode opCode, ILocalRef localBuilder)
 {
     ilSize += InstructionSize.Get(opCode);
     AdjustStack(opCode);
     commands.Add(new ILCommand {
         opCode = opCode, args = $"<local>{localBuilder.LocalIndex}"
     });
 }
 internal AsyncResume(LabelRef resumeLabel, LabelRef pollLabel, FieldInfo futureField,
                      ILocalRef futureResultVar)
 {
     this.resumeLabel     = resumeLabel;
     this.pollLabel       = pollLabel;
     this.futureField     = futureField;
     this.futureResultVar = futureResultVar;
 }
 public static void EmitLoadPtr(this ILocalRef localRef, IBlockContext context)
 {
     if (localRef.LocalIndex < 256)
     {
         context.IL.Emit(OpCodes.Ldloca_S, localRef);
     }
     else
     {
         context.IL.Emit(OpCodes.Ldloca, localRef);
     }
 }
Beispiel #6
0
 public void EmitInitialize(IBlockContext context)
 {
     rangeRef = context.DeclareHiddenLocal(typeof(Range));
     rangeRef.EmitStore(context);
     currentIndex = context.DeclareHiddenLocal(typeof(long));
     rangeRef.EmitLoad(context);
     context.IL.Emit(OpCodes.Ldfld, typeof(Range).GetField("from"));
     context.IL.Emit(OpCodes.Ldc_I4_1);
     context.IL.Emit(OpCodes.Conv_I8);
     context.IL.Emit(OpCodes.Sub);
     currentIndex.EmitStore(context);
 }
Beispiel #7
0
        public override void Prepare(IBlockContext context)
        {
            if (preparedResult != null)
            {
                return;
            }

            TO2Type targetType = target.ResultType(context);
            IMethodInvokeEmitter methodInvoker = targetType.FindMethod(context.ModuleContext, methodName)
                                                 ?.Create(context, arguments.Select(arg => arg.ResultType(context)).ToList(), this);

            if (methodInvoker == null || !methodInvoker.IsAsync || !context.IsAsync)
            {
                return;
            }

            EmitCode(context, false);
            preparedResult = context.DeclareHiddenLocal(methodInvoker.ResultType.GeneratedType(context.ModuleContext));
            preparedResult.EmitStore(context);
        }
Beispiel #8
0
        public override void EmitCode(IBlockContext context, bool dropResult)
        {
            if (preparedResult != null)
            {
                if (!dropResult)
                {
                    preparedResult.EmitLoad(context);
                }
                preparedResult = null;
                return;
            }

            TO2Type targetType          = target.ResultType(context);
            IMethodInvokeFactory method = targetType.FindMethod(context.ModuleContext, methodName);

            if (method != null)
            {
                EmitCodeMethodCall(context, targetType, method, dropResult);
                return;
            }

            IFieldAccessFactory field = targetType.FindField(context.ModuleContext, methodName);

            if (field != null)
            {
                EmitCodeDelegateCall(context, targetType, field, dropResult);
                return;
            }

            context.AddError(new StructuralError(
                                 StructuralError.ErrorType.NoSuchMethod,
                                 $"Type '{targetType.Name}' does not have a method or field '{methodName}'",
                                 Start,
                                 End
                                 ));
        }
 public void Emit(OpCode opCode, ILocalRef localBuilder)
 {
     ilSize += InstructionSize.Get(opCode);
     AdjustStack(opCode);
 }
 internal StateRef(ILocalRef localRef, FieldInfo storageField)
 {
     this.localRef     = localRef;
     this.storageField = storageField;
 }
 public void Emit(OpCode opCode, ILocalRef localRef)
 {
     generator.Emit(opCode, ((LocalBuilderRef)localRef).localBuilder);
     AdjustStack(opCode);
 }