コード例 #1
0
ファイル: Builder.Match.cs プロジェクト: rizwan3d/elalang
        //Used to compile a 'try' expression.
        private void CompileTryExpression(ElaTry n, LabelMap map, Hints hints)
        {
            var catchLab = cw.DefineLabel();
            var exitLab = cw.DefineLabel();

            //Generate a start of a 'try' section
            AddLinePragma(n);
            cw.Emit(Op.Start, catchLab);

            CompileExpression(n.Expression, map, Hints.None, n);

            //Leaving 'try' section
            cw.Emit(Op.Leave);
            cw.Emit(Op.Br, exitLab);
            cw.MarkLabel(catchLab);
            cw.Emit(Op.Leave);

            //Throw hint is to tell match compiler to generate a different typeId if
            //all pattern fail - to rethrow an original error instead of generating a
            //new MatchFailed error.
            CompileSimpleMatch(n.Entries.Equations, map, hints | Hints.Throw, null);

            cw.MarkLabel(exitLab);
            cw.Emit(Op.Nop);

            if ((hints & Hints.Left) == Hints.Left)
                AddValueNotUsed(n);
        }
コード例 #2
0
ファイル: Parser.cs プロジェクト: rizwan3d/elalang
        void TryExpr(out ElaExpression exp)
        {
            scanner.InjectBlock();
            bindings.Push(unit);

            while (!(la.kind == 0 || la.kind == 39)) {SynErr(78); Get();}
            Expect(39);
            var match = new ElaTry(t);
            exp = match;
            var block = default(ElaEquationSet);
            var cexp = default(ElaExpression);

            Expr(out cexp);
            match.Expression = cexp;
            Expect(34);
            BindingChain(out block);
            match.Entries = block;
            bindings.Pop();

            EndBlock();
        }