本文整理汇总了C#中Compiler.LoadValue方法的典型用法代码示例。如果您正苦于以下问题:C# Compiler.LoadValue方法的具体用法?C# Compiler.LoadValue怎么用?C# Compiler.LoadValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Compiler
的用法示例。
在下文中一共展示了Compiler.LoadValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmitRead
protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
using (Compiler.Local oldValue = ctx.GetLocalWithValue(expectedType, valueFrom))
using (Compiler.Local token = new Compiler.Local(ctx, ctx.MapType(typeof(SubItemToken))))
using (Compiler.Local field = new Compiler.Local(ctx, ctx.MapType(typeof(int))))
{
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("StartSubItem"));
ctx.StoreValue(token);
Compiler.CodeLabel next = ctx.DefineLabel(), processField = ctx.DefineLabel(), end = ctx.DefineLabel();
ctx.MarkLabel(next);
ctx.EmitBasicRead("ReadFieldHeader", ctx.MapType(typeof(int)));
ctx.CopyValue();
ctx.StoreValue(field);
ctx.LoadValue(Tag); // = 1 - process
ctx.BranchIfEqual(processField, true);
ctx.LoadValue(field);
ctx.LoadValue(1); // < 1 - exit
ctx.BranchIfLess(end, false);
// default: skip
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("SkipField"));
ctx.Branch(next, true);
// process
ctx.MarkLabel(processField);
if (Tail.RequiresOldValue)
{
if (Helpers.IsValueType(expectedType))
{
ctx.LoadAddress(oldValue, expectedType);
ctx.EmitCall(expectedType.GetMethod("GetValueOrDefault", Helpers.EmptyTypes));
}
else
{
ctx.LoadValue(oldValue);
}
}
Tail.EmitRead(ctx, null);
// note we demanded always returns a value
if (Helpers.IsValueType(expectedType))
{
ctx.EmitCtor(expectedType, Tail.ExpectedType); // re-nullable<T> it
}
ctx.StoreValue(oldValue);
ctx.Branch(next, false);
// outro
ctx.MarkLabel(end);
ctx.LoadValue(token);
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("EndSubItem"));
ctx.LoadValue(oldValue); // load the old value
}
}
示例2: EmitDedicatedMethod
bool EmitDedicatedMethod(Compiler.CompilerContext ctx, Compiler.Local valueFrom, bool read)
{
System.Reflection.Emit.MethodBuilder method = ctx.GetDedicatedMethod(key, read);
if (method == null) return false;
using (Compiler.Local token = new ProtoBuf.Compiler.Local(ctx, typeof(SubItemToken)))
{
Type rwType = read ? typeof(ProtoReader) : typeof(ProtoWriter);
ctx.LoadValue(valueFrom);
if (!read) // write requires the object for StartSubItem; read doesn't
{
if (type.IsValueType) { ctx.LoadNullRef(); }
else { ctx.CopyValue(); }
}
ctx.LoadReaderWriter();
ctx.EmitCall(rwType.GetMethod("StartSubItem"));
ctx.StoreValue(token);
// note: value already on the stack
ctx.LoadReaderWriter();
ctx.EmitCall(method);
// handle inheritance (we will be calling the *base* version of things,
// but we expect Read to return the "type" type)
if (read && type != method.ReturnType) ctx.Cast(this.type);
ctx.LoadValue(token);
ctx.LoadReaderWriter();
ctx.EmitCall(rwType.GetMethod("EndSubItem"));
}
return true;
}
示例3: EmitWrite
protected override void EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
ctx.LoadValue((int)fieldNumber);
ctx.LoadValue((int)wireType);
ctx.LoadReaderWriter();
ctx.EmitCall(typeof(ProtoWriter).GetMethod("WriteFieldHeader"));
Tail.EmitWrite(ctx, valueFrom);
}
示例4: EmitWrite
public void EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
ctx.LoadValue(valueFrom);
ctx.CastToObject(type);
ctx.LoadReaderWriter();
ctx.LoadValue(ctx.MapMetaKeyToCompiledKey(key));
ctx.LoadValue((int)options);
ctx.EmitCall(ctx.MapType(typeof(BclHelpers)).GetMethod("WriteNetObject"));
}
示例5: EmitRead
public void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
ctx.LoadValue(valueFrom);
ctx.CastToObject(type);
ctx.LoadReaderWriter();
ctx.LoadValue(ctx.MapMetaKeyToCompiledKey(key));
if (type == ctx.MapType(typeof(object))) ctx.LoadNullRef();
else ctx.LoadValue(type);
ctx.LoadValue((int)options);
ctx.EmitCall(ctx.MapType(typeof(BclHelpers)).GetMethod("ReadNetObject"));
ctx.CastFromObject(type);
}
示例6: EmitRead
protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
bool writeValue;
SanityCheck(property, Tail, out writeValue, ctx.NonPublic);
if (ExpectedType.IsValueType && valueFrom == null)
{
throw new InvalidOperationException("Attempt to mutate struct on the head of the stack; changes would be lost");
}
ctx.LoadAddress(valueFrom, ExpectedType); // stack is: old-addr
if (writeValue && Tail.RequiresOldValue)
{ // need to read and write
ctx.CopyValue();
}
// stack is: [old-addr]|old-addr
if (Tail.RequiresOldValue)
{
ctx.LoadValue(property); // stack is: [old-addr]|old-value
}
ctx.ReadNullCheckedTail(property.PropertyType, Tail, null); // stack is [old-addr]|[new-value]
if (writeValue)
{ // stack is old-addr|new-value
ctx.StoreValue(property);
}
else
{ // don't want return value; drop it if anything there
// stack is [new-value]
if (Tail.ReturnsValue) { ctx.DiscardValue(); }
}
}
示例7: EmitWriteArrayLoop
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);
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);
}
示例8: using
void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
Helpers.DebugAssert(valueFrom != null); // don't support stack-head for this
using (Compiler.Local converted = new Compiler.Local(ctx, tail.ExpectedType)) // declare/re-use local
{
ctx.LoadValue(valueFrom); // load primary onto stack
ctx.EmitCall(toTail); // static convert op, primary-to-surrogate
ctx.StoreValue(converted); // store into surrogate local
tail.EmitRead(ctx, converted); // downstream processing against surrogate local
ctx.LoadValue(converted); // load from surrogate local
ctx.EmitCall(fromTail); // static convert op, surrogate-to-primary
ctx.StoreValue(valueFrom); // store back into primary
}
}
示例9: EmitRead
public void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
ctx.LoadValue(valueFrom);
ctx.CastToObject(type);
ctx.LoadReaderWriter();
ctx.LoadValue(key);
if (type == typeof(object))
{
ctx.LoadNullRef();
}
else
{
ctx.LoadValue(type);
}
ctx.LoadValue((int)options);
ctx.EmitCall(typeof(BclHelpers).GetMethod("ReadNetObject"));
ctx.CastFromObject(type);
}
示例10: EmitRead
protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
using (Compiler.Local loc = ctx.GetLocalWithValue(ExpectedType, valueFrom))
{
if (Tail.RequiresOldValue)
{
ctx.LoadAddress(loc, ExpectedType);
ctx.LoadValue(field);
}
// value is either now on the stack or not needed
ctx.ReadNullCheckedTail(field.FieldType, Tail, null);
if (Tail.ReturnsValue)
{
using (Compiler.Local newVal = new Compiler.Local(ctx, field.FieldType))
{
ctx.StoreValue(newVal);
if (Helpers.IsValueType(field.FieldType))
{
ctx.LoadAddress(loc, ExpectedType);
ctx.LoadValue(newVal);
ctx.StoreValue(field);
}
else
{
Compiler.CodeLabel allDone = ctx.DefineLabel();
ctx.LoadValue(newVal);
ctx.BranchIfFalse(allDone, true); // interpret null as "don't assign"
ctx.LoadAddress(loc, ExpectedType);
ctx.LoadValue(newVal);
ctx.StoreValue(field);
ctx.MarkLabel(allDone);
}
}
}
}
}
示例11:
void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
if (overwriteList)
{
ctx.LoadNullRef();
}
else
{
ctx.LoadValue(valueFrom);
}
ctx.LoadReaderWriter();
ctx.EmitCall(typeof(ProtoReader).GetMethod("AppendBytes"));
}
示例12: EmitRead
protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
if (setSpecified == null)
{
Tail.EmitRead(ctx, valueFrom);
return;
}
using (Compiler.Local loc = ctx.GetLocalWithValue(ExpectedType, valueFrom))
{
Tail.EmitRead(ctx, loc);
ctx.LoadAddress(loc, ExpectedType);
ctx.LoadValue(1); // true
ctx.EmitCall(setSpecified);
}
}
示例13: EmitRead
protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
Tail.EmitRead(ctx, valueFrom);
ctx.CopyValue();
Compiler.CodeLabel @nonEmpty = ctx.DefineLabel(), @end = ctx.DefineLabel();
ctx.LoadValue(typeof(string).GetProperty("Length"));
ctx.BranchIfTrue(@nonEmpty, true);
ctx.DiscardValue();
ctx.LoadNullRef();
ctx.Branch(@end, true);
ctx.MarkLabel(@nonEmpty);
ctx.EmitCtor(typeof(Uri), typeof(string));
ctx.MarkLabel(@end);
}
示例14: EmitRead
protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
using (Compiler.Local loc = ctx.GetLocalWithValue(ExpectedType, valueFrom))
{
ctx.LoadAddress(loc, ExpectedType);
if (Tail.RequiresOldValue)
{
ctx.CopyValue();
ctx.LoadValue(field);
}
// value is either now on the stack or not needed
ctx.ReadNullCheckedTail(field.FieldType, Tail, null);
// stack is now the return value
ctx.StoreValue(field);
}
}
示例15: EmitRead
protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
using (Compiler.Local loc = ctx.GetLocalWithValue(ExpectedType, valueFrom))
{
ctx.LoadAddress(loc, ExpectedType);
if (Tail.RequiresOldValue)
{
ctx.CopyValue();
ctx.LoadValue(field);
}
// value is either now on the stack or not needed
ctx.ReadNullCheckedTail(field.FieldType, Tail, null);
if (Tail.ReturnsValue)
{
if (field.FieldType.IsValueType)
{
// stack is now the return value
ctx.StoreValue(field);
}
else
{
Compiler.CodeLabel hasValue = ctx.DefineLabel(), allDone = ctx.DefineLabel();
ctx.CopyValue();
ctx.BranchIfTrue(hasValue, true); // interpret null as "don't assign"
// no value, discard
ctx.DiscardValue();
ctx.DiscardValue();
ctx.Branch(allDone, true);
ctx.MarkLabel(hasValue);
ctx.StoreValue(field);
ctx.MarkLabel(allDone);
}
}
else
{
ctx.DiscardValue();
}
}
}