示例#1
0
        //Compile conditional if-then-else operator
        private void CompileConditionalOperator(ElaCondition s, LabelMap map, Hints hints)
        {
            AddLinePragma(s);
            CompileExpression(s.Condition, map, Hints.Scope, s);
            var falseLab = cw.DefineLabel();
            cw.Emit(Op.Brfalse, falseLab);

            //Both the True and False parts may be the tail expressions
            //Also this whole operator can be used as a statement. Or can be compiled
            //in a situation when some of the referenced names are not initialized (Lazy)
            var left = (hints & Hints.Left) == Hints.Left ? Hints.Left : Hints.None;
            var tail = (hints & Hints.Tail) == Hints.Tail ? Hints.Tail : Hints.None;

            if (s.True != null)
                CompileExpression(s.True, map, left | tail | Hints.Scope, s);

            if (s.False != null)
            {
                var skipLabel = cw.DefineLabel();
                cw.Emit(Op.Br, skipLabel);
                cw.MarkLabel(falseLab);
                CompileExpression(s.False, map, left | tail | Hints.Scope, s);
                cw.MarkLabel(skipLabel);
                cw.Emit(Op.Nop);
            }
            else
            {
                AddError(ElaCompilerError.ElseMissing, s.True);
                AddHint(ElaCompilerHint.AddElse, s.True);
            }
        }
示例#2
0
        void LambdaGuard(out ElaExpression exp)
        {
            var ifExp = new ElaCondition(t);
            exp = ifExp;

            var cond = default(ElaExpression);
            var trueExp = default(ElaExpression);
            var falseExp = default(ElaExpression);

            Expr(out cond);
            ifExp.Condition = cond;
            Expect(24);
            Expr(out trueExp);
            ifExp.True = trueExp;
            Expect(23);
            if (la.kind == 36) {
            Get();
            Expect(24);
            Expr(out falseExp);
            } else if (StartOf(3)) {
            LambdaGuard(out falseExp);
            } else SynErr(100);
            ifExp.False = falseExp;
        }
示例#3
0
        void IfExpr(out ElaExpression exp)
        {
            Expect(35);
            var cond = new ElaCondition(t);
            var cexp = default(ElaExpression);
            exp = cond;

            Expr(out cexp);
            cond.Condition = cexp;
            Expect(37);
            Expr(out cexp);
            cond.True = cexp;
            ExpectWeak(36, 5);
            Expr(out cexp);
            cond.False = cexp;
        }