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 TridentTuple create(TridentTupleView parent, List<Object> selfVals) { IPersistentVector curr = parent._delegates; curr = (IPersistentVector) RT.conj(curr, selfVals); return new TridentTupleView(curr, _index, _fieldIndex); }
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(); } }
ret.name = className.toString(); ret.classMeta = RT.meta(className); ret.internalName = ret.name.replace('.', '/'); ret.objtype = Type.getObjectType(ret.internalName); 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]; Var.pushThreadBindings( RT.mapUniqueKeys(CONSTANTS, PersistentVector.EMPTY, CONSTANT_IDS, new IdentityHashMap(), KEYWORDS, PersistentHashMap.EMPTY, Var.pushThreadBindings(RT.mapUniqueKeys(METHOD, null, LOCAL_ENV, ret.fields , COMPILE_STUB_SYM, Symbol.intern(null, tagName) , COMPILE_STUB_CLASS, stub)); ret.hintedFields = RT.subvec(fieldSyms, 0, fieldSyms.count() - ret.altCtorDrops); ret.column = columnDeref(); IPersistentCollection methods = null; for(ISeq s = methodForms; s != null; s = RT.next(s)) NewInstanceMethod m = NewInstanceMethod.parse(ret, (ISeq) RT.first(s),thistag, overrideables); methods = RT.conj(methods, m);
@SuppressWarnings("unchecked") @Override public void open(final Map conf, final TopologyContext context, final SpoutOutputCollector collector) { IFn hof = Utils.loadClojureFn(_fnSpec.get(0), _fnSpec.get(1)); try { IFn preparer = (IFn) hof.applyTo(RT.seq(_params)); final Map<Keyword, Object> collectorMap = new PersistentArrayMap(new Object[]{Keyword.intern(Symbol.create("output-collector")), collector, Keyword.intern(Symbol.create("context")), context}); List<Object> args = new ArrayList<Object>() { { add(conf); add(context); add(collectorMap); } }; _spout = (ISpout) preparer.applyTo(RT.seq(args)); // this is kind of unnecessary for clojure try { _spout.open(conf, context, collector); } catch (AbstractMethodError ignored) { } } catch (Exception e) { throw new RuntimeException(e); } }
fn.onceOnly = RT.booleanCast(RT.get(RT.meta(form.first()), Keyword.intern(null, "once"))); if(RT.second(form) instanceof Symbol) { nm = (Symbol) RT.second(form); name = nm.name + "__" + RT.nextID(); } else { if(name == null) name = "fn__" + RT.nextID(); else if (enclosingMethod != null) name += "__" + RT.nextID(); Var.pushThreadBindings( RT.mapUniqueKeys(CONSTANTS, PersistentVector.EMPTY, CONSTANT_IDS, new IdentityHashMap(), KEYWORDS, PersistentHashMap.EMPTY, form = RT.cons(FN, RT.next(RT.next(form))); if(RT.second(form) instanceof IPersistentVector) form = RT.list(FN, RT.next(form)); fn.line = lineDeref(); fn.column = columnDeref(); FnMethod[] methodArray = new FnMethod[MAX_POSITIONAL_ARITY + 1]; FnMethod variadicMethod = null; for(ISeq s = RT.next(form); s != null; s = RT.next(s)) FnMethod f = FnMethod.parse(fn, (ISeq) RT.first(s), fn.isStatic); if(f.isVariadic())
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); return RT.var(vs.ns, vs.name); //Compiler.resolve((Symbol) RT.second(o),true); Object[] args = RT.toArray(RT.next(o)); return Reflector.invokeConstructor(RT.classForName(fs.name.substring(0, fs.name.length() - 1)), args); Object[] args = RT.toArray(RT.next(o)); return Reflector.invokeStaticMethod(fs.ns, fs.name, args); if(v instanceof Var) return ((IFn) v).applyTo(RT.next(o));
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 ); } }
/** * Generates a string for freetext questions. If the input question's freetextPattern field is not null, it will * generate a random regular expression. If the freetextPattern field is null, but the freetextDefault field is not, * it will return the default string. Otherwise, it will return the string "DEFAULT". * @param q The question whose string response we wish to generate. * @return A string for this respondent's response. */ protected String generateStringComponent(Question q) { if (q.freetextPattern!=null){ String pat = String.format("(re-rand/re-rand #\"%s\")", q.freetextPattern.pattern()); Var require = RT.var("clojure.core", "require"); Var eval = RT.var("clojure.core", "eval"); Var readString = RT.var("clojure.core", "read-string"); require.invoke(Symbol.intern("re-rand")); Object str = eval.invoke(readString.invoke(pat)); if (str instanceof String) return (String) str; return (String) ((PersistentVector) str).nth(0); } else if (q.freetextDefault!=null) return q.freetextDefault; else return "DEFAULT"; }
context = C.EXPRESSION; Expr fexpr = analyze(context, form.first()); if(fexpr instanceof VarExpr && ((VarExpr)fexpr).var.equals(INSTANCE) && RT.count(form) == 3) Expr sexpr = analyze(C.EXPRESSION, RT.second(form)); if(sexpr instanceof ConstantExpr) return new InstanceOfExpr((Class) val, analyze(context, RT.third(form))); Object arglists = RT.get(RT.meta(v), arglistsKey); int arity = RT.count(form.next()); for(ISeq s = RT.seq(arglists); s != null; s = s.next()) if(primc != null) return analyze(context, RT.listStar(Symbol.intern(".invokePrim"), ((Symbol) form.first()).withMeta(RT.map(RT.TAG_KEY, Symbol.intern(primc))), form.next())); break; if(fexpr instanceof KeywordExpr && RT.count(form) == 2 && KEYWORD_CALLSITES.isBound()) Expr target = analyze(context, RT.second(form)); return new KeywordInvokeExpr((String) SOURCE.deref(), lineDeref(), columnDeref(), tagOf(form), (KeywordExpr) fexpr, target); for(ISeq s = RT.seq(form.next()); s != null; s = s.next())
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));
return analyze(context, RT.list(RT.list(FNONCE, PersistentVector.EMPTY, form))); Var.pushThreadBindings(RT.map(NO_RECUR, true)); bodyExpr = (new BodyExpr.Parser()).parse(context, RT.seq(body)); } finally { Var.popThreadBindings(); Class c = HostExpr.maybeClass(RT.second(f), false); if(c == null) throw new IllegalArgumentException("Unable to resolve classname: " + RT.second(f)); if(!(RT.third(f) instanceof Symbol)) throw new IllegalArgumentException( "Bad binding form, expected symbol, got: " + RT.third(f)); Symbol sym = (Symbol) RT.third(f); if(sym.getNamespace() != null) throw Util.runtimeException("Can't bind qualified name:" + sym); IPersistentMap dynamicBindings = RT.map(LOCAL_ENV, LOCAL_ENV.deref(), NEXT_LOCAL_NUM, NEXT_LOCAL_NUM.deref(), IN_CATCH_FINALLY, RT.T); Var.pushThreadBindings(dynamicBindings); LocalBinding lb = registerLocal(sym, (Symbol) (RT.second(f) instanceof Symbol ? RT.second(f) : null), null,false); Expr handler = (new BodyExpr.Parser()).parse(C.EXPRESSION, RT.next(RT.next(RT.next(f)))); catches = catches.cons(new CatchClause(c, lb, handler));
static public Object instantiate(String implementation) throws Exception { Var require = RT.var("clojure.core", "require"); Var symbol = RT.var("clojure.core", "symbol"); require.invoke(symbol.invoke("clojure.plexus.factory.component-factory")); Var instantiate = RT.var( "clojure.plexus.factory.component-factory", "instantiate"); return instantiate.invoke(implementation); } }
private boolean prefers(Object x, Object y) { IPersistentSet xprefs = (IPersistentSet) getPreferTable().valAt(x); if(xprefs != null && xprefs.contains(y)) return true; for(ISeq ps = RT.seq(parents.invoke(y)); ps != null; ps = ps.next()) { if(prefers(x, ps.first())) return true; } for(ISeq ps = RT.seq(parents.invoke(x)); ps != null; ps = ps.next()) { if(prefers(ps.first(), y)) return true; } return false; }
@Override public boolean isMacro() { Var v=RT.var(sym.getNamespace(),sym.getName()); return KissUtils.isTruthy(v.meta().valAt(Keywords.MACRO)); }
String cljfile = scriptbase + ".clj"; String scriptfile = cljfile; URL classURL = getResource(baseLoader(),classfile); URL cljURL = getResource(baseLoader(), scriptfile); if(cljURL == null) { scriptfile = scriptbase + ".cljc"; cljURL = getResource(baseLoader(), scriptfile); || lastModified(classURL, classfile) > lastModified(cljURL, scriptfile))) || classURL == null) { try { Var.pushThreadBindings( RT.mapUniqueKeys(CURRENT_NS, CURRENT_NS.deref(), WARN_ON_REFLECTION, WARN_ON_REFLECTION.deref() ,RT.UNCHECKED_MATH, RT.UNCHECKED_MATH.deref())); loaded = (loadClassForName(scriptbase.replace('/', '.') + LOADER_SUFFIX) != null); if(booleanCast(Compiler.COMPILE_FILES.deref())) compile(scriptfile); else loadResourceScript(RT.class, scriptfile);
private void lazilyLoadGamerStub() { if (theClojureGamer == null) { try { // Load the Clojure script -- as a side effect this initializes the runtime. RT.loadResourceScript(getClojureGamerFile() + ".clj"); // Get a reference to the gamer-generating function. Var gamerVar = RT.var("gamer_namespace", getClojureGamerName()); // Call it! theClojureGamer = (Gamer)gamerVar.invoke(); } catch(Exception e) { GamerLogger.logError("GamePlayer", "Caught exception in Clojure initialization:"); GamerLogger.logStackTrace("GamePlayer", e); } } }