コード例 #1
0
ファイル: Builder.Literals.cs プロジェクト: rizwan3d/elalang
        //Compiles xs literal
        private ExprData CompileTuple(ElaTupleLiteral v, LabelMap map, Hints hints)
        {
            CompileTupleParameters(v, v.Parameters, map);

            if ((hints & Hints.Left) == Hints.Left)
                AddValueNotUsed(v);

            return new ExprData(DataKind.VarType, (Int32)ElaTypeCode.Tuple);
        }
コード例 #2
0
ファイル: Builder.Match.cs プロジェクト: rizwan3d/elalang
        //Compile a xs pattern in the form: {fieldName=pat,..}. This pattern can fail at
        //run-time if a given expression doesn't support Len and Pushelem op codes.
        private void CompileTuplePattern(int sysVar, ElaTupleLiteral tuple, Label failLab, bool allowBang)
        {
            var len = tuple.Parameters.Count;

            //Check the length first
            PushVar(sysVar);
            cw.Emit(Op.Len);
            cw.Emit(Op.PushI4, len);
            cw.Emit(Op.Cneq);
            cw.Emit(Op.Brtrue, failLab); //Length not equal, proceed to fail

            //Loops through all xs patterns
            for (var i = 0; i < len; i++)
            {
                var pat = tuple.Parameters[i];
                PushVar(sysVar);

                //Generate a 'short' op typeId for the first entry
                if (i == 0)
                    cw.Emit(Op.PushI4_0);
                else
                    cw.Emit(Op.PushI4, i);

                cw.Emit(Op.Pushelem);

                //Here we need to bind a value of an element to a new system
                //variable in order to match it.
                var sysVar2 = AddVariable();
                PopVar(sysVar2);

                //Match an element of a xs
                CompilePattern(sysVar2, pat, failLab, allowBang, false /*forceStrict*/);
            }
        }
コード例 #3
0
ファイル: Parser.cs プロジェクト: rizwan3d/elalang
        void GroupExpr(out ElaExpression exp)
        {
            exp = null;
            var cexp = default(ElaExpression);
            var ot = t;

            Expr(out exp);
            if (la.kind == 56) {
            var tuple = new ElaTupleLiteral(ot);
            tuple.Parameters.Add(exp);
            exp = tuple;

            Get();
            if (StartOf(3)) {
                Expr(out cexp);
                tuple.Parameters.Add(cexp);
            }
            while (la.kind == 56) {
                Get();
                Expr(out cexp);
                tuple.Parameters.Add(cexp);
            }
            }
        }