本文整理汇总了C#中JavaCompiler.Compilation.ByteCode.ByteCodeGenerator.Emit方法的典型用法代码示例。如果您正苦于以下问题:C# ByteCodeGenerator.Emit方法的具体用法?C# ByteCodeGenerator.Emit怎么用?C# ByteCodeGenerator.Emit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JavaCompiler.Compilation.ByteCode.ByteCodeGenerator
的用法示例。
在下文中一共展示了ByteCodeGenerator.Emit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompileReturn
private void CompileReturn(ByteCodeGenerator generator, Type type)
{
var typeCode = TypeCodeHelper.Truncate(PrimativeTypes.TypeCode(type));
switch (typeCode)
{
case ItemTypeCode.Int:
generator.Emit(OpCodeValue.ireturn);
break;
case ItemTypeCode.Long:
generator.Emit(OpCodeValue.lreturn);
break;
case ItemTypeCode.Float:
generator.Emit(OpCodeValue.freturn);
break;
case ItemTypeCode.Double:
generator.Emit(OpCodeValue.dreturn);
break;
case ItemTypeCode.Object:
generator.Emit(OpCodeValue.areturn);
break;
default:
throw new NotImplementedException();
}
}
示例2: CompileNewClass
private static Item CompileNewClass(ByteCodeGenerator generator, NewNode.NewClassNode node)
{
node.Type = ClassLocator.Find(node.GetType(generator), generator.Manager.Imports);
generator.Emit([email protected], generator.Manager.AddConstantClass(node.GetType(generator) as DefinedType));
generator.Emit(OpCodeValue.dup);
new PrimaryCompiler(new PrimaryNode.TermMethodExpression { Identifier = "<init>", Arguments = node.Arguments }).Compile(generator, new StackItem(generator, node.GetType(generator)));
return new StackItem(generator, node.GetType(generator));
}
示例3: Compile
public void Compile(ByteCodeGenerator generator)
{
MethodTreeNode first = tree.FirstOrDefault();
if (first == null)
{
CompileSuperCall(generator);
}
else
{
if (first is PrimaryNode.TermConstructorCallExpression)
{
var call = first as PrimaryNode.TermConstructorCallExpression;
CompileSuperCall(generator, call);
tree.RemoveAt(0);
}
else
{
CompileSuperCall(generator);
}
}
new BlockCompiler(tree).Compile(generator);
generator.Emit([email protected]);
}
示例4: MakeStringBuffer
public static void MakeStringBuffer(ByteCodeGenerator generator, Class sb)
{
var sbInit = (Method)sb.Constructors.First(x => x.Parameters.Count == 0);
var sbIndex = generator.Manager.AddConstantClass(sb);
generator.EmitNew(sbIndex, sb);
generator.Emit(OpCodeValue.dup);
new MemberItem(generator, sbInit, true).Invoke();
}
示例5: CompileDivide
private static void CompileDivide(ByteCodeGenerator generator, Type type)
{
var typeCode = TypeCodeHelper.Truncate(PrimativeTypes.TypeCode(type));
switch (typeCode)
{
case ItemTypeCode.Int:
generator.Emit(OpCodeValue.idiv);
break;
case ItemTypeCode.Long:
generator.Emit(OpCodeValue.ldiv);
break;
case ItemTypeCode.Float:
generator.Emit(OpCodeValue.fdiv);
break;
case ItemTypeCode.Double:
generator.Emit(OpCodeValue.ddiv);
break;
default:
throw new NotImplementedException();
}
}
示例6: CompileAssignOp
private Item CompileAssignOp(ByteCodeGenerator generator)
{
var lType = new TranslateNode { Child = node.Left }.GetType(generator, false, true);
var rType = node.Right.GetType(generator, false, true);
var type = lType.FindCommonType(rType);
Item lhs;
if (lType.Name == BuiltinTypes.String.Name)
{
var sb = BuiltinTypes.StringBuilder;
AdditiveCompiler.MakeStringBuffer(generator, sb);
lhs = new ExpressionCompiler(node.Left).Compile(generator);
if (lhs.Width() > 0)
{
generator.Emit(OpCodeValue.dup_x1 + (byte)(3 * (lhs.Width() - 1)));
}
lhs.Load();
AdditiveCompiler.AppendStrings(generator, sb, node.Left);
AdditiveCompiler.AppendStrings(generator, sb, node.Right.Child);
AdditiveCompiler.BufferToString(generator, sb);
}
else
{
lhs = new ExpressionCompiler(node.Left).Compile(generator);
lhs.Duplicate();
lhs.Coerce(type).Load();
new TranslationCompiler(node.Right, type).Compile(generator).Load();
if (node is AssignmentNode.AddAssignNode)
{
AdditiveCompiler.CompileAddition(generator, type);
}
else if (node is AssignmentNode.MinusAssignNode)
{
AdditiveCompiler.CompileSubtraction(generator, type);
}
else
{
throw new NotImplementedException();
}
}
return new AssignItem(generator, lhs);
}
示例7: Compile
public Item Compile(ByteCodeGenerator generator)
{
if (node.Value == null)
{
if (generator.Method.ReturnType != PrimativeTypes.Void)
{
throw new InvalidOperationException();
}
generator.Emit([email protected]);
return new VoidItem(generator);
}
var value = new TranslationCompiler(node.Value, generator.Method.ReturnType).Compile(generator);
value.Load();
CompileReturn(generator, value.Type);
return new VoidItem(generator);
}
示例8: CompilePostOp
private Item CompilePostOp(ByteCodeGenerator generator, Item item)
{
item.Duplicate();
if (item is LocalItem && TypeCodeHelper.Truncate(item.TypeCode) == ItemTypeCode.Int)
{
//var res = item.Load();
((LocalItem)item).Incr(node is UnaryNode.PostIncNode ? 1 : -1);
//return res;
return item;
}
else
{
var res = item.Load();
item.Stash(item.TypeCode);
generator.Emit(One(item.TypeCode));
if (node is UnaryNode.PostIncNode)
{
generator.Emit(OpAdd(item.Type));
}
else if (node is UnaryNode.PostDecNode)
{
generator.Emit(OpSub(item.Type));
}
var typeCode = TypeCodeHelper.TypeCode(item.Type);
if (item.Type != PrimativeTypes.Int && TypeCodeHelper.Truncate(typeCode) == ItemTypeCode.Int)
{
generator.Emit(OpCodeValue.i2b + (byte)typeCode - (byte)ItemTypeCode.Byte);
}
item.Store();
return res;
}
}
示例9: CompileBody
private void CompileBody(CompileManager manager)
{
attributes = new List<CompileAttribute>();
generator = new ByteCodeGenerator(manager, method);
foreach (Method.Parameter parameter in method.Parameters)
{
generator.DefineVariable(parameter.Name, parameter.Type);
}
new BlockCompiler(method.Body).Compile(generator);
if (method.ReturnType.Name == "void")
{
generator.Emit([email protected]);
}
var code = new CompileAttributeCode
{
NameIndex = manager.AddConstantUtf8(new CompileAttributeCode().Name),
Code = generator.GetBytes(),
Attributes = new List<CompileAttribute>(),
ExceptionTable = new List<CompileAttributeCode.ExceptionTableEntry>(),
MaxLocals = generator.MaxVariables,
MaxStack = generator.MaxStack
};
var stackMapTable = generator.StackMapTable;
if (stackMapTable != null)
{
stackMapTable.NameIndex = manager.AddConstantUtf8(stackMapTable.Name);
code.Attributes.Add(stackMapTable);
}
attributes.Add(code);
}
示例10: CompilePreOp
private Item CompilePreOp(ByteCodeGenerator generator, Item item)
{
if (item is LocalItem && TypeCodeHelper.Truncate(item.TypeCode) == ItemTypeCode.Int)
{
((LocalItem)item).Incr(node is UnaryNode.PreIncNode ? 1 : -1);
return item;
}
else
{
item.Load();
generator.Emit(One(item.TypeCode));
if (node is UnaryNode.PreIncNode)
{
generator.Emit(OpAdd(item.Type));
}
else if (node is UnaryNode.PreDecNode)
{
generator.Emit(OpSub(item.Type));
}
var typeCode = item.TypeCode;
if (item.Type != PrimativeTypes.Int && TypeCodeHelper.Truncate(typeCode) == ItemTypeCode.Int)
{
generator.Emit(OpCodeValue.i2b + (byte)typeCode - (byte)ItemTypeCode.Byte);
}
return new AssignItem(generator, item);
}
}
示例11: CompileLong
private void CompileLong(ByteCodeGenerator generator)
{
generator.Emit(OpCodeValue.lcmp);
}
示例12: CompileFloat
private void CompileFloat(ByteCodeGenerator generator)
{
generator.Emit(OpCodeValue.fcmpl);
}
示例13: CompileDouble
private void CompileDouble(ByteCodeGenerator generator)
{
generator.Emit(OpCodeValue.dcmpl);
}
示例14: CompileSubtraction
internal static void CompileSubtraction(ByteCodeGenerator generator, Type type)
{
var typeCode = TypeCodeHelper.Truncate(PrimativeTypes.TypeCode(type));
switch (typeCode)
{
case ItemTypeCode.Int:
generator.Emit(OpCodeValue.isub);
break;
case ItemTypeCode.Long:
generator.Emit(OpCodeValue.lsub);
break;
case ItemTypeCode.Float:
generator.Emit(OpCodeValue.fsub);
break;
case ItemTypeCode.Double:
generator.Emit(OpCodeValue.dsub);
break;
default:
throw new InvalidOperationException();
}
}
示例15: TryInstance
private static Item TryInstance(ByteCodeGenerator generator, Type type, PrimaryNode.TermIdentifierExpression id)
{
if (type is Array)
{
if (id.Identifier == "length")
{
generator.Emit(OpCodeValue.arraylength);
return new StackItem(generator, PrimativeTypes.Int);
}
}
var definedType = type as DefinedType;
if (definedType == null) return null;
// try instance
Field field = definedType.Fields.FirstOrDefault(x => x.Name == id.Identifier);
if (field == null)
{
if (type is Class && ((Class)type).Super != null)
{
definedType.Resolve(generator.Manager.Imports);
return TryInstance(generator, ((Class)type).Super, id);
}
return null;
}
bool nonVirtual = field.Modifiers.HasFlag(Modifier.Private);
bool isStatic = field.Modifiers.HasFlag(Modifier.Static);
return isStatic
? new StaticItem(generator, field)
: (Item)new MemberItem(generator, field, nonVirtual);
}