public override void OutputSet(NitroIL into,Type setting){ if(VariableType==null){ VariableType=setting; }else if(setting!=VariableType){ // Overwriting the variable with something of a different type. Create a new one. VariableType=setting; Builder=null; } if(VariableType==null){ VariableType=typeof(object); } if(Builder==null){ Builder=into.DeclareLocal(VariableType); } into.Emit(OpCodes.Stloc,Builder); }
public override void OutputSet(NitroIL into, Type setting) { if (VariableType == null) { VariableType = setting; } else if (setting != VariableType && setting != null) { // Overwriting the variable with something of a different type. Create a new one. VariableType = setting; Builder = null; } if (VariableType == null) { VariableType = typeof(object); } if (Builder == null) { Builder = into.DeclareLocal(VariableType); } into.Emit(OpCodes.Stloc, Builder); }
public override void OutputIL(NitroIL into) { GetMethodInfo(); // First, the instance this method is on: bool useVirtual = (CalledOn != null); if (useVirtual) { Type type = CalledOn.OutputType(out CalledOn); CalledOn.OutputIL(into); if (type.IsValueType) { if (!CalledOn.EmitsAddress) { // Value must be set into a temporary local and reloaded (but as an address). // Future optimization may be to pool these. LocalBuilder builder = into.DeclareLocal(type); into.Emit(OpCodes.Stloc, builder); into.Emit(OpCodes.Ldloca, builder); } useVirtual = false; } } // Next, its arguments: if (Types.IsDynamic(MethodToCall)) { if (Arguments != null) { for (int i = 0; i < Arguments.Length; i++) { Arguments[i].OutputIL(into); } } } else { Types.OutputParameters(Arguments, Method, into, MethodToCall.GetParameters()); } // And emit the call: if (useVirtual) { into.Emit(OpCodes.Callvirt, MethodToCall); } else { into.Emit(OpCodes.Call, MethodToCall); } }
public override void OutputIL(NitroIL into) { if (Size != null) { Size.OutputIL(into); } else { into.Emit(OpCodes.Ldc_I4, DirectSize); } Type ElementType = ArrayType.GetElementType(); into.Emit(OpCodes.Newarr, ElementType); if (DefaultValues == null || DefaultValues.Length == 0) { return; } LocalBuilder temp = into.DeclareLocal(ArrayType); into.Emit(OpCodes.Stloc, temp); // Emit a series of SET's into the array. for (int i = 0; i < DefaultValues.Length; i++) { into.Emit(OpCodes.Ldloc, temp); into.Emit(OpCodes.Ldc_I4, i); DefaultValues[i].OutputIL(into); if (ElementType.IsValueType) { into.Emit(OpCodes.Stelem, ElementType); } else { into.Emit(OpCodes.Stelem_Ref); } } into.Emit(OpCodes.Ldloc, temp); }
public CompiledMethod(CompiledClass parent, string name, BracketFragment parameterBlock, BracketFragment codeBlock, TypeFragment retType, bool isPublic) { Name = name; Parent = parent; CodeBlock = codeBlock; Script = Parent.Script; ParameterBlock = parameterBlock; Type returnType = null; if (retType != null) { returnType = retType.FindType(Script); if (returnType == null) { Error("Type '" + retType.Value + "' was not found."); } } string methodName = Name; MethodAttributes attrib = isPublic?MethodAttributes.Public:MethodAttributes.Private; if (methodName == "new") { methodName = ".ctor"; attrib |= MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName; } // Does the parent base type define this method? // If so, use it's name. Type baseType = Parent.Builder.BaseType; // Parse the parameter set right away: ParseParameters(); MethodInfo mInfo = Types.GetOverload(baseType.GetMethods(), Name, ParameterTypes, true); if (mInfo != null) { methodName = mInfo.Name; attrib |= MethodAttributes.Virtual | MethodAttributes.HideBySig; //|MethodAttributes.NewSlot; } bool isVoid = Types.IsVoid(returnType); if (isVoid) { returnType = typeof(void); } Builder = Parent.Builder.DefineMethod( methodName, attrib, returnType, null ); ApplyParameters(); ILStream = new NitroIL(Builder.GetILGenerator()); EndOfMethod = ILStream.DefineLabel(); if (!isVoid) { ReturnBay = ILStream.DeclareLocal(returnType); } }
public override void OutputIL(NitroIL into){ if(Size!=null){ Size.OutputIL(into); }else{ into.Emit(OpCodes.Ldc_I4,DirectSize); } Type ElementType=ArrayType.GetElementType(); into.Emit(OpCodes.Newarr,ElementType); if(DefaultValues==null || DefaultValues.Length==0){ return; } LocalBuilder temp=into.DeclareLocal(ArrayType); into.Emit(OpCodes.Stloc,temp); // Emit a series of SET's into the array. for(int i=0;i<DefaultValues.Length;i++){ into.Emit(OpCodes.Ldloc,temp); into.Emit(OpCodes.Ldc_I4,i); DefaultValues[i].OutputIL(into); if(ElementType.IsValueType){ into.Emit(OpCodes.Stelem,ElementType); }else{ into.Emit(OpCodes.Stelem_Ref); } } into.Emit(OpCodes.Ldloc,temp); }
public override void OutputIL(NitroIL into){ GetMethodInfo(); // First, the instance this method is on: bool useVirtual=(CalledOn!=null); if(useVirtual){ Type type=CalledOn.OutputType(out CalledOn); CalledOn.OutputIL(into); if(type.IsValueType){ if(!CalledOn.EmitsAddress){ // Value must be set into a temporary local and reloaded (but as an address). // Future optimization may be to pool these. LocalBuilder builder=into.DeclareLocal(type); into.Emit(OpCodes.Stloc,builder); into.Emit(OpCodes.Ldloca,builder); } useVirtual=false; } } // Next, its arguments: if(Types.IsDynamic(MethodToCall)){ if(Arguments!=null){ for(int i=0;i<Arguments.Length;i++){ Arguments[i].OutputIL(into); } } }else{ Types.OutputParameters(Arguments,Method,into,MethodToCall.GetParameters()); } // And emit the call: if(useVirtual){ into.Emit(OpCodes.Callvirt,MethodToCall); }else{ into.Emit(OpCodes.Call,MethodToCall); } }
public CompiledMethod(CompiledClass parent,string name,BracketFragment parameterBlock,BracketFragment codeBlock,TypeFragment retType,bool isPublic){ Name=name; Parent=parent; CodeBlock=codeBlock; Script=Parent.Script; ParameterBlock=parameterBlock; Type returnType=null; if(retType!=null){ returnType=retType.FindType(Script); if(returnType==null){ Error("Type '"+retType.Value+"' was not found."); } } string methodName=Name; MethodAttributes attrib=isPublic?MethodAttributes.Public:MethodAttributes.Private; if(methodName=="new"){ methodName=".ctor"; attrib|=MethodAttributes.HideBySig|MethodAttributes.SpecialName|MethodAttributes.RTSpecialName; } // Does the parent base type define this method? // If so, use it's name. Type baseType=Parent.Builder.BaseType; // Parse the parameter set right away: ParseParameters(); MethodInfo mInfo=Types.GetOverload(baseType.GetMethods(),Name,ParameterTypes,true); if(mInfo!=null){ methodName=mInfo.Name; attrib|=MethodAttributes.Virtual|MethodAttributes.HideBySig;//|MethodAttributes.NewSlot; } bool isVoid=Types.IsVoid(returnType); if(isVoid){ returnType=typeof(void); } Builder=Parent.Builder.DefineMethod( methodName, attrib, returnType, null ); ApplyParameters(); ILStream=new NitroIL(Builder.GetILGenerator()); EndOfMethod=ILStream.DefineLabel(); if(!isVoid){ ReturnBay=ILStream.DeclareLocal(returnType); } }