• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# ByteCode.ByteCodeGenerator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中JavaCompiler.Compilation.ByteCode.ByteCodeGenerator的典型用法代码示例。如果您正苦于以下问题:C# ByteCodeGenerator类的具体用法?C# ByteCodeGenerator怎么用?C# ByteCodeGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ByteCodeGenerator类属于JavaCompiler.Compilation.ByteCode命名空间,在下文中一共展示了ByteCodeGenerator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Compile

        public Item Compile(ByteCodeGenerator generator)
        {
            Chain thenExit = null;

            var item = new ConditionCompiler(node.Condition).Compile(generator);
            var elseChain = item.JumpFalse();

            Item x = null;
            if (!item.IsFalse())
            {
                generator.ResolveChain(item.TrueJumps);

                x = new ExpressionCompiler(node.ThenExpression).Compile(generator).Load();

                thenExit = generator.Branch([email protected]);
            }
            if (elseChain != null)
            {
                generator.ResolveChain(elseChain);

                x = new ExpressionCompiler(node.ElseExpression).Compile(generator).Load();
            }
            generator.ResolveChain(thenExit);

            //var type = tb.Type.FindCommonType(fb.Type);
            var type = x.Type;

            return new StackItem(generator, type);
        }
开发者ID:will14smith,项目名称:JavaCompiler,代码行数:29,代码来源:ConditionalCompiler.cs


示例2: Compile

        public Item Compile(ByteCodeGenerator generator)
        {
            var type = node.GetType(generator);

            var lhs = new TranslationCompiler(node.LeftChild, type).Compile(generator);
            var rhs = new TranslationCompiler(node.RightChild, type).Compile(generator);

            if (!type.Primitive)
            {
                throw new InvalidOperationException();
            }

            lhs.Load();
            rhs.Load();

            if (node is MultiplicativeNode.MultiplicativeMultiplyNode)
            {
                CompileMultiplication(generator, type);
            }
            else if (node is MultiplicativeNode.MultiplicativeDivideNode)
            {
                CompileDivide(generator, type);
            }
            else if (node is MultiplicativeNode.MultiplicativeModNode)
            {
                CompileMod(generator, type);
            }

            return new StackItem(generator, type);
        }
开发者ID:will14smith,项目名称:JavaCompiler,代码行数:30,代码来源:MultiplicativeCompiler.cs


示例3: 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();
            }
        }
开发者ID:will14smith,项目名称:JavaCompiler,代码行数:25,代码来源:ReturnCompiler.cs


示例4: 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]);
        }
开发者ID:will14smith,项目名称:JavaCompiler,代码行数:27,代码来源:ConstructorBlockCompiler.cs


示例5: CompileBody

        private void CompileBody(CompileManager manager)
        {
            attributes = new List<CompileAttribute>();
            generator = new ByteCodeGenerator(manager, (Method)constructor);

            foreach (Method.Parameter parameter in constructor.Parameters)
            {
                generator.DefineVariable(parameter.Name, parameter.Type);
            }

            new ConstructorBlockCompiler(constructor.Body).Compile(generator);

            attributes.Add(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);

                attributes.Add(stackMapTable);
            }
        }
开发者ID:will14smith,项目名称:JavaCompiler,代码行数:30,代码来源:ConstructorCompiler.cs


示例6: Compile

        public void Compile(ByteCodeGenerator generator)
        {
            var item = new ConditionCompiler(node.Condition).Compile(generator);
            var elseChain = item.JumpFalse();

            Chain thenExit = null;
            if (!item.IsFalse())
            {
                generator.ResolveChain(item.TrueJumps);

                generator.PushScope();

                new StatementCompiler(node.TrueBranch).Compile(generator);
                thenExit = generator.Branch([email protected]);

                generator.PopScope();
            }
            if (elseChain != null)
            {
                generator.ResolveChain(elseChain);

                if (node.FalseBranch != null)
                {
                    generator.PushScope();
                    new StatementCompiler(node.FalseBranch).Compile(generator);
                    generator.PopScope();
                }
            }

            generator.ResolveChain(thenExit);
        }
开发者ID:will14smith,项目名称:JavaCompiler,代码行数:31,代码来源:IfCompiler.cs


示例7: Compile

        public Item Compile(ByteCodeGenerator generator)
        {
            //TODO
            var item = new ExpressionCompiler(node.Child.Child).Compile(generator);

            if (node is UnaryNode.PlusNode)
            {
                return item.Load();
            }
            if (node is UnaryNode.MinusNode)
            {
                throw new NotImplementedException();
            }

            if (node is UnaryNode.PreIncNode)
            {
                return CompilePreOp(generator, item);
            }
            if (node is UnaryNode.PreDecNode)
            {
                return CompilePreOp(generator, item);
            }

            if (node is UnaryNode.PostIncNode)
            {
                return CompilePostOp(generator, item);
            }
            if (node is UnaryNode.PostDecNode)
            {
                return CompilePostOp(generator, item);
            }

            throw new NotImplementedException();
        }
开发者ID:will14smith,项目名称:JavaCompiler,代码行数:34,代码来源:UnaryCompiler.cs


示例8: CompileNewArray

        private static Item CompileNewArray(ByteCodeGenerator generator, NewNode.NewArrayNode node)
        {
            var elemType = node.GetType(generator);
            var type = node.GetType(generator);

            foreach (var expression in node.Dimensions)
            {
                new ExpressionCompiler(expression).Compile(generator).Coerce(PrimativeTypes.Int).Load();

                type = new Array(type);
            }

            var ndims = (byte)node.Dimensions.Count;

            var elemcode = TypeCodeHelper.ArrayCode((type as Array).ArrayType);
            if (elemcode == 0 || (elemcode == 1 && ndims == 1))
            {
                generator.EmitAnewarray(generator.Manager.AddConstantClass(elemType), type);
            }
            else if (elemcode == 1)
            {
                generator.EmitMultianewarray(ndims, generator.Manager.AddConstantClass(type), type);
            }
            else
            {
                generator.EmitNewarray(elemcode, type);
            }

            return new StackItem(generator, type);
        }
开发者ID:will14smith,项目名称:JavaCompiler,代码行数:30,代码来源:NewCompiler.cs


示例9: BufferToString

        public static void BufferToString(ByteCodeGenerator generator, DefinedType sb)
        {
            var toString = sb.FindMethod(generator, "toString", null);
            if (toString == null) throw new InvalidOperationException();

            new MemberItem(generator, toString, false).Invoke();
        }
开发者ID:will14smith,项目名称:JavaCompiler,代码行数:7,代码来源:AdditiveCompiler.cs


示例10: AppendStrings

        public static void AppendStrings(ByteCodeGenerator generator, DefinedType sb, ExpressionNode node)
        {
            if (node is AdditiveNode)
            {
                var addNode = node as AdditiveNode;

                generator.Kill();
                var addType = new AdditiveCompiler(addNode).Compile(generator).Type;
                generator.Revive();

                if (addType.Name == BuiltinTypes.String.Name)
                {
                    AppendStrings(generator, sb, addNode.LeftChild.Child);
                    AppendStrings(generator, sb, addNode.RightChild.Child);

                    return;
                }
            }

            var item = new ExpressionCompiler(node).Compile(generator);

            var appendMethod = sb.FindMethod(generator, "append", new List<Type> { item.Type });
            if (appendMethod == null) throw new InvalidOperationException();

            item.Load();
            new MemberItem(generator, appendMethod, false).Invoke();
        }
开发者ID:will14smith,项目名称:JavaCompiler,代码行数:27,代码来源:AdditiveCompiler.cs


示例11: Compile

        public Item Compile(ByteCodeGenerator generator)
        {
            var item = new ExpressionCompiler(expression).Compile(generator);

            if (type == null) return item;

            if (type.Primitive && item.Type.Primitive)
            {
                return item.Coerce(type);
            }

            if (item.Type.IsAssignableTo(type))
            {
                return item;
            }

            if (item.Type.Primitive && !type.Primitive)
            {
                // box!
                var primative = item.Type as PrimativeTypes.PrimativeType;

                return primative.Box(generator, item, type as DefinedType);
            }
            if (!item.Type.Primitive && type.Primitive)
            {
                // unbox!
                var primative = type as PrimativeTypes.PrimativeType;

                return primative.Unbox(generator, item);
            }

            throw new InvalidOperationException();
        }
开发者ID:will14smith,项目名称:JavaCompiler,代码行数:33,代码来源:TranslationCompiler.cs


示例12: FindMethod

        public static Method FindMethod(this DefinedType type, ByteCodeGenerator generator, string name, List<Type> args)
        {
            type.Resolve(generator.Manager.Imports);

            var argCount = args == null ? 0 : args.Count;
            var methods = (name == "<init>"
                ? ((Class)type).Constructors.Select(x => (Method)x)
                : type.Methods)
                    .Where(x => x.Name == name && x.Parameters.Count == argCount);

            if (args == null || argCount == 0)
            {
                return methods.SingleOrDefault();
            }

            var method = methods
                .Where(x => x.Parameters.Zip(args, (p, a) => a.IsAssignableTo(p.Type)).All(i => i))
                // find the method with the fewest casts
                .Select(
                    x =>
                    new
                        {
                            method = x,
                            casts = x.Parameters.Zip(args, (p, a) => a.GetDescriptor() == p.Type.GetDescriptor() ? 0 : 1).Sum()
                        })
                .OrderBy(x => x.casts)
                .Select(x => x.method)
                .FirstOrDefault();

            return method;
        }
开发者ID:will14smith,项目名称:JavaCompiler,代码行数:31,代码来源:CommonFinder.cs


示例13: GetType

        public override Type GetType(ByteCodeGenerator manager)
        {
            var l = LeftChild.GetType(manager, false, true);
            var r = RightChild.GetType(manager, false, true);

            return l.FindCommonType(r);
        }
开发者ID:will14smith,项目名称:JavaCompiler,代码行数:7,代码来源:RelationNode.cs


示例14: Compile

 public Item Compile(ByteCodeGenerator generator)
 {
     if (node is AssignmentNode.NormalAssignNode)
     {
         return CompileAssign(generator);
     }
     return CompileAssignOp(generator);
 }
开发者ID:will14smith,项目名称:JavaCompiler,代码行数:8,代码来源:AssignmentCompiler.cs


示例15: ConditionalItem

        public ConditionalItem(ByteCodeGenerator generator, OpCodeValue opCode, Chain trueChain, Chain falseChain)
            : base(generator, PrimativeTypes.Boolean)
        {
            OpCode = opCode;

            TrueJumps = trueChain;
            FalseJumps = falseChain;
        }
开发者ID:will14smith,项目名称:JavaCompiler,代码行数:8,代码来源:ConditionalItem.cs


示例16: CompileAssign

        private Item CompileAssign(ByteCodeGenerator generator)
        {
            var lhs = new ExpressionCompiler(node.Left).Compile(generator);
            var type = ClassLocator.Find(lhs.Type, generator.Manager.Imports);

            new TranslationCompiler(node.Right, type).Compile(generator).Load();

            return new AssignItem(generator, lhs);
        }
开发者ID:will14smith,项目名称:JavaCompiler,代码行数:9,代码来源:AssignmentCompiler.cs


示例17: 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();
        }
开发者ID:will14smith,项目名称:JavaCompiler,代码行数:11,代码来源:AdditiveCompiler.cs


示例18: 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));
        }
开发者ID:will14smith,项目名称:JavaCompiler,代码行数:11,代码来源:NewCompiler.cs


示例19: StackItem

        public static Item StackItem(ByteCodeGenerator generator, Type type)
        {
            if (type.Primitive)
            {
                if (TypeCode(type) == ItemTypeCode.Void)
                {
                    return new VoidItem(generator);
                }
            }

            return new StackItem(generator, type);
        }
开发者ID:will14smith,项目名称:JavaCompiler,代码行数:12,代码来源:TypeCodeHelper.cs


示例20: GetType

            public override Type GetType(ByteCodeGenerator manager)
            {
                var l = LeftChild.GetType(manager, false, true);
                var r = RightChild.GetType(manager, false, true);

                if (!l.Primitive || !r.Primitive)
                {
                    return BuiltinTypes.String;
                }

                return base.GetType(manager);
            }
开发者ID:will14smith,项目名称:JavaCompiler,代码行数:12,代码来源:AdditiveNode.cs



注:本文中的JavaCompiler.Compilation.ByteCode.ByteCodeGenerator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# JsRt.JsValue类代码示例发布时间:2022-05-26
下一篇:
C# Workspace.ProjectType类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap