示例#1
0
        //Compiles Ela 'is' expression.
        private void CompileTypeCheck(ElaTypeCheck n, LabelMap map, Hints hints)
        {
            var failLab = cw.DefineLabel();
            var endLab = cw.DefineLabel();

            var sysVar = AddVariable();
            CompileExpression(n.Expression, map, Hints.None, n);
            PopVar(sysVar);

            //Here we are checking all classes specified in a pattern. We have to loop
            //through all classes and generate a check instruction (Traitch) for each.
            for (var i = 0; i < n.Traits.Count; i++)
            {
                var t = n.Traits[i];
                PushVar(sysVar);
                CheckTypeOrClass(t.Prefix, t.Name, failLab, n);
            }

            cw.Emit(Op.PushI1_1);
            cw.Emit(Op.Br, endLab);
            cw.MarkLabel(failLab);
            cw.Emit(Op.PushI1_0);
            cw.MarkLabel(endLab);
            cw.Emit(Op.Nop);

            if ((hints & Hints.Left) == Hints.Left)
                AddValueNotUsed(n);
        }
示例#2
0
        void TypeCheckExpr(ref ElaExpression pat)
        {
            Expect(31);
            var eis = new ElaTypeCheck(t) { Expression = pat };
            pat = eis;
            var fst = default(String);
            var snd = default(String);

            while (la.kind == 1 || la.kind == 2) {
            if (la.kind == 1) {
                Get();
            } else {
                Get();
            }
            fst = t.val; snd = null;
            if (la.kind == 27) {
                Get();
                if (la.kind == 1) {
                    Get();
                } else if (la.kind == 2) {
                    Get();
                } else SynErr(95);
                snd = t.val;
            }
            var ti = new TraitInfo(snd != null ? fst : null, snd != null ? snd : fst);
            eis.Traits.Add(ti);

            }
        }