private void EmitWriteArrayLoop(Compiler.CompilerContext ctx, Compiler.Local i, Compiler.Local arr) { // i = 0 ctx.LoadValue(0); ctx.StoreValue(i); // range test is last (to minimise branches) Compiler.CodeLabel loopTest = ctx.DefineLabel(), processItem = ctx.DefineLabel(); ctx.Branch(loopTest, false); ctx.MarkLabel(processItem); // {...} ctx.LoadArrayValue(arr, i); if (SupportNull) { Tail.EmitWrite(ctx, null); } else { ctx.WriteNullCheckedTail(itemType, Tail, null); } // i++ ctx.LoadValue(i); ctx.LoadValue(1); ctx.Add(); ctx.StoreValue(i); // i < arr.Length ctx.MarkLabel(loopTest); ctx.LoadValue(i); ctx.LoadLength(arr, false); ctx.BranchIfLess(processItem, false); }
public void EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom) { using (Compiler.Local loc = ctx.GetLocalWithValue(ctor.DeclaringType, valueFrom)) { for (int i = 0; i < tails.Length; i++) { Type type = GetMemberType(i); ctx.LoadAddress(loc, ExpectedType); if (members[i] is FieldInfo) { ctx.LoadValue((FieldInfo)members[i]); } else if (members[i] is PropertyInfo) { ctx.LoadValue((PropertyInfo)members[i]); } ctx.WriteNullCheckedTail(type, tails[i], null); } } }
protected override void EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom) { ctx.LoadAddress(valueFrom, ExpectedType); ctx.LoadValue(property); ctx.WriteNullCheckedTail(property.PropertyType, Tail, null); }
public void EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom) { Compiler.CodeLabel @end = ctx.DefineLabel(); using (Compiler.Local value = ctx.GetLocalWithValue(ctor.DeclaringType, valueFrom)) { if (!baseTupleAsReference && asReference) { using (Compiler.Local existing = new Compiler.Local(ctx, typeof(bool))) using (Compiler.Local tupleKey = new Compiler.Local(ctx, typeof(int))) { //int tupleKey = dest.NetCache.AddObjectKey(value, out existing); ctx.LoadReaderWriter(); ctx.LoadValue(typeof(ProtoWriter).GetProperty("NetCache")); ctx.LoadValue(value); ctx.CastToObject(ctor.DeclaringType); // HACK : doesn't seem to get boxed from ctx.GetLocalWithValue ctx.LoadAddress(existing, typeof(bool)); ctx.EmitCall(typeof(NetObjectCache).GetMethod("AddObjectKey", new Type[] { typeof(object), typeof(bool).MakeByRefType() })); ctx.StoreValue(tupleKey); //ProtoWriter.WriteUInt32(existing ? (uint) tupleKey : 0, dest); Compiler.CodeLabel @continueBranch = ctx.DefineLabel(); ctx.LoadValue(0); ctx.LoadValue(existing); ctx.BranchIfFalse(@continueBranch, true); ctx.DiscardValue(); ctx.LoadValue(tupleKey); //ctx.CastToObject(typeof(uint)); ctx.MarkLabel(@continueBranch); ctx.LoadReaderWriter(); ctx.EmitCall(typeof(ProtoWriter).GetMethod("WriteUInt32")); //if (existing) { return; } ctx.LoadValue(existing); ctx.BranchIfTrue(@end, false); } } for (int i = 0; i < tails.Length; i++) { Type type = GetMemberType(i); ctx.LoadAddress(value, ExpectedType); switch(members[i].MemberType) { case MemberTypes.Field: ctx.LoadValue((FieldInfo)members[i]); break; case MemberTypes.Property: ctx.LoadValue((PropertyInfo)members[i]); break; } ctx.WriteNullCheckedTail(type, tails[i], null); } } if (forceIssueFakeHeader) { ctx.LoadReaderWriter(); ctx.EmitCall(typeof(ProtoWriter).GetMethod("WriteEndGroupFieldHeaderHack")); } ctx.MarkLabel(@end); }