Refine search
public static IFn loadClojureFn(String namespace, String name) { try { clojure.lang.Compiler.eval(RT.readString("(require '" + namespace + ")")); } catch (Exception ignored) { // if playing from the repl and defining functions, file won't exist } return (IFn) RT.var(namespace, name).deref(); }
public FnLoaderThunk(Var v, String fnClassName){ this.v = v; this.loader = (ClassLoader) RT.FN_LOADER_VAR.get(); this.fnClassName = fnClassName; fn = null; }
@Override public Object eval(Reader reader, ScriptContext context) throws ScriptException { try { // Get engine bindings and send them to Clojure Bindings engineBindings = context.getBindings(ScriptContext.ENGINE_SCOPE); engineBindings.entrySet().forEach((entry) -> Var.intern(Namespace.findOrCreate(NAMESPACE_SYMBOL), Symbol.create(entry.getKey().intern()), entry.getValue(), true)); Var.pushThreadBindings( RT.map(RT.CURRENT_NS, RT.CURRENT_NS.deref(), RT.IN, new LineNumberingPushbackReader(context.getReader()), RT.OUT, context.getWriter(), RT.ERR, context.getErrorWriter())); Object result = Compiler.load(reader); return result; } catch (Exception e) { throw new ScriptException(e); } finally { Namespace.remove(NAMESPACE_SYMBOL); } }
static void doInit() throws ClassNotFoundException, IOException{ Protocol.init(); load("clojure/core"); Var.pushThreadBindings( RT.mapUniqueKeys(CURRENT_NS, CURRENT_NS.deref(), WARN_ON_REFLECTION, WARN_ON_REFLECTION.deref() ,RT.UNCHECKED_MATH, RT.UNCHECKED_MATH.deref())); try { Symbol USER = Symbol.intern("user"); Symbol CLOJURE = Symbol.intern("clojure.core"); Var in_ns = var("clojure.core", "in-ns"); Var refer = var("clojure.core", "refer"); in_ns.invoke(USER); refer.invoke(CLOJURE); maybeLoadResourceScript("user.clj"); } finally { Var.popThreadBindings(); } }
if(form instanceof Symbol) { if(Compiler.isQualifiedSpecial(form) || ((Compiler.currentNS().getMapping((Symbol)form) == null) && (Compiler.isSpecial(form)))) ret = RT.list(Compiler.QUOTE, form); else { Symbol sym = (Symbol) form; if(sym.ns == null && sym.name.endsWith("#")) IPersistentMap gmap = (IPersistentMap) GENSYM_ENV.deref(); if(gmap == null) throw new IllegalStateException("Gensym literal not in syntax-quote"); Symbol gs = (Symbol) gmap.valAt(sym); if(gs == null) GENSYM_ENV.set(gmap.assoc(sym, gs = Symbol.intern(null, sym.name.substring(0, sym.name.length() - 1) + "__" + RT.nextID() + "__auto__"))); sym = gs; Symbol csym = Symbol.intern(null, sym.name.substring(0, sym.name.length() - 1)); csym = Compiler.resolveSymbol(csym); sym = Symbol.intern(null, csym.name.concat(".")); sym = Compiler.resolveSymbol(sym); ret = RT.list(Compiler.QUOTE, sym); IPersistentMap newMeta = ((IObj) form).meta().without(RT.LINE_KEY).without(RT.COLUMN_KEY); if(newMeta.count() > 0) return RT.list(WITH_META, ret, syntaxQuote(((IObj) form).meta()));
for(ISeq s = RT.seq(interfaceSyms);s!=null;s = s.next()) Map[] mc = gatherMethods(superClass,RT.seq(interfaces)); Map overrideables = mc[0]; Map covariants = mc[1]; Symbol thistag = Symbol.intern(null,stub.getName()); Var.pushThreadBindings( if(ret.isDeftype()) Var.pushThreadBindings(RT.mapUniqueKeys(METHOD, null, LOCAL_ENV, ret.fields , COMPILE_STUB_SYM, Symbol.intern(null, tagName) , COMPILE_STUB_CLASS, stub)); ret.keywords = (IPersistentMap) KEYWORDS.deref(); ret.vars = (IPersistentMap) VARS.deref(); ret.constants = (PersistentVector) CONSTANTS.deref(); ret.constantsID = RT.nextID(); ret.keywordCallsites = (IPersistentVector) KEYWORD_CALLSITES.deref(); ret.protocolCallsites = (IPersistentVector) PROTOCOL_CALLSITES.deref(); ret.varCallsites = (IPersistentSet) VAR_CALLSITES.deref(); Var.popThreadBindings(); Var.popThreadBindings();
protected Var var(String namespacedFunction) { ClassLoader origLoader = preInvoke(); try { Var var = (Var)this.resolve.invoke(Symbol.create(namespacedFunction)); if (var == null) { String[] parts = namespacedFunction.split("/"); this.require.invoke(Symbol.create(parts[0])); var = RT.var(parts[0], parts[1]); } return var; } catch (Exception e) { throw new RuntimeException( "Failed to load Var " + namespacedFunction, e ); } finally { postInvoke( origLoader ); } }
if(true)//!LOADER.isBound()) Var.pushThreadBindings(RT.map(LOADER, RT.makeClassLoader())); createdLoader = true; if(RT.meta(form) != null && RT.meta(form).containsKey(RT.LINE_KEY)) line = RT.meta(form).valAt(RT.LINE_KEY); if(RT.meta(form) != null && RT.meta(form).containsKey(RT.COLUMN_KEY)) column = RT.meta(form).valAt(RT.COLUMN_KEY); Var.pushThreadBindings(RT.map(LINE, line, COLUMN, column)); try "eval" + RT.nextID()); IFn fn = (IFn) fexpr.eval(); return fn.invoke(); Var.popThreadBindings(); Var.popThreadBindings();
FnExpr fn = new FnExpr(tagOf(form)); fn.src = form; ObjMethod enclosingMethod = (ObjMethod) METHOD.deref(); if(((IMeta) form.first()).meta() != null) fn.onceOnly = RT.booleanCast(RT.get(RT.meta(form.first()), Keyword.intern(null, "once"))); try Var.pushThreadBindings( RT.mapUniqueKeys(CONSTANTS, PersistentVector.EMPTY, CONSTANT_IDS, new IdentityHashMap(), fn.keywords = (IPersistentMap) KEYWORDS.deref(); fn.vars = (IPersistentMap) VARS.deref(); fn.constants = (PersistentVector) CONSTANTS.deref(); fn.keywordCallsites = (IPersistentVector) KEYWORD_CALLSITES.deref(); fn.protocolCallsites = (IPersistentVector) PROTOCOL_CALLSITES.deref(); fn.varCallsites = (IPersistentSet) VAR_CALLSITES.deref(); fn.constantsID = RT.nextID(); Var.popThreadBindings(); fn.hasMeta = RT.count(fmeta) > 0;
public Expr parse(C context, Object form) { throw Util.runtimeException("Can't create defs outside of current ns"); IPersistentMap mm = sym.meta(); boolean isDynamic = RT.booleanCast(RT.get(mm,dynamicKey)); if(isDynamic) v.setDynamic(); if(!isDynamic && sym.name.startsWith("*") && sym.name.endsWith("*") && sym.name.length() > 2) RT.errPrintWriter().format("Warning: %1$s not declared dynamic and thus is not dynamically rebindable, " +"but its name suggests otherwise. Please either indicate ^:dynamic %1$s or change the name. (%2$s:%3$d)\n", sym, SOURCE_PATH.get(), LINE.get()); IPersistentMap vm = v.meta(); vm = (IPersistentMap) RT.assoc(vm,arglistsKey,RT.second(mm.valAt(arglistsKey))); v.setMeta(vm); Object source_path = SOURCE_PATH.get(); source_path = source_path == null ? "NO_SOURCE_FILE" : source_path; mm = (IPersistentMap) RT.assoc(mm, RT.LINE_KEY, LINE.get()).assoc(RT.COLUMN_KEY, COLUMN.get()).assoc(RT.FILE_KEY, source_path); if (docstring != null) mm = (IPersistentMap) RT.assoc(mm, RT.DOC_KEY, docstring); Expr meta = mm.count()==0 ? null:analyze(context == C.EVAL ? context : C.EXPRESSION, mm); return new DefExpr((String) SOURCE.deref(), lineDeref(), columnDeref(), v, analyze(context == C.EVAL ? context : C.EXPRESSION, RT.third(form), v.sym.name), meta, RT.count(form) == 3, isDynamic, shadowsCoreMapping);
ObjMethod method = (ObjMethod) METHOD.deref(); IPersistentMap backupMethodLocals = method.locals; IPersistentMap backupMethodIndexLocals = method.indexlocals; IPersistentMap dynamicBindings = RT.map(LOCAL_ENV, LOCAL_ENV.deref(), NEXT_LOCAL_NUM, NEXT_LOCAL_NUM.deref()); method.locals = backupMethodLocals; method.indexlocals = backupMethodIndexLocals; PathNode looproot = new PathNode(PATHTYPE.PATH, (PathNode) CLEAR_PATH.get()); PathNode clearroot = new PathNode(PATHTYPE.PATH,looproot); PathNode clearpath = new PathNode(PATHTYPE.PATH,looproot); if(isLoop) dynamicBindings = dynamicBindings.assoc(LOOP_LOCALS, null); Var.pushThreadBindings(dynamicBindings); if(RT.booleanCast(RT.WARN_ON_REFLECTION.deref())) Var.pushThreadBindings( Var.popThreadBindings(); LOOP_LOCALS.set(loopLocals); Expr bodyExpr; boolean moreMismatches = false; Var.pushThreadBindings(
try { IFn loadFile = Clojure.var("clojure.core", "load-file"); returnValue = loadFile.invoke(file.getCanonicalPath()); } catch (IOException e) { throw new LoadException(file, e); String namespace = ns.name.getName(); if (var.ns.toString().equals(namespace)) { String name = entry.getKey().toString(); if (var.deref() instanceof IFn) { Function f = new ClojureFunction(name, var.fn()); builder.put(name, f);
private static Expr analyzeSeq(C context, ISeq form, String name) { Object line = lineDeref(); Object column = columnDeref(); if(RT.meta(form) != null && RT.meta(form).containsKey(RT.LINE_KEY)) line = RT.meta(form).valAt(RT.LINE_KEY); if(RT.meta(form) != null && RT.meta(form).containsKey(RT.COLUMN_KEY)) column = RT.meta(form).valAt(RT.COLUMN_KEY); Var.pushThreadBindings( RT.map(LINE, line, COLUMN, column)); try IFn inline = isInline(op, RT.count(RT.next(form))); if(inline != null) return analyze(context, preserveTag(form, inline.applyTo(RT.next(form)))); IParser p; if(op.equals(QFN) || op.equals(FN)) throw new CompilerException((String) SOURCE_PATH.deref(), lineDeref(), columnDeref(), e); else throw (CompilerException) e; Var.popThreadBindings();
public Object invoke(Object reader, Object eq, Object opts, Object pendingForms) { if (!RT.booleanCast(RT.READEVAL.deref())) if(o instanceof Symbol) return RT.classForName(o.toString()); Symbol fs = (Symbol) RT.first(o); if(fs.equals(THE_VAR) || (!Compiler.isQualifiedSpecials() && fs.equals(Compiler.QTHE_VAR))) Symbol vs = (Symbol) RT.second(o); if(v instanceof Var) return ((IFn) v).applyTo(RT.next(o));
private Object readTagged(Object o, Symbol tag, Object opts, Object pendingForms){ ILookup data_readers = (ILookup)RT.DATA_READERS.deref(); IFn data_reader = (IFn)RT.get(data_readers, tag); if(data_reader == null){ data_readers = (ILookup)RT.DEFAULT_DATA_READERS.deref(); data_reader = (IFn)RT.get(data_readers, tag); if(data_reader == null){ IFn default_reader = (IFn)RT.DEFAULT_DATA_READER_FN.deref(); if(default_reader != null) return default_reader.invoke(tag, o); else throw new RuntimeException("No reader function for tag " + tag.toString()); } } return data_reader.invoke(o); }
public Object invoke(Object reader, Object eq) { if (!RT.booleanCast(RT.READEVAL.deref())) Symbol fs = (Symbol) RT.first(o); if(fs.equals(THE_VAR)) Symbol vs = (Symbol) RT.second(o); return RT.var(vs.ns, vs.name); //Compiler.resolve((Symbol) RT.second(o),true); if(v instanceof Var) return ((IFn) v).applyTo(RT.next(o));
static void compile1(GeneratorAdapter gen, ObjExpr objx, Object form) { Object line = lineDeref(); Object column = columnDeref(); if(RT.meta(form) != null && RT.meta(form).containsKey(RT.LINE_KEY)) line = RT.meta(form).valAt(RT.LINE_KEY); if(RT.meta(form) != null && RT.meta(form).containsKey(RT.COLUMN_KEY)) column = RT.meta(form).valAt(RT.COLUMN_KEY); Var.pushThreadBindings( RT.map(LINE, line, COLUMN, column ,LOADER, RT.makeClassLoader() objx.keywords = (IPersistentMap) KEYWORDS.deref(); objx.vars = (IPersistentMap) VARS.deref(); objx.constants = (PersistentVector) CONSTANTS.deref(); expr.emit(C.EXPRESSION, objx, gen); expr.eval(); Var.popThreadBindings();