Esempio n. 1
0
        private CompilerContext IfStatement(CompilerContext context)
        {
            var ifFalse = Enumerable.Empty <Instruction>();

            var expression = context.Node.GetNamedChild("if_condition").GetNamedChild("relational_expression");

            context.Compile(expression);
            var jumpCode = context.JumpExpression;

            var        block  = context.Node.GetNamedChild("block");
            var        child  = context.Push(block);
            CodeStream ifTrue = child.Compiler(child);

            var elseBlock = context.Node.GetNamedChild("else_block");

            if (elseBlock != null)
            {
                block   = elseBlock.GetNamedChild("block");
                child   = context.Push(block);
                ifFalse = child.Compiler(child);
                ifTrue.AsFluent()
                .Jmp.I(ifFalse.Count() + 1);
            }

            context.Code.AsFluent()
            .UnaryOp(jumpCode).I(ifTrue.Count() + 1);

            context.Code += ifTrue;
            context.Code += ifFalse;

            return(context);
        }
Esempio n. 2
0
        private CompilerContext Statement(CompilerContext context)
        {
            context.Code.Add(new Instruction(OpCode.Noop, context.Node.ToString()));
            foreach (var expression in context.Node)
            {
                var child = context.Push(expression);
                context.Code += child.Compiler(child);
            }

            return(context);
        }
Esempio n. 3
0
        private CompilerContext WhileStatement(CompilerContext context)
        {
            var expression = context.Node.GetNamedChild("while_condition").GetNamedChild("relational_expression");

            var conditionPtr = context.Code.Position;

            context.Compile(expression);

            var block = context.Node.GetNamedChild("block");
            var child = context.Push(block);

            var blockCode = child.Compiler(child);

            context.Code.AsFluent()
            .Je.I(blockCode.Count() + 2);

            context.Code += blockCode;
            context.Code.AsFluent()
            .Jmp.I(conditionPtr - context.Code.Position);

            return(context);
        }
Esempio n. 4
0
        private CompilerContext WhileStatement(CompilerContext context)
        {
            var expression = context.Node.GetNamedChild("while_condition").GetNamedChild("relational_expression");

            var conditionPtr = context.Code.Position;
            context.Compile(expression);

            var block = context.Node.GetNamedChild("block");
            var child = context.Push(block);

            var blockCode = child.Compiler(child);
            context.Code.AsFluent()
                .Je.I(blockCode.Count() + 2);

            context.Code += blockCode;
            context.Code.AsFluent()
                .Jmp.I(conditionPtr - context.Code.Position);

            return context;
        }
Esempio n. 5
0
        private CompilerContext Statement(CompilerContext context)
        {
            context.Code.Add(new Instruction(OpCode.Noop, context.Node.ToString()));
            foreach ( var expression in context.Node )
            {
                var child = context.Push(expression);
                context.Code += child.Compiler(child);
            }

            return context;
        }
Esempio n. 6
0
        private CompilerContext IfStatement(CompilerContext context)
        {
            var ifFalse = Enumerable.Empty<Instruction>();

            var expression = context.Node.GetNamedChild("if_condition").GetNamedChild("relational_expression");
            context.Compile(expression);
            var jumpCode = context.JumpExpression;

            var block = context.Node.GetNamedChild("block");
            var child = context.Push(block);
            CodeStream ifTrue = child.Compiler(child);

            var elseBlock = context.Node.GetNamedChild("else_block");
            if (elseBlock != null)
            {
                block = elseBlock.GetNamedChild("block");
                child = context.Push(block);
                ifFalse = child.Compiler(child);
                ifTrue.AsFluent()
                    .Jmp.I(ifFalse.Count() + 1);
            }

            context.Code.AsFluent()
                .UnaryOp(jumpCode).I(ifTrue.Count() + 1);

            context.Code += ifTrue;
            context.Code += ifFalse;

            return context;
        }