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(OpCodeValue.@goto);
            }
            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);
        }
Пример #2
0
        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(OpCodeValue.@goto);

                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);
        }
Пример #3
0
        public void Compile(ByteCodeGenerator generator)
        {
            var start = generator.EntryPoint();

            // Test Condition
            var item = new ConditionCompiler(node.Expression).Compile(generator);
            var loopDone = item.JumpFalse();

            generator.ResolveChain(item.TrueJumps);

            // Run Body
            generator.PushScope();

            new StatementCompiler(node.Statement).Compile(generator);
            generator.ResolveChain(generator.Branch(OpCodeValue.@goto), start);

            generator.PopScope();

            // End
            generator.ResolveChain(loopDone);
        }
Пример #4
0
        public void Compile(ByteCodeGenerator generator)
        {
            generator.PushScope();

            var start = generator.CurrentPC();
            new StatementCompiler(node.Initialiser).Compile(generator);

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

            generator.ResolveChain(item.TrueJumps);

            new StatementCompiler(node.Body).Compile(generator);
            new StatementCompiler(node.Updater).Compile(generator);

            generator.ResolveChain(generator.Branch(OpCodeValue.@goto), start);

            generator.PopScope();

            generator.ResolveChain(loopDone);
        }