public void AddLocal(int index, LocalBinding lb) { Locals = (IPersistentMap)RT.assoc(Locals, lb, lb); IndexLocals = (IPersistentMap)RT.assoc(IndexLocals, index, lb); }
protected override object Read(PushbackTextReader r, char caret, object opts) { int startLine = -1; int startCol = -1; LineNumberingTextReader lntr = r as LineNumberingTextReader; if (lntr != null) { startLine = lntr.LineNumber; startCol = lntr.ColumnNumber; } IPersistentMap metaAsMap; { object meta = ReadAux(r, opts); if (meta is Symbol || meta is String) { metaAsMap = RT.map(RT.TagKey, meta); } else if (meta is Keyword) { metaAsMap = RT.map(meta, true); } else if ((metaAsMap = meta as IPersistentMap) == null) { throw new ArgumentException("Metadata must be Symbol,Keyword,String or Map"); } } object o = ReadAux(r, opts); if (o is IMeta) { if (startLine != -1 && o is ISeq) { metaAsMap = metaAsMap.assoc(RT.LineKey, startLine) .assoc(RT.ColumnKey, startCol) .assoc(RT.SourceSpanKey, RT.map( RT.StartLineKey, startLine, RT.StartColumnKey, startCol, RT.EndLineKey, lntr.LineNumber, RT.EndColumnKey, lntr.ColumnNumber)); } if (o is IReference iref) { iref.resetMeta(metaAsMap); return(o); } object ometa = RT.meta(o); for (ISeq s = RT.seq(metaAsMap); s != null; s = s.next()) { IMapEntry kv = (IMapEntry)s.first(); ometa = RT.assoc(ometa, kv.key(), kv.val()); } return(((IObj)o).withMeta((IPersistentMap)ometa)); } else { throw new ArgumentException("Metadata can only be applied to IMetas"); } }
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); } } }
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)); }
public override object invoke(object m, object k, object v) { return(RT.assoc(m, k, v)); }