예제 #1
0
        private void CompileContinue(Node node)
        {
            if (this.continues == null)
            {
                Runtime.RaiseCompileError("no loop to continue from", node.span);
            }

            var cont = new Instruction.Goto {
                span = node.span
            };

            this.continues.Add(cont);
            this.Emit(cont);
        }
예제 #2
0
        private void CompileBreak(Node node)
        {
            if (this.breaks == null)
            {
                Runtime.RaiseCompileError("no loop to break from", node.span);
            }

            var br = new Instruction.Goto {
                span = node.span
            };

            this.breaks.Add(br);
            this.Emit(br);
        }
예제 #3
0
        private void CompileIf(Node node)
        {
            this.CompileExpr(node.children[0]);

            var branch = new Instruction.Branch {
                span = node.span
            };

            this.Emit(branch);

            var trueIndex = this.CurrentIndex();

            this.CompileExpr(node.children[1]);
            this.Emit(new Instruction.Discard {
                span = node.children[1].span.JustAfter
            });

            var gotoAfter = new Instruction.Goto {
                span = node.children[1].span.JustAfter
            };

            this.Emit(gotoAfter);

            var afterIndex = this.CurrentIndex();
            var falseIndex = afterIndex;

            if (node.children.Count == 3)
            {
                this.CompileExpr(node.children[2]);
                this.Emit(new Instruction.Discard {
                    span = node.children[2].span.JustAfter
                });
                afterIndex = this.CurrentIndex();
            }

            branch.destinationIfTrue  = trueIndex;
            branch.destinationIfFalse = falseIndex;
            gotoAfter.destination     = afterIndex;

            this.Emit(new Instruction.PushLiteral {
                span = node.span.JustAfter, literal = null
            });
        }