Esempio n. 1
0
        public override void Accept(MatchExpression match)
        {
            AstNode value = match.Children [0];

            value.Visit(this);
            int temporary = methodBuilder.CreateTemporary();

            methodBuilder.EmitInstruction(match.Location, Opcode.StoreLocal, temporary);
            PatternCompiler compiler = new PatternCompiler(symbolTable, methodBuilder,
                                                           temporary,
                                                           this);
            IodineLabel nextLabel = methodBuilder.CreateLabel();
            IodineLabel endLabel  = methodBuilder.CreateLabel();

            for (int i = 1; i < match.Children.Count; i++)
            {
                if (i > 1)
                {
                    methodBuilder.MarkLabelPosition(nextLabel);
                    nextLabel = methodBuilder.CreateLabel();
                }
                CaseExpression clause = match.Children [i] as CaseExpression;
                clause.Pattern.Visit(compiler);
                methodBuilder.EmitInstruction(match.Location, Opcode.JumpIfFalse, nextLabel);
                if (clause.Condition != null)
                {
                    clause.Condition.Visit(this);
                    methodBuilder.EmitInstruction(match.Location, Opcode.JumpIfFalse, nextLabel);
                }
                clause.Value.Visit(this);
                methodBuilder.EmitInstruction(match.Location, Opcode.Jump, endLabel);
            }
            methodBuilder.MarkLabelPosition(endLabel);
        }
Esempio n. 2
0
        public override void Accept(TupleExpression tuple)
        {
            IodineLabel startLabel = methodBuilder.CreateLabel();
            IodineLabel endLabel   = methodBuilder.CreateLabel();
            int         item       = methodBuilder.CreateTemporary();

            PatternCompiler compiler = new PatternCompiler(symbolTable, methodBuilder,
                                                           item,
                                                           parentVisitor);

            for (int i = 0; i < tuple.Children.Count; i++)
            {
                if (tuple.Children [i] is NameExpression &&
                    ((NameExpression)tuple.Children [i]).Value == "_")
                {
                    continue;
                }
                methodBuilder.EmitInstruction(tuple.Location, Opcode.LoadLocal, temporary);
                methodBuilder.EmitInstruction(tuple.Location, Opcode.LoadConst,
                                              methodBuilder.Module.DefineConstant(new IodineInteger(i)));
                methodBuilder.EmitInstruction(tuple.Location, Opcode.LoadIndex);
                methodBuilder.EmitInstruction(tuple.Location, Opcode.StoreLocal, item);
                tuple.Children [i].Visit(compiler);
                methodBuilder.EmitInstruction(tuple.Location, Opcode.JumpIfFalse, endLabel);
            }
            methodBuilder.EmitInstruction(tuple.Location, Opcode.LoadTrue);
            methodBuilder.EmitInstruction(tuple.Location, Opcode.Jump, startLabel);

            methodBuilder.MarkLabelPosition(endLabel);
            methodBuilder.EmitInstruction(tuple.Location, Opcode.LoadFalse);

            methodBuilder.MarkLabelPosition(startLabel);
        }
Esempio n. 3
0
		public override void Accept (MatchExpression match)
		{
			AstNode value = match.Children [0];
			value.Visit (this);
			int temporary = methodBuilder.CreateTemporary ();
			methodBuilder.EmitInstruction (match.Location, Opcode.StoreLocal, temporary);
			PatternCompiler compiler = new PatternCompiler (symbolTable, methodBuilder,
				temporary,
				this);
			IodineLabel nextLabel = methodBuilder.CreateLabel ();
			IodineLabel endLabel = methodBuilder.CreateLabel ();
			for (int i = 1; i < match.Children.Count; i++) {
				if (i > 1) {
					methodBuilder.MarkLabelPosition (nextLabel);
					nextLabel = methodBuilder.CreateLabel ();
				}
				CaseExpression clause = match.Children [i] as CaseExpression;
				clause.Pattern.Visit (compiler);
				methodBuilder.EmitInstruction (match.Location, Opcode.JumpIfFalse, nextLabel);
				if (clause.Condition != null) {
					clause.Condition.Visit (this);
					methodBuilder.EmitInstruction (match.Location, Opcode.JumpIfFalse, nextLabel);
				}
				clause.Value.Visit (this);
				methodBuilder.EmitInstruction (match.Location, Opcode.Jump, endLabel);
			}
			methodBuilder.MarkLabelPosition (endLabel);
		}
Esempio n. 4
0
		public override void Accept (TupleExpression tuple)
		{
			IodineLabel startLabel = methodBuilder.CreateLabel ();
			IodineLabel endLabel = methodBuilder.CreateLabel ();
			int item = methodBuilder.CreateTemporary ();

			PatternCompiler compiler = new PatternCompiler (symbolTable, methodBuilder,
				item,
				parentVisitor);
			
			for (int i = 0; i < tuple.Children.Count; i++) {
				if (tuple.Children [i] is NameExpression &&
					((NameExpression)tuple.Children [i]).Value == "_")
					continue;
				methodBuilder.EmitInstruction (tuple.Location, Opcode.LoadLocal, temporary);
				methodBuilder.EmitInstruction (tuple.Location, Opcode.LoadConst,
					methodBuilder.Module.DefineConstant (new IodineInteger (i)));
				methodBuilder.EmitInstruction (tuple.Location, Opcode.LoadIndex);
				methodBuilder.EmitInstruction (tuple.Location, Opcode.StoreLocal, item);
				tuple.Children [i].Visit (compiler);
				methodBuilder.EmitInstruction (tuple.Location, Opcode.JumpIfFalse, endLabel);
			}
			methodBuilder.EmitInstruction (tuple.Location, Opcode.LoadTrue);
			methodBuilder.EmitInstruction (tuple.Location, Opcode.Jump, startLabel);

			methodBuilder.MarkLabelPosition (endLabel);
			methodBuilder.EmitInstruction (tuple.Location, Opcode.LoadFalse);

			methodBuilder.MarkLabelPosition (startLabel);
		}