示例#1
0
        public BlockStatement ConvertBlock(Instruction[] instructions, Stack <Expression> stack, out int consumed)
        {
            var statements = new List <Statement>();

            for (consumed = 0; consumed < instructions.Length; consumed++)
            {
                Instruction instruction = instructions[consumed];

                if (instruction == null)
                {
                    Console.WriteLine($"Unimplemented instruction! Stack: {stack.Count}");
                    continue;
                }

                if (Jumper.IsValid(instruction.OP))
                {
                    throw new NotImplementedException("Control Flow handling is still under construction.");
                }

                Statement stmt = instruction.AcceptVisitor(this, stack);

                if (stmt != null)
                {
                    statements.Add(stmt);
                }
            }
            return(new BlockStatement(statements));
        }
示例#2
0
        public BlockStatement ConvertBlock(Instruction[] instructions, Stack <Expression> stack, out int consumed)
        {
            var statements = new List <Statement>();

            for (consumed = 0; consumed < instructions.Length; consumed++)
            {
                Instruction instruction = instructions[consumed];

                Console.WriteLine(new string('\t', _intendation) + $"[{consumed}/{instructions.Length}] {instruction.OP}");

                if (instruction == null)
                {
                    Console.WriteLine($"Unimplemented instruction! Stack: {stack.Count}");
                    continue;
                }

                if (instruction is IfTrueIns ifTrue)
                {
                    var block = new List <Instruction>(_code.GetJumpBlock(ifTrue));
                    Console.WriteLine(new string('\t', ++_intendation) + $"# Entering conditional block. Stack: {stack.Count}");

                    _ifTrueBlocks.Add(ifTrue, ConvertBlock(block.ToArray(), stack, out int ifConsumed));
                    consumed += ifConsumed;
                    Console.WriteLine(new string('\t', --_intendation) + $"# Block exit. Stack: {stack.Count}");

                    if (block.Last() is Jumper jump)
                    {
                        block.Remove(jump);
                        var elseBlock = _code.GetJumpBlock(jump);

                        Console.WriteLine(new string('\t', _intendation++) + $"# Has else block. Entering.. Stack: {stack.Count}");

                        _elseBlocks.Add(ifTrue, ConvertBlock(elseBlock, stack, out int elseConsumed));
                        consumed += elseConsumed;

                        Console.WriteLine(new string('\t', --_intendation) + $"# Block exit. Stack: {stack.Count}");
                    }
                }
                Statement stmt = instruction.AcceptVisitor(this, stack);

                if (stmt != null)
                {
                    statements.Add(stmt);
                }
            }
            return(new BlockStatement(statements));
        }
示例#3
0
 protected override void Default(Instruction instruction, Stack <Expression> expressionStack)
 {
     instruction.AcceptVisitor(_statementBuilder, expressionStack);
 }