예제 #1
0
        //Compiles xs literal
        private ExprData CompileTuple(ElaTupleLiteral v, LabelMap map, Hints hints)
        {
            CompileTupleParameters(v, v.Parameters, map);

            if ((hints & Hints.Left) == Hints.Left)
            {
                AddValueNotUsed(map, v);
            }

            return(new ExprData(DataKind.VarType, (Int32)ElaTypeCode.Tuple));
        }
예제 #2
0
        //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*/);
            }
        }