Exemple #1
0
        public void ImplementInCil(CompilerState state, Instruction ins)
        {
            var argc = ins.Arguments;
            if (argc == 0)
                return;

            if (ins.JustEffect)
            {
                state.EmitIgnoreArguments(argc);
            }
            else
            {
                state.EmitIgnoreArguments(argc - 1);
            }
        }
Exemple #2
0
 void ICilCompilerAware.ImplementInCil(CompilerState state, Instruction ins)
 {
     state.EmitIgnoreArguments(ins.Arguments);
     state.Il.Emit(OpCodes.Newobj, _channelCtor);
     PType.PrexoniteObjectTypeProxy._ImplementInCil(state, typeof (Channel));
     state.Il.Emit(OpCodes.Newobj, _newPValue);
 }
Exemple #3
0
 public void Implement(CompilerState state, Instruction ins, CompileTimeValue[] staticArgv,
     int dynamicArgc)
 {
     if (dynamicArgc >= 1)
     {
         state.EmitIgnoreArguments(dynamicArgc - 1);
     }
     else
     {
         staticArgv[0].EmitLoadAsPValue(state);
     }
     state.EmitLoadLocal(state.SctxLocal);
     state.Il.EmitCall(OpCodes.Call, OperationMethod, null);
 }
Exemple #4
0
        public virtual void Implement(CompilerState state, Instruction ins,
            CompileTimeValue[] staticArgv, int dynamicArgc)
        {
            if (dynamicArgc >= 2)
            {
                state.EmitIgnoreArguments(dynamicArgc - 2);
                state.EmitStoreLocal(state.PrimaryTempLocal);
                state.EmitLoadLocal(state.SctxLocal);
                state.EmitLoadLocal(state.PrimaryTempLocal);
            }
            else if (dynamicArgc == 1)
            {
                //we can load the second static arg just where we need it
                state.EmitLoadLocal(state.SctxLocal);
                staticArgv[0].EmitLoadAsPValue(state);
            }
            else
            {
                PValue left;
                PValue right;

                if (staticArgv[0].TryGetConstant(out left)
                    && staticArgv[1].TryGetConstant(out right))
                {
                    //Both operands are constants (remember: static args can also be references)
                    //=> Apply the operator at compile time.
                    var result = Run(state, new[] {left, right});
                    switch (result.Type.ToBuiltIn())
                    {
                        case PType.BuiltIn.Real:
                            state.EmitLoadRealAsPValue((double) result.Value);
                            break;
                        case PType.BuiltIn.Int:
                            state.EmitLoadIntAsPValue((int) result.Value);
                            break;
                        case PType.BuiltIn.String:
                            state.EmitLoadStringAsPValue((string) result.Value);
                            break;
                        case PType.BuiltIn.Null:
                            state.EmitLoadNullAsPValue();
                            break;
                        case PType.BuiltIn.Bool:
                            state.EmitLoadBoolAsPValue((bool) result.Value);
                            break;
                        default:
                            throw new PrexoniteException(
                                string.Format(
                                    "The operation {0} is no implemented correctly. Given {1} and {2} it results in the non-constant {3}",
                                    GetType().FullName, left, right, result));
                    }
                    return; //We've already emitted the result. 
                }
                else
                {
                    //Load the first operand now, then proceed like for just one static arg
                    staticArgv[0].EmitLoadAsPValue(state);
                    state.EmitLoadLocal(state.SctxLocal);
                    staticArgv[1].EmitLoadAsPValue(state);
                }
            }

            state.Il.EmitCall(OpCodes.Call, OperationMethod, null);
        }
Exemple #5
0
		public override void Implement(CompilerState state, Instruction ins, CompileTimeValue[] staticArgv, int dynamicArgc)
		{
			if(dynamicArgc >= 2)
			{
				state.EmitIgnoreArguments(dynamicArgc-2);
			}
			else if(dynamicArgc == 1)
			{
				staticArgv[0].EmitLoadAsPValue(state);
			}
			else
			{
				staticArgv[0].EmitLoadAsPValue(state);
				staticArgv[1].EmitLoadAsPValue(state);
			}
			state.EmitLoadLocal(state.SctxLocal);
            state.Il.EmitCall(System.Reflection.Emit.OpCodes.Call, OperationMethod, null);
		}
Exemple #6
0
        public void ImplementInCil(CompilerState state, Instruction ins)
        {
            var argc = ins.Arguments;
            if (argc > 1)
                state.EmitIgnoreArguments(argc - 1);

            state.EmitLoadLocal(state.SctxLocal);
            if (argc == 0)
                state.EmitLoadNullAsPValue();

            state.EmitCall(_createConstFunction);
        }
Exemple #7
0
 /// <summary>
 ///     Provides a custom compiler routine for emitting CIL byte code for a specific instruction.
 /// </summary>
 /// <param name = "state">The compiler state.</param>
 /// <param name = "ins">The instruction to compile.</param>
 void ICilCompilerAware.ImplementInCil(CompilerState state, Instruction ins)
 {
     var argc = ins.Arguments;
     if (ins.JustEffect)
     {
         state.EmitIgnoreArguments(argc);
     }
     else
     {
         if (argc > 2)
         {
             state.EmitIgnoreArguments(argc - 2);
             argc = 2;
         }
         switch (argc)
         {
             case 0:
                 state.EmitLdcI4(0);
                 state.EmitWrapInt();
                 goto case 1;
             case 1:
                 state.EmitLoadLocal(state.SctxLocal);
                 state.EmitCall(RunStaticallyNaturalMethod);
                 break;
             case 2:
                 state.EmitLoadLocal(state.SctxLocal);
                 state.EmitCall(RunStaticallyAnyMethod);
                 break;
         }
     }
 }