Наследование: clojure.lang.CljCompiler.Ast.Expr, MaybePrimitiveExpr, AssignableExpr
Пример #1
0
        public CaseExpr(IPersistentMap sourceSpan, LocalBindingExpr expr, int shift, int mask, int low, int high, Expr defaultExpr,
                        SortedDictionary <int, Expr> tests, Dictionary <int, Expr> thens, Keyword switchType, Keyword testType, IPersistentSet skipCheck)
        {
            _sourceSpan  = sourceSpan;
            _expr        = expr;
            _shift       = shift;
            _mask        = mask;
            _low         = low;
            _high        = high;
            _defaultExpr = defaultExpr;
            _tests       = tests;
            _thens       = thens;
            if (switchType != _compactKey && switchType != _sparseKey)
            {
                throw new ArgumentException("Unexpected switch type: " + switchType);
            }
            _switchType = switchType;
            if (testType != _intKey && testType != _hashEquivKey && testType != _hashIdentityKey)
            {
                throw new ArgumentException("Unexpected test type: " + testType);
            }
            _testType  = testType;
            _skipCheck = skipCheck;
            ICollection <Expr> returns = new List <Expr>(thens.Values);

            returns.Add(defaultExpr);
            _returnType = Compiler.MaybeClrType(returns);
            if (RT.count(skipCheck) > 0 && RT.booleanCast(RT.WarnOnReflectionVar.deref()))
            {
                RT.errPrintWriter().WriteLine("Performance warning, {0}:{1}:{2} - hash collision of some case test constants; if selected, those entries will be tested sequentially.",
                                              Compiler.SourcePathVar.deref(), Compiler.GetLineFromSpanMap(sourceSpan), Compiler.GetColumnFromSpanMap(sourceSpan));
            }
        }
Пример #2
0
 public CaseExpr( IPersistentMap sourceSpan, LocalBindingExpr expr, int shift, int mask, int low, int high, Expr defaultExpr,
     SortedDictionary<int, Expr> tests, Dictionary<int, Expr> thens, Keyword switchType, Keyword testType, IPersistentSet skipCheck)
 {
     _sourceSpan = sourceSpan;
     _expr = expr;
     _shift = shift;
     _mask = mask;
     //_low = low;
     //_high = high;
     _defaultExpr = defaultExpr;
     _tests = tests;
     _thens = thens;
     if (switchType != _compactKey && switchType != _sparseKey)
         throw new ArgumentException("Unexpected switch type: " + switchType);
     //_switchType = switchType;
     if (testType != _intKey && testType != _hashEquivKey && testType != _hashIdentityKey)
         throw new ArgumentException("Unexpected test type: " + testType);
     _testType = testType;
     _skipCheck = skipCheck;
     ICollection<Expr> returns = new List<Expr>(thens.Values);
     returns.Add(defaultExpr);
     _returnType = Compiler.MaybeClrType(returns);
     if (RT.count(skipCheck) > 0 && RT.booleanCast(RT.WarnOnReflectionVar.deref()))
     {
         RT.errPrintWriter().WriteLine("Performance warning, {0}:{1} - hash collision of some case test constants; if selected, those entries will be tested sequentially.",
             Compiler.SourcePathVar.deref(),RT.get(sourceSpan,RT.StartLineKey));
     }
 }
Пример #3
0
 public CaseExpr( IPersistentMap sourceSpan, LocalBindingExpr expr, int shift, int mask, int low, int high, Expr defaultExpr,
     Dictionary<int, Expr> tests, Dictionary<int, Expr> thens, bool allKeywords)
 {
     _sourceSpan = sourceSpan;
     _expr = expr;
     _shift = shift;
     _mask = mask;
     _low = low;
     _high = high;
     _defaultExpr = defaultExpr;
     _tests = tests;
     _thens = thens;
     _allKeywords = allKeywords;
 }
Пример #4
0
            //(case* expr shift mask  default map<minhash, [test then]> table-type test-type skip-check?)
            //prepared by case macro and presumed correct
            //case macro binds actual expr in let so expr is always a local,
            //no need to worry about multiple evaluation
            public Expr Parse(ParserContext pcon, object frm)
            {
                ISeq form = (ISeq)frm;

                if (pcon.Rhc == RHC.Eval)
                {
                    return(Compiler.Analyze(pcon, RT.list(RT.list(Compiler.FnOnceSym, PersistentVector.EMPTY, form)), "case__" + RT.nextID()));
                }

                IPersistentVector args = LazilyPersistentVector.create(form.next());

                object         exprForm    = args.nth(0);
                int            shift       = Util.ConvertToInt(args.nth(1));
                int            mask        = Util.ConvertToInt(args.nth(2));
                object         defaultForm = args.nth(3);
                IPersistentMap caseMap     = (IPersistentMap)args.nth(4);
                Keyword        switchType  = (Keyword)args.nth(5);
                Keyword        testType    = (Keyword)args.nth(6);
                IPersistentSet skipCheck   = RT.count(args) < 8 ? null : (IPersistentSet)args.nth(7);

                ISeq             keys     = RT.keys(caseMap);
                int              low      = Util.ConvertToInt(RT.first(keys));
                int              high     = Util.ConvertToInt(RT.nth(keys, RT.count(keys) - 1));
                LocalBindingExpr testexpr = (LocalBindingExpr)Compiler.Analyze(pcon.SetRhc(RHC.Expression), exprForm);


                SortedDictionary <int, Expr> tests = new SortedDictionary <int, Expr>();
                Dictionary <int, Expr>       thens = new Dictionary <int, Expr>();

                foreach (IMapEntry me in caseMap)
                {
                    int    minhash  = Util.ConvertToInt(me.key());
                    object pair     = me.val(); // [test-val then-expr]
                    object first    = RT.first(pair);
                    Expr   testExpr = testType == _intKey
                        ? NumberExpr.Parse(Util.ConvertToInt(first))
                        : (first == null ? Compiler.NilExprInstance : new ConstantExpr(first));

                    tests[minhash] = testExpr;
                    Expr thenExpr;
                    thenExpr       = Compiler.Analyze(pcon, RT.second(pair));
                    thens[minhash] = thenExpr;
                }

                Expr defaultExpr;

                defaultExpr = Compiler.Analyze(pcon, defaultForm);

                return(new CaseExpr(
                           (IPersistentMap)Compiler.SourceSpanVar.deref(),
                           testexpr,
                           shift,
                           mask,
                           low,
                           high,
                           defaultExpr,
                           tests,
                           thens,
                           switchType,
                           testType,
                           skipCheck));
            }