Exemple #1
0
 public override object Eval()
 {
     try
     {
         object   targetVal = _target.Eval();
         object[] argvals   = new object[_args.Count];
         for (int i = 0; i < _args.Count; i++)
         {
             argvals[i] = _args[i].ArgExpr.Eval();
         }
         if (_method != null)
         {
             return(Reflector.InvokeMethod(_method, targetVal, argvals));
         }
         return(Reflector.CallInstanceMethod(_methodName, _typeArgs, targetVal, argvals));
     }
     catch (Compiler.CompilerException)
     {
         throw;
     }
     catch (Exception e)
     {
         throw new Compiler.CompilerException(_source, Compiler.GetLineFromSpanMap(_spanMap), Compiler.GetColumnFromSpanMap(_spanMap), e);
     }
 }
        public override object EvalAssign(Expr val)
        {
            object e = val.Eval();

            _tinfo.SetValue(null, e, new object[0]);
            return(e);
        }
Exemple #3
0
 public object Eval()
 {
     try
     {
         if (_initProvided)
         {
             _var.bindRoot(_init.Eval());
         }
         if (_meta != null)
         {
             if (_initProvided || true) // includesExplicitMetadata((MapExpr)_meta))
             {
                 _var.setMeta((IPersistentMap)_meta.Eval());
             }
         }
         return(_var.setDynamic(_isDynamic));
     }
     catch (Compiler.CompilerException)
     {
         throw;
     }
     catch (Exception e)
     {
         throw new Compiler.CompilerException(_source, _line, _column, e);
     }
 }
Exemple #4
0
        public override object EvalAssign(Expr val)
        {
            object target = _target.Eval();
            object e      = val.Eval();

            _tinfo.SetValue(target, e, new object[0]);
            return(e);
        }
Exemple #5
0
        public object Eval()
        {
            Object t = _testExpr.Eval();

            if (RT.booleanCast(t))
            {
                return(_thenExpr.Eval());
            }
            return(_elseExpr.Eval());
        }
        public override object EvalAssign(Expr val)
        {
            if (_tinfo.IsInitOnly)
            {
                throw new InvalidOperationException(String.Format("Attempt to set readonly static field {0} in class {1}", _tinfo.Name, _tinfo.DeclaringType));
            }

            object e = val.Eval();

            _tinfo.SetValue(null, e);
            return(e);
        }
Exemple #7
0
        public override object EvalAssign(Expr val)
        {
            object target = _target.Eval();
            object e      = val.Eval();

            if (_tinfo.IsInitOnly)
            {
                throw new InvalidOperationException(String.Format("Attempt to set readonly field {0} in class {1}", _tinfo.Name, _targetType));
            }

            _tinfo.SetValue(target, e);
            return(e);
        }
Exemple #8
0
 public object Eval()
 {
     try
     {
         return(_kw.Kw.invoke(_target.Eval()));
     }
     catch (Compiler.CompilerException)
     {
         throw;
     }
     catch (Exception e)
     {
         throw new Compiler.CompilerException(_source, Compiler.GetLineFromSpanMap(_spanMap), Compiler.GetColumnFromSpanMap(_spanMap), e);
     }
 }
Exemple #9
0
        public static Expr Parse(ParserContext pcon, IPersistentMap form)
        {
            ParserContext pconToUse = pcon.EvalOrExpr();

            bool           keysConstant          = true;
            bool           valsConstant          = true;
            bool           allConstantKeysUnique = true;
            IPersistentSet constantKeys          = PersistentHashSet.EMPTY;

            IPersistentVector keyvals = PersistentVector.EMPTY;

            for (ISeq s = RT.seq(form); s != null; s = s.next())
            {
                IMapEntry e = (IMapEntry)s.first();
                Expr      k = Compiler.Analyze(pconToUse, e.key());
                Expr      v = Compiler.Analyze(pconToUse, e.val());
                keyvals = (IPersistentVector)keyvals.cons(k);
                keyvals = (IPersistentVector)keyvals.cons(v);
                if (k is LiteralExpr)
                {
                    object kval = k.Eval();
                    if (constantKeys.contains(kval))
                    {
                        allConstantKeysUnique = false;
                    }
                    else
                    {
                        constantKeys = (IPersistentSet)constantKeys.cons(kval);
                    }
                }
                else
                {
                    keysConstant = false;
                }
                if (!(v is LiteralExpr))
                {
                    valsConstant = false;
                }
            }

            Expr ret = new MapExpr(keyvals);

            if (form is IObj iobjForm && iobjForm.meta() != null)
            {
                return(Compiler.OptionallyGenerateMetaInit(pcon, form, ret));
            }
Exemple #10
0
        public void Emit(RHC rhc, ObjExpr objx, CljILGen ilg)
        {
            bool           allKeysConstant       = true;
            bool           allConstantKeysUnique = true;
            IPersistentSet constantKeys          = PersistentHashSet.EMPTY;

            for (int i = 0; i < _keyvals.count(); i += 2)
            {
                Expr k = (Expr)_keyvals.nth(i);
                if (k is LiteralExpr)
                {
                    object kval = k.Eval();
                    if (constantKeys.contains(kval))
                    {
                        allConstantKeysUnique = false;
                    }
                    else
                    {
                        constantKeys = (IPersistentSet)constantKeys.cons(kval);
                    }
                }
                else
                {
                    allKeysConstant = false;
                }
            }

            MethodExpr.EmitArgsAsArray(_keyvals, objx, ilg);

            if ((allKeysConstant && allConstantKeysUnique) || (_keyvals.count() <= 2))
            {
                ilg.EmitCall(Compiler.Method_RT_mapUniqueKeys);
            }
            else
            {
                ilg.EmitCall(Compiler.Method_RT_map);
            }

            if (rhc == RHC.Statement)
            {
                ilg.Emit(OpCodes.Pop);
            }
        }
Exemple #11
0
 public object Eval()
 {
     try
     {
         IFn fn = (IFn)_fexpr.Eval();
         IPersistentVector argvs = PersistentVector.EMPTY;
         for (int i = 0; i < _args.count(); i++)
         {
             argvs = (IPersistentVector)argvs.cons(((Expr)_args.nth(i)).Eval());
         }
         return(fn.applyTo(RT.seq(Util.Ret1(argvs, argvs = null))));
     }
     catch (Compiler.CompilerException)
     {
         throw;
     }
     catch (Exception e)
     {
         throw new Compiler.CompilerException(_source, Compiler.GetLineFromSpanMap(_spanMap), Compiler.GetColumnFromSpanMap(_spanMap), e);
     }
 }
Exemple #12
0
 public object Eval()
 {
     return(((IObj)_expr.Eval()).withMeta((IPersistentMap)_meta.Eval()));
 }
Exemple #13
0
 public object EvalAssign(Expr val)
 {
     return _var.set(val.Eval());
 }
Exemple #14
0
        // TODO: Handle by-ref
        public override object Eval()
        {
            object target = _target.Eval();

            return(Reflector.CallInstanceMethod(_memberName, null, target, new object[0]));
        }
Exemple #15
0
 public object EvalAssign(Expr val)
 {
     return(_var.set(val.Eval()));
 }
 public object Eval()
 {
     return(_t.IsInstanceOfType(_expr.Eval()));
 }
Exemple #17
0
        public static Expr Parse(ParserContext pcon, IPersistentMap form)
        {
            ParserContext pconToUse = pcon.EvalOrExpr();

            bool           keysConstant          = true;
            bool           valsConstant          = true;
            bool           allConstantKeysUnique = true;
            IPersistentSet constantKeys          = PersistentHashSet.EMPTY;

            IPersistentVector keyvals = PersistentVector.EMPTY;

            for (ISeq s = RT.seq(form); s != null; s = s.next())
            {
                IMapEntry e = (IMapEntry)s.first();
                Expr      k = Compiler.Analyze(pconToUse, e.key());
                Expr      v = Compiler.Analyze(pconToUse, e.val());
                keyvals = (IPersistentVector)keyvals.cons(k);
                keyvals = (IPersistentVector)keyvals.cons(v);
                if (k is LiteralExpr)
                {
                    object kval = k.Eval();
                    if (constantKeys.contains(kval))
                    {
                        allConstantKeysUnique = false;
                    }
                    else
                    {
                        constantKeys = (IPersistentSet)constantKeys.cons(kval);
                    }
                }
                else
                {
                    keysConstant = false;
                }
                if (!(v is LiteralExpr))
                {
                    valsConstant = false;
                }
            }

            Expr ret = new MapExpr(keyvals);

            IObj iobjForm = form as IObj;

            if (iobjForm != null && iobjForm.meta() != null)
            {
                return(Compiler.OptionallyGenerateMetaInit(pcon, form, ret));
            }
            //else if (constant)
            //{
            // This 'optimzation' works, mostly, unless you have nested map values.
            // The nested map values do not participate in the constants map, so you end up with the code to create the keys.
            // Result: huge duplication of keyword creation.  3X increase in init time to the REPL.
            //    //IPersistentMap m = PersistentHashMap.EMPTY;
            //    //for (int i = 0; i < keyvals.length(); i += 2)
            //    //    m = m.assoc(((LiteralExpr)keyvals.nth(i)).Val, ((LiteralExpr)keyvals.nth(i + 1)).Val);
            //    //return new ConstantExpr(m);
            //    return ret;
            //}
            else if (keysConstant)
            {
                // TBD: Add more detail to exception thrown below.
                if (!allConstantKeysUnique)
                {
                    throw new ArgumentException("Duplicate constant keys in map");
                }
                if (valsConstant)
                {
                    // This 'optimzation' works, mostly, unless you have nested map values.
                    // The nested map values do not participate in the constants map, so you end up with the code to create the keys.
                    // Result: huge duplication of keyword creation.  3X increase in init time to the REPL.
                    //IPersistentMap m = PersistentHashMap.EMPTY;
                    //for (int i = 0; i < keyvals.length(); i += 2)
                    //    m = m.assoc(((LiteralExpr)keyvals.nth(i)).Val, ((LiteralExpr)keyvals.nth(i + 1)).Val);
                    //return new ConstantExpr(m);
                    return(ret);
                }
                else
                {
                    return(ret);
                }
            }
            else
            {
                return(ret);
            }
        }