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);
        }
        public Item Compile(ByteCodeGenerator generator)
        {
            if (node is UnaryOtherNode.UnaryCastNode)
            {
                var cast = node as UnaryOtherNode.UnaryCastNode;
                var type = cast.GetType(generator);

                return new TranslationCompiler(cast.Expression, type).Compile(generator).Load();
            }
            if (node is UnaryOtherNode.UnaryNotNode)
            {
                var not = node as UnaryOtherNode.UnaryNotNode;

                var item = new TranslationCompiler(not.Expression, PrimativeTypes.Boolean).Compile(generator).Conditional();

                return item.Negate();
            }

            throw new NotImplementedException();
        }
Пример #3
0
        public Item Compile(ByteCodeGenerator generator)
        {
            if (node.Value == null)
            {
                if (generator.Method.ReturnType != PrimativeTypes.Void)
                {
                    throw new InvalidOperationException();
                }

                generator.Emit(OpCodeValue.@return);

                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);
        }
Пример #4
0
        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);

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

            if ((!lhs.Type.Primitive || !rhs.Type.Primitive) && (lhs.Type.Primitive || rhs.Type.Primitive))
            {
                throw new InvalidOperationException();
            }

            OpCodeValue opcode;
            if (node is EqualityNode.EqualityEqualNode)
            {
                if (type.Primitive)
                {
                    opcode = OpCodeValue.if_icmpeq;
                }
                else
                {
                    opcode = OpCodeValue.if_acmpeq;
                }
            }
            else if (node is EqualityNode.EqualityNotEqualNode)
            {
                opcode = type.Primitive ? OpCodeValue.if_icmpne : OpCodeValue.if_acmpne;
            }
            else
            {
                throw new NotImplementedException();
            }

            return new ConditionalItem(generator, opcode);
        }
Пример #5
0
        public ConditionalItem Compile(ByteCodeGenerator generator)
        {
            var item = new TranslationCompiler(node, PrimativeTypes.Boolean).Compile(generator);

            return item.Conditional();
        }