예제 #1
0
 public CacheStructure(TypeStructure rt, ExpressionStructure exp)
     : base(rt)
 {
     Expression = exp;
     Cache = new LocalStructure(Expression.ResultType);
     AppendChild(Expression);
     AppendChild(Cache);
 }
예제 #2
0
 public LoopLocalStructure(string name, TypeStructure dt, CilStructure def)
     : base(dt)
 {
     Name = name;
     DataType = dt;
     DefaultValue = def;
     Local = new LocalStructure(name, dt);
     AppendChild(DefaultValue);
     AppendChild(Local);
 }
예제 #3
0
 internal void BuildCall(CilStructure variant, CodeGenerator cg)
 {
     var b = variant as BuilderStructure;
     if(b != null && BaseInstance != null)
     {
         variant = b.RenewInstance(BaseInstance);
     }
     var f = variant as FieldStructure;
     if(f != null)
     {
         if(f.IsEnumField)
         {
             cg.GeneratePrimitive((dynamic)f.DefaultValue);
         }
         else if (IsStore)
         {
             if(f.IsStatic)
             {
                 cg.GenerateStore(f);
                 cg.GenerateLoad(f);
             }
             else
             {
                 cg.GenerateCode(OpCodes.Dup);
                 var temp = new LocalStructure(f.DataType, cg);
                 cg.GenerateStore(temp);
                 cg.GenerateStore(f);
                 cg.GenerateLoad(temp);
             }
         }
         else
         {
             cg.GenerateLoad(f);
         }
         return;
     }
     var l = variant as LocalStructure;
     if (l != null)
     {
         if (IsStore)
         {
             cg.GenerateStore(l);
         }
         cg.GenerateLoad(l);
         return;
     }
     var p = variant as ParameterStructure;
     if(p != null)
     {
         if (IsStore)
         {
             cg.GenerateStore(p);
         }
         cg.GenerateLoad(p);
         return;
     }
     var lo = variant as LoopLocalStructure;
     if (lo != null)
     {
         if (IsStore)
         {
             cg.GenerateStore(lo.Local);
         }
         cg.GenerateLoad(lo.Local);
         return;
     }
     var v = variant as ValueStructure;
     if(v != null)
     {
         cg.GeneratePrimitive(v.Value);
         return;
     }
     throw new InvalidOperationException();
 }
예제 #4
0
 internal override void BuildCode()
 {
     if(CurrentContainer.IsDataTypeContext)
     {
         return;
     }
     var cg = CurrentContainer.GainGenerator();
     if (Pre != null)
     {
         Pre.BuildCode();
         if (Call is MethodStructure && Pre.ResultType != null)
         {
             cg.GenerateToAddress(Pre.ResultType);
         }
     }
     if (Call == null)
     {
         return;
     }
     if (IsVariadic)
     {
         var arr = new LocalStructure(GetVariadicType(Call), cg);
         cg.GenerateArray(GetVariadicLangth(Call), arr.DataType.GetBaseType());
         cg.GenerateStore(arr);
         var vi = GetVariadicIndex(Call);
         for (var i = 0; i < Arguments.Count; ++i)
         {
             if (i < vi)
             {
                 Arguments[i].BuildCode();
                 if (Converters[i] != null)
                 {
                     Converters[i].BuildCall(cg);
                 }
             }
             else
             {
                 cg.GenerateLoad(arr);
                 cg.GeneratePrimitive(i - vi);
                 Arguments[i].BuildCode();
                 if (Converters[i] != null)
                 {
                     Converters[i].BuildCall(cg);
                 }
                 cg.GenerateToAddress(Arguments[i].ResultType, arr.DataType.GetBaseType());
                 cg.GenerateStoreElement(arr.DataType.GetBaseType());
             }
         }
         cg.GenerateLoad(arr);
     }
     else
     {
         for (var i = 0; i < Arguments.Count; ++i)
         {
             Arguments[i].BuildCode();
             if(Converters[i] != null)
             {
                 Converters[i].BuildCall(cg);
             }
         }
     }
     var lss = Call as LoadStoreStructure;
     var gms = Call as GenericMethodStructure;
     if (lss != null)
     {
         lss.BuildCall(Variant, cg);
     }
     else if(gms != null)
     {
         gms.BuildCall(Variant, cg);
     }
     else
     {
         Call.BuildCall(cg);
     }
 }
예제 #5
0
 internal void GenerateToAddress(TypeStructure from)
 {
     if (from.IsValueType)
     {
         var loc = new LocalStructure(from, this);
         GenerateStore(loc);
         GenerateLoadAddress(loc);
     }
 }
예제 #6
0
 internal void GenerateStore(LocalStructure local)
 {
     var lb = local.GainLocal();
     if (lb.LocalIndex <= 255)
     {
         switch (lb.LocalIndex)
         {
             case 0: Generator.Emit(OpCodes.Stloc_0); break;
             case 1: Generator.Emit(OpCodes.Stloc_1); break;
             case 2: Generator.Emit(OpCodes.Stloc_2); break;
             case 3: Generator.Emit(OpCodes.Stloc_3); break;
             default: Generator.Emit(OpCodes.Stloc_S, lb); break;
         }
     }
     else
     {
         Generator.Emit(OpCodes.Stloc, lb);
     }
 }
예제 #7
0
 internal void GenerateLoadAddress(LocalStructure local)
 {
     var lb = local.GainLocal();
     if (lb.LocalIndex <= 255)
     {
         Generator.Emit(OpCodes.Ldloca_S, lb);
     }
     else
     {
         Generator.Emit(OpCodes.Ldloca, lb);
     }
 }