private void EmitExprForInts(ObjExpr objx, CljILGen ilg, Type exprType, Label defaultLabel)
 {
     if (exprType == null)
     {
         if (RT.booleanCast(RT.WarnOnReflectionVar.deref()))
         {
             RT.errPrintWriter().WriteLine("Performance warning, {0}:{1}:{2} - case has int tests, but tested expression is not primitive.",
                                           Compiler.SourcePathVar.deref(), Compiler.GetLineFromSpanMap(_sourceSpan), Compiler.GetColumnFromSpanMap(_sourceSpan));
         }
         _expr.Emit(RHC.Expression, objx, ilg);
         ilg.Emit(OpCodes.Call, Compiler.Method_Util_IsNonCharNumeric);
         ilg.Emit(OpCodes.Brfalse, defaultLabel);
         _expr.Emit(RHC.Expression, objx, ilg);
         ilg.Emit(OpCodes.Call, Compiler.Method_Util_ConvertToInt);
         EmitShiftMask(ilg);
     }
     else if (exprType == typeof(long) ||
              exprType == typeof(int) ||
              exprType == typeof(short) ||
              exprType == typeof(byte) ||
              exprType == typeof(ulong) ||
              exprType == typeof(uint) ||
              exprType == typeof(ushort) ||
              exprType == typeof(sbyte))
     {
         _expr.EmitUnboxed(RHC.Expression, objx, ilg);
         ilg.Emit(OpCodes.Conv_I4);
         EmitShiftMask(ilg);
     }
     else
     {
         ilg.Emit(OpCodes.Br, defaultLabel);
     }
 }
示例#2
0
        protected InstanceFieldOrPropertyExpr(string source, IPersistentMap spanMap, Symbol tag, Expr target, string memberName, TInfo tinfo)
        {
            _source     = source;
            _spanMap    = spanMap;
            _target     = target;
            _memberName = memberName;
            _tinfo      = tinfo;
            _tag        = tag;

            _targetType = target.HasClrType ? target.ClrType : null;

            // Java version does not include check on _targetType
            // However, this seems consistent with the checks in the generation code.
            if ((_targetType == null || _tinfo == null) && RT.booleanCast(RT.WarnOnReflectionVar.deref()))
            {
                if (_targetType == null)
                {
                    RT.errPrintWriter().WriteLine("Reflection warning, {0}:{1}:{2} - reference to field/property {3} can't be resolved.",
                                                  Compiler.SourcePathVar.deref(), Compiler.GetLineFromSpanMap(_spanMap), Compiler.GetColumnFromSpanMap(_spanMap), _memberName);
                }
                else
                {
                    RT.errPrintWriter().WriteLine("Reflection warning, {0}:{1}:{2} - reference to field/property {3} on {4} can't be resolved.",
                                                  Compiler.SourcePathVar.deref(), Compiler.GetLineFromSpanMap(_spanMap), Compiler.GetColumnFromSpanMap(_spanMap), _memberName, _targetType.FullName);
                }
            }
        }
        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));
            }
        }
示例#4
0
        private ConstructorInfo ComputeCtor()
        {
            if (Compiler.CompileStubClassVar.isBound && _type == (Type)Compiler.CompileStubClassVar.deref())
            {
                return(null);
            }

            int numArgs = _args.Count;

            int             numCtors;
            ConstructorInfo ctor = Reflector.GetMatchingConstructor(_spanMap, _type, _args, out numCtors);

            if (numCtors == 0)
            {
                if (_type.IsValueType && numArgs == 0)
                {
                    // Value types have a default no-arg c-tor that is not picked up in the regular c-tors.
                    _isNoArgValueTypeCtor = true;
                    return(null);
                }
                throw new InvalidOperationException(string.Format("No constructor in type: {0} with {1} arguments", _type.Name, numArgs));
            }

            if (ctor == null && RT.booleanCast(RT.WarnOnReflectionVar.deref()))
            {
                RT.errPrintWriter().WriteLine("Reflection warning, {0}:{1} - call to {2} ctor can't be resolved.",
                                              Compiler.SourcePathVar.deref(), _spanMap != null ? (int)_spanMap.valAt(RT.StartLineKey, 0) : 0, _type.FullName);
            }

            return(ctor);
        }
示例#5
0
        private Expression GenTestExprForInts(ObjExpr objx, GenContext context, Type exprType, LabelTarget defaultLabel)
        {
            if (exprType == null)
            {
                if (RT.booleanCast(RT.WarnOnReflectionVar.deref()))
                {
                    RT.errPrintWriter().WriteLine("Performance warning, {0}:{1} - case has int tests, but tested expression is not primitive.",
                                                  Compiler.SourcePathVar.deref(), RT.get(_sourceSpan, RT.StartLineKey));
                }

                ParameterExpression parm     = Expression.Parameter(typeof(object), "p");
                Expression          initParm = Expression.Assign(parm, _expr.GenCode(RHC.Expression, objx, context));
                Expression          testType = Expression.Call(null, Compiler.Method_Util_IsNonCharNumeric, parm); // matching JVM's handling of char as non-integer
                Expression          expr     = GenShiftMask(Expression.Call(null, Compiler.Method_Util_ConvertToInt, parm));
                return(Expression.Block(
                           new ParameterExpression[] { parm },
                           initParm,
                           Expression.IfThen(Expression.Not(testType), Expression.Goto(defaultLabel)),
                           expr));
            }
            else if (exprType == typeof(long) || exprType == typeof(int) || exprType == typeof(short) || exprType == typeof(byte) || exprType == typeof(ulong) || exprType == typeof(uint) || exprType == typeof(ushort) || exprType == typeof(sbyte))
            {
                Expression expr = Expression.Convert(_expr.GenCodeUnboxed(RHC.Expression, objx, context), typeof(int));
                return(GenShiftMask(expr));
            }
            else
            {
                return(Expression.Goto(defaultLabel));
            }
        }
示例#6
0
 private static void MaybeReflectionWarn(IPersistentMap spanMap, MethodBase method, string methodName, IList <HostArg> args)
 {
     if (method == null && RT.booleanCast(RT.WarnOnReflectionVar.deref()))
     {
         RT.errPrintWriter().WriteLine(string.Format("Reflection warning, {0}:{1} - call to {2} can't be resolved.",
                                                     Compiler.SourcePathVar.deref(), Compiler.GetLineFromSpanMap(spanMap), methodName));
     }
 }
示例#7
0
 public StaticMethodExpr(string source, IPersistentMap spanMap, Symbol tag, Type type, string methodName, IList <Type> typeArgs, IList <HostArg> args, bool tailPosition)
     : base(source, spanMap, tag, methodName, typeArgs, args, tailPosition)
 {
     _type   = type;
     _method = Reflector.GetMatchingMethod(spanMap, _type, _args, _methodName, typeArgs);
     if (_method != null && warnOnBoxedKeyword.Equals(RT.UncheckedMathVar.deref()) && IsBoxedMath(_method))
     {
         RT.errPrintWriter().WriteLine("Boxed math warning, {0}:{1}:{2} - call {3}.",
                                       Compiler.SourcePathVar.deref(), Compiler.GetLineFromSpanMap(spanMap), Compiler.GetColumnFromSpanMap(spanMap), _method.ToString());
     }
 }
示例#8
0
        static void Main(string[] args)
        {
            TextWriter outTW = (TextWriter)RT.OutVar.deref();
            TextWriter errTW = RT.errPrintWriter();

            string path = Environment.GetEnvironmentVariable(PATH_PROP);

            path = path ?? ".";

            string warnVal          = Environment.GetEnvironmentVariable(REFLECTION_WARNING_PROP);
            bool   warnOnReflection = warnVal == null ? false : warnVal.Equals("true");
            string mathVal          = Environment.GetEnvironmentVariable(UNCHECKED_MATH_PROP);
            bool   uncheckedMath    = mathVal == null ? false : mathVal.Equals("true");

            try
            {
                Var.pushThreadBindings(RT.map(
                                           Compiler.CompilePathVar, path,
                                           RT.WarnOnReflectionVar, warnOnReflection,
                                           RT.UncheckedMathVar, uncheckedMath
                                           ));

                Stopwatch sw = new Stopwatch();

                foreach (string lib in args)
                {
                    sw.Reset();
                    sw.Start();
                    outTW.Write("Compiling {0} to {1}", lib, path);
                    outTW.Flush();
                    Compiler.CompileVar.invoke(Symbol.intern(lib));
                    sw.Stop();
                    outTW.WriteLine(" -- {0} milliseconds.", sw.ElapsedMilliseconds);
                }
            }
            catch (Exception e)
            {
                errTW.WriteLine(e.ToString());
                Environment.Exit(1);
            }
            finally
            {
                Var.popThreadBindings();
                try {
                    outTW.Flush();
                }
                catch (IOException e)
                {
                    errTW.WriteLine(e.StackTrace);
                }
            }
        }
示例#9
0
        internal InstanceZeroArityCallExpr(string source, IPersistentMap spanMap, Symbol tag, Expr target, string memberName)
        {
            _source     = source;
            _spanMap    = spanMap;
            _memberName = memberName;
            _target     = target;
            _tag        = tag;

            _targetType = target.HasClrType ? target.ClrType : null;

            if (RT.booleanCast(RT.WarnOnReflectionVar.deref()))
            {
                RT.errPrintWriter().WriteLine("Reflection warning, {0}:{1}:{2} - reference to field/property {3} can't be resolved.",
                                              Compiler.SourcePathVar.deref(), Compiler.GetLineFromSpanMap(_spanMap), Compiler.GetColumnFromSpanMap(_spanMap), memberName);
            }
        }
示例#10
0
 private void WarnOrFailOnReplace(Symbol sym, object o, object v)
 {
     if (o is Var ovar)
     {
         Namespace ns = ovar.Namespace;
         Var       vv = v as Var;
         if (ns == this || (vv != null && vv.ns == RT.ClojureNamespace))
         {
             return;
         }
         if (ns != RT.ClojureNamespace)
         {
             throw new InvalidOperationException(sym + " already refers to: " + o + " in namespace: " + _name);
         }
     }
     RT.errPrintWriter().WriteLine("WARNING: {0} already refers to: {1} in namespace: {2}, being replaced by: {3}",
                                   sym, o, _name, v);
 }
示例#11
0
 private static void MaybeReflectionWarn(IPersistentMap spanMap, Type targetType, bool isStatic, bool hasMethods, MethodBase method, string methodName, IList <HostArg> args)
 {
     if (method == null && RT.booleanCast(RT.WarnOnReflectionVar.deref()))
     {
         if (targetType == null)
         {
             RT.errPrintWriter().WriteLine(string.Format("Reflection warning, {0}:{1}:{2} - call to method {4} can't be resolved (target class is unknown).",
                                                         Compiler.SourcePathVar.deref(), Compiler.GetLineFromSpanMap(spanMap), Compiler.GetColumnFromSpanMap(spanMap), (isStatic ? "static " : ""), methodName));
         }
         else if (hasMethods)
         {
             RT.errPrintWriter().WriteLine(string.Format("Reflection warning, {0}:{1}:{2} - call to {3}method {4} on {5} can't be resolved (argument types: {6}).",
                                                         Compiler.SourcePathVar.deref(), Compiler.GetLineFromSpanMap(spanMap), Compiler.GetColumnFromSpanMap(spanMap), (isStatic ? "static " : ""), methodName, targetType.FullName, GetTypeStringForArgs(args)));
         }
         else
         {
             RT.errPrintWriter().WriteLine(string.Format("Reflection warning, {0}:{1}:{2} - call to {3}method {4} on {5} can't be resolved (no such method).",
                                                         Compiler.SourcePathVar.deref(), Compiler.GetLineFromSpanMap(spanMap), Compiler.GetColumnFromSpanMap(spanMap), (isStatic ? "static " : ""), methodName, targetType.FullName, GetTypeStringForArgs(args)));
         }
     }
 }
示例#12
0
        static void Main(string[] args)
        {
            TextWriter outTW = (TextWriter)RT.OutVar.deref();
            TextWriter errTW = RT.errPrintWriter();

            string path = Environment.GetEnvironmentVariable(PATH_PROP);

            // TODO: get rid of this when we have the full build process set up
            path = path ?? ".";

            if (path == null)
            {
                errTW.WriteLine("ERROR: Must set system property {0}", PATH_PROP);
                errTW.WriteLine("to the location for the compiled .class files.");
                errTW.WriteLine("This directory must also be on your {0}.", RT.ClojureLoadPathString);
                Environment.Exit(1);
            }

            string warnVal          = Environment.GetEnvironmentVariable(REFLECTION_WARNING_PROP);
            bool   warnOnReflection = warnVal == null ? false : warnVal.Equals(true);
            string mathVal          = Environment.GetEnvironmentVariable(UNCHECKED_MATH_PROP);
            bool   uncheckedMath    = mathVal == null ? false : mathVal.Equals(true);

            try
            {
                Var.pushThreadBindings(RT.map(
                                           Compiler.CompilePathVar, path,
                                           RT.WarnOnReflectionVar, warnOnReflection,
                                           RT.UncheckedMathVar, uncheckedMath
                                           ));

                Stopwatch sw = new Stopwatch();

                foreach (string lib in args)
                {
                    sw.Reset();
                    sw.Start();
                    outTW.Write("Compiling {0} to {1}", lib, path);
                    outTW.Flush();
                    Compiler.CompileVar.invoke(Symbol.intern(lib));
                    sw.Stop();
                    outTW.WriteLine(" -- {0} milliseconds.", sw.ElapsedMilliseconds);
                }
            }
            catch (Exception e)
            {
                errTW.WriteLine(e.ToString());
                Environment.Exit(1);
            }
            finally
            {
                Var.popThreadBindings();
                try {
                    outTW.Flush();
                    outTW.Close();
                }
                catch (IOException e)
                {
                    errTW.WriteLine(e.StackTrace);
                }
            }
        }
示例#13
0
            public Expr Parse(ParserContext pcon, object frm)
            {
                string         source  = (string)Compiler.SourceVar.deref();
                IPersistentMap spanMap = (IPersistentMap)Compiler.SourceSpanVar.deref();  // Compiler.GetSourceSpanMap(form);

                ISeq form = (ISeq)frm;

                IPersistentVector loopLocals = (IPersistentVector)Compiler.LoopLocalsVar.deref();

                if (pcon.Rhc != RHC.Return || loopLocals == null)
                {
                    throw new ParseException("Can only recur from tail position");
                }

                if (Compiler.NoRecurVar.deref() != null)
                {
                    throw new ParseException("Cannot recur across try");
                }

                IPersistentVector args = PersistentVector.EMPTY;

                for (ISeq s = RT.seq(form.next()); s != null; s = s.next())
                {
                    args = args.cons(Compiler.Analyze(pcon.SetRhc(RHC.Expression).SetAssign(false), s.first()));
                }
                if (args.count() != loopLocals.count())
                {
                    throw new ParseException(string.Format("Mismatched argument count to recur, expected: {0} args, got {1}",
                                                           loopLocals.count(), args.count()));
                }

                for (int i = 0; i < loopLocals.count(); i++)
                {
                    LocalBinding lb    = (LocalBinding)loopLocals.nth(i);
                    Type         primt = lb.PrimitiveType;
                    if (primt != null)
                    {
                        bool mismatch = false;
                        Type pt       = Compiler.MaybePrimitiveType((Expr)args.nth(i));
                        if (primt == typeof(long))
                        {
                            if (!(pt == typeof(long) || pt == typeof(int) || pt == typeof(short) || pt == typeof(uint) || pt == typeof(ushort) || pt == typeof(ulong) ||
                                  pt == typeof(char) || pt == typeof(byte) || pt == typeof(sbyte)))
                            {
                                mismatch = true;
                            }
                        }
                        else if (primt == typeof(double))
                        {
                            if (!(pt == typeof(double) || pt == typeof(float)))
                            {
                                mismatch = true;
                            }
                        }

                        if (mismatch)
                        {
                            lb.RecurMismatch = true;
                            if (RT.booleanCast(RT.WarnOnReflectionVar.deref()))
                            {
                                RT.errPrintWriter().WriteLine("{0}:{1} recur arg for primitive local: {2} is not matching primitive, had: {3}, needed {4}",
                                                              source, spanMap != null ? (int)spanMap.valAt(RT.StartLineKey, 0) : 0,
                                                              lb.Name, pt != null ? pt.Name : "Object", primt.Name);
                            }
                        }
                    }
                }


                return(new RecurExpr(source, spanMap, loopLocals, args));
            }
示例#14
0
            public Expr Parse(ParserContext pcon, object form)
            {
                // (def x) or (def x initexpr) or (def x "docstring" initexpr)
                string docstring = null;

                if (RT.count(form) == 4 && (RT.third(form) is String))
                {
                    docstring = (String)RT.third(form);
                    form      = RT.list(RT.first(form), RT.second(form), RT.fourth(form));
                }

                if (RT.count(form) > 3)
                {
                    throw new ParseException("Too many arguments to def");
                }

                if (RT.count(form) < 2)
                {
                    throw new ParseException("Too few arguments to def");
                }

                Symbol sym = RT.second(form) as Symbol;

                if (sym == null)
                {
                    throw new ParseException("First argument to def must be a Symbol.");
                }

                //Console.WriteLine("Def {0}", sym.Name);

                Var v = Compiler.LookupVar(sym, true);

                if (v == null)
                {
                    throw new ParseException("Can't refer to qualified var that doesn't exist");
                }

                if (!v.Namespace.Equals(Compiler.CurrentNamespace))
                {
                    if (sym.Namespace == null)
                    {
                        v = Compiler.CurrentNamespace.intern(sym);
                        Compiler.RegisterVar(v);
                    }

                    //throw new Exception(string.Format("Name conflict, can't def {0} because namespace: {1} refers to: {2}",
                    //            sym, Compiler.CurrentNamespace.Name, v));
                    else
                    {
                        throw new ParseException("Can't create defs outside of current namespace");
                    }
                }

                IPersistentMap mm        = sym.meta();
                bool           isDynamic = RT.booleanCast(RT.get(mm, Compiler.DynamicKeyword));

                if (isDynamic)
                {
                    v.setDynamic();
                }
                if (!isDynamic && sym.Name.StartsWith("*") && sym.Name.EndsWith("*") && sym.Name.Length > 2)
                {
                    RT.errPrintWriter().WriteLine("Warning: {0} not declared dynamic and thus is not dynamically rebindable, "
                                                  + "but its name suggests otherwise. Please either indicate ^:dynamic {0} or change the name. ({1}:{2}\n",
                                                  sym, Compiler.SourcePathVar.get(), Compiler.LineVar.get());
                }

                if (RT.booleanCast(RT.get(mm, Compiler.ArglistsKeyword)))
                {
                    IPersistentMap vm = v.meta();
                    //vm = (IPersistentMap)RT.assoc(vm, Compiler.STATIC_KEY, true);
                    // drop quote
                    vm = (IPersistentMap)RT.assoc(vm, Compiler.ArglistsKeyword, RT.second(mm.valAt(Compiler.ArglistsKeyword)));
                    v.setMeta(vm);
                }

                Object source_path = Compiler.SourcePathVar.get();

                source_path = source_path ?? "NO_SOURCE_FILE";
                mm          = (IPersistentMap)RT.assoc(mm, RT.LineKey, Compiler.LineVar.get())
                              .assoc(RT.ColumnKey, Compiler.ColumnVar.get())
                              .assoc(RT.FileKey, source_path);
                //.assoc(RT.SOURCE_SPAN_KEY,Compiler.SOURCE_SPAN.deref());
                if (docstring != null)
                {
                    mm = (IPersistentMap)RT.assoc(mm, RT.DocKey, docstring);
                }

                //  Following comment in JVM version
                //mm = mm.without(RT.DOC_KEY)
                //            .without(Keyword.intern(null, "arglists"))
                //            .without(RT.FILE_KEY)
                //            .without(RT.LINE_KEY)
                //            .without(RT.COLUMN_KEY)
                //            .without(Keyword.intern(null, "ns"))
                //            .without(Keyword.intern(null, "name"))
                //            .without(Keyword.intern(null, "added"))
                //            .without(Keyword.intern(null, "static"));

                mm = (IPersistentMap)Compiler.ElideMeta(mm);

                Expr meta         = mm == null || mm.count() == 0 ? null : Compiler.Analyze(pcon.EvalOrExpr(), mm);
                Expr init         = Compiler.Analyze(pcon.EvalOrExpr(), RT.third(form), v.Symbol.Name);
                bool initProvided = RT.count(form) == 3;

                return(new DefExpr(
                           (string)Compiler.SourceVar.deref(),
                           Compiler.LineVarDeref(),
                           Compiler.ColumnVarDeref(),
                           v, init, meta, initProvided, isDynamic));
            }
示例#15
0
            public Expr Parse(ParserContext pcon, object frm)
            {
                ISeq form = (ISeq)frm;

                // form => (let  [var1 val1 var2 val2 ... ] body ... )
                //      or (loop [var1 val1 var2 val2 ... ] body ... )

                bool isLoop = RT.first(form).Equals(Compiler.LoopSym);

                if (!(RT.second(form) is IPersistentVector bindings))
                {
                    throw new ParseException("Bad binding form, expected vector");
                }

                if ((bindings.count() % 2) != 0)
                {
                    throw new ParseException("Bad binding form, expected matched symbol/value pairs.");
                }

                ISeq body = RT.next(RT.next(form));

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

                ObjMethod      method                  = (ObjMethod)Compiler.MethodVar.deref();
                IPersistentMap backupMethodLocals      = method.Locals;
                IPersistentMap backupMethodIndexLocals = method.IndexLocals;

                IPersistentVector recurMismatches = PersistentVector.EMPTY;

                for (int i = 0; i < bindings.count() / 2; i++)
                {
                    recurMismatches = recurMismatches.cons(false);
                }

                // may repeat once for each binding with a mismatch, return breaks
                while (true)
                {
                    IPersistentMap dynamicBindings = RT.map(
                        Compiler.LocalEnvVar, Compiler.LocalEnvVar.deref(),
                        Compiler.NextLocalNumVar, Compiler.NextLocalNumVar.deref());
                    method.SetLocals(backupMethodLocals, backupMethodIndexLocals);

                    if (isLoop)
                    {
                        dynamicBindings = dynamicBindings.assoc(Compiler.LoopLocalsVar, null);
                    }

                    try
                    {
                        Var.pushThreadBindings(dynamicBindings);

                        IPersistentVector bindingInits = PersistentVector.EMPTY;
                        IPersistentVector loopLocals   = PersistentVector.EMPTY;

                        for (int i = 0; i < bindings.count(); i += 2)
                        {
                            if (!(bindings.nth(i) is Symbol))
                            {
                                throw new ParseException("Bad binding form, expected symbol, got " + bindings.nth(i));
                            }

                            Symbol sym = (Symbol)bindings.nth(i);
                            if (sym.Namespace != null)
                            {
                                throw new ParseException("Can't let qualified name: " + sym);
                            }

                            Expr init = Compiler.Analyze(pcon.SetRhc(RHC.Expression).SetAssign(false), bindings.nth(i + 1), sym.Name);
                            if (isLoop)
                            {
                                if (recurMismatches != null && RT.booleanCast(recurMismatches.nth(i / 2)))
                                {
                                    HostArg        ha  = new HostArg(HostArg.ParameterType.Standard, init, null);
                                    List <HostArg> has = new List <HostArg>(1)
                                    {
                                        ha
                                    };
                                    init = new StaticMethodExpr("", PersistentArrayMap.EMPTY, null, typeof(RT), "box", null, has, false);
                                    if (RT.booleanCast(RT.WarnOnReflectionVar.deref()))
                                    {
                                        RT.errPrintWriter().WriteLine("Auto-boxing loop arg: " + sym);
                                    }
                                }
                                else if (Compiler.MaybePrimitiveType(init) == typeof(int))
                                {
                                    List <HostArg> args = new List <HostArg>
                                    {
                                        new HostArg(HostArg.ParameterType.Standard, init, null)
                                    };
                                    init = new StaticMethodExpr("", null, null, typeof(RT), "longCast", null, args, false);
                                }
                                else if (Compiler.MaybePrimitiveType(init) == typeof(float))
                                {
                                    List <HostArg> args = new List <HostArg>
                                    {
                                        new HostArg(HostArg.ParameterType.Standard, init, null)
                                    };
                                    init = new StaticMethodExpr("", null, null, typeof(RT), "doubleCast", null, args, false);
                                }
                            }

                            // Sequential enhancement of env (like Lisp let*)
                            LocalBinding b  = Compiler.RegisterLocal(sym, Compiler.TagOf(sym), init, typeof(Object), false);
                            BindingInit  bi = new BindingInit(b, init);
                            bindingInits = bindingInits.cons(bi);

                            if (isLoop)
                            {
                                loopLocals = loopLocals.cons(b);
                            }
                        }
                        if (isLoop)
                        {
                            Compiler.LoopLocalsVar.set(loopLocals);
                        }

                        Expr bodyExpr;
                        bool moreMismatches = false;
                        try
                        {
                            if (isLoop)
                            {
                                object methodReturnContext = pcon.Rhc == RHC.Return ? Compiler.MethodReturnContextVar.deref() : null;
                                // stuff with clear paths,
                                Var.pushThreadBindings(RT.map(Compiler.NoRecurVar, null,
                                                              Compiler.MethodReturnContextVar, methodReturnContext));
                            }
                            bodyExpr = new BodyExpr.Parser().Parse(isLoop ? pcon.SetRhc(RHC.Return) : pcon, body);
                        }
                        finally
                        {
                            if (isLoop)
                            {
                                Var.popThreadBindings();

                                for (int i = 0; i < loopLocals.count(); i++)
                                {
                                    LocalBinding lb = (LocalBinding)loopLocals.nth(i);
                                    if (lb.RecurMismatch)
                                    {
                                        recurMismatches = (IPersistentVector)recurMismatches.assoc(i, true);
                                        moreMismatches  = true;
                                    }
                                }
                            }
                        }

                        if (!moreMismatches)
                        {
                            return(new LetExpr(bindingInits, bodyExpr, isLoop));
                        }
                    }
                    finally
                    {
                        Var.popThreadBindings();
                    }
                }
            }
示例#16
0
        static void Main(string[] args)
        {
            TextWriter outTW = (TextWriter)RT.OutVar.deref();
            TextWriter errTW = RT.errPrintWriter();

            string path = Environment.GetEnvironmentVariable(PATH_PROP);

            path = path ?? ".";

            string warnVal          = Environment.GetEnvironmentVariable(REFLECTION_WARNING_PROP);
            bool   warnOnReflection = warnVal == null ? false : warnVal.Equals("true");
            string mathVal          = Environment.GetEnvironmentVariable(UNCHECKED_MATH_PROP);
            bool   uncheckedMath    = mathVal == null ? false : mathVal.Equals("true");

            object compilerOptions = null;

            foreach (DictionaryEntry kv in Environment.GetEnvironmentVariables())
            {
                String name = (String)kv.Key;
                String v    = (String)kv.Value;
                if (name.StartsWith("CLOJURE_COMPILER_"))
                {
                    compilerOptions = RT.assoc(compilerOptions
                                               , RT.keyword(null, name.Substring(1 + name.LastIndexOf('_')))
                                               , RT.readString(v));
                }
            }

            try
            {
                Var.pushThreadBindings(RT.map(
                                           Compiler.CompilePathVar, path,
                                           RT.WarnOnReflectionVar, warnOnReflection,
                                           RT.UncheckedMathVar, uncheckedMath,
                                           Compiler.CompilerOptionsVar, compilerOptions
                                           ));

                Stopwatch sw = new Stopwatch();

                foreach (string lib in args)
                {
                    sw.Reset();
                    sw.Start();
                    outTW.Write("Compiling {0} to {1}", lib, path);
                    outTW.Flush();
                    Compiler.CompileVar.invoke(Symbol.intern(lib));
                    sw.Stop();
                    outTW.WriteLine(" -- {0} milliseconds.", sw.ElapsedMilliseconds);
                }
            }
            catch (Exception e)
            {
                errTW.WriteLine(e.ToString());
                Environment.Exit(1);
            }
            finally
            {
                Var.popThreadBindings();
                try {
                    outTW.Flush();
                    outTW.Close();
                }
                catch (IOException e)
                {
                    errTW.WriteLine(e.StackTrace);
                }
            }
        }