private void init() { loader = ClojureClassLoaderFactory.newInstance(classPath, outDir); String loadFunctionPrefix = "run_str"; try { String clojureInitScript = String.format(initScriptSource(), beaker_clojure_ns, shellId, loadFunctionPrefix, NSClientProxy.class.getName()); String ns = String.format("%1$s_%2$s", beaker_clojure_ns, shellId); clearClojureNamespace(ns); clojureLoadString = RT.var(ns, String.format("%1$s_%2$s", loadFunctionPrefix, shellId)); clojure.lang.Compiler.load(new StringReader(clojureInitScript)); } catch (Exception e) { logger.error(e.getMessage()); } clojureAutocomplete = new ClojureAutocomplete(clojureLoadString, shellId, autocompletePatterns); }
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(); }
private static Expr analyzeSymbol(Symbol sym) { Symbol tag = tagOf(sym); if(sym.ns == null) //ns-qualified syms are always Vars LocalBinding b = referenceLocal(sym); if(b != null) if(namespaceFor(sym) == null) return new StaticFieldExpr(lineDeref(), columnDeref(), c, sym.name, tag); throw Util.runtimeException("Unable to find static field: " + sym.name + " in " + c); Object o = resolve(sym); if(o instanceof Var) if(isMacro(v) != null) throw Util.runtimeException("Can't take value of a macro: " + v); if(RT.booleanCast(RT.get(v.meta(),RT.CONST_KEY))) return analyze(C.EXPRESSION, RT.list(QUOTE, v.get())); registerVar(v); return new VarExpr(v, tag);
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); try Object me = macroexpand1(form); if(me != form) return analyze(context, me, name); 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)) return FnExpr.parse(context, form, name); else if((p = specialParser(op)) != null) return p.parse(context, form); else if((p = qualifiedSpecialParser(op)) != null) return p.parse(context, form); else throw new CompilerException((String) SOURCE_PATH.deref(), lineDeref(), columnDeref(), e); else throw (CompilerException) e;
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); try form = macroexpand(form); if(form instanceof ISeq && (Util.equals(RT.first(form), QDO) || Util.equals(RT.first(form), DO))) eval(RT.first(s), false); return eval(RT.first(s), false); && ((Symbol) RT.first(form)).name.startsWith("def")))) ObjExpr fexpr = (ObjExpr) analyze(C.EXPRESSION, RT.list(FN, PersistentVector.EMPTY, form), "eval" + RT.nextID()); IFn fn = (IFn) fexpr.eval(); Expr expr = analyze(C.EVAL, form); return expr.eval();
Class fclass = form.getClass(); if(fclass == Symbol.class) return analyzeSymbol((Symbol) form); else if(fclass == Keyword.class) return registerKeyword((Keyword) form); else if(form instanceof Number) return NumberExpr.parse((Number) form); return analyzeSeq(context, (ISeq) form, name); else if(form instanceof IPersistentVector) return VectorExpr.parse(context, (IPersistentVector) form); throw new CompilerException((String) SOURCE_PATH.deref(), lineDeref(), columnDeref(), e); else throw (CompilerException) e;
throw Util.runtimeException("First argument to def must be a Symbol"); Symbol sym = (Symbol) RT.second(form); Var v = lookupVar(sym, true); if(v == null) throw Util.runtimeException("Can't refer to qualified var that doesn't exist"); boolean shadowsCoreMapping = false; if(!v.ns.equals(currentNS())) v = currentNS().intern(sym); shadowsCoreMapping = true; registerVar(v); mm = (IPersistentMap) elideMeta(mm); 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);
(rdr instanceof LineNumberingPushbackReader) ? (LineNumberingPushbackReader) rdr : new LineNumberingPushbackReader(rdr); consumeWhitespaces(pushbackReader); Var.pushThreadBindings( RT.mapUniqueKeys(LOADER, RT.makeClassLoader(), )); Object readerOpts = readerOpts(sourceName); try r = LispReader.read(pushbackReader, false, EOF, false, readerOpts)) consumeWhitespaces(pushbackReader); LINE_AFTER.set(pushbackReader.getLineNumber()); COLUMN_AFTER.set(pushbackReader.getColumnNumber()); ret = eval(r,false); LINE_BEFORE.set(pushbackReader.getLineNumber()); COLUMN_BEFORE.set(pushbackReader.getColumnNumber());
public Expr parse(C context, Object frm) { ISeq form = (ISeq) frm; if(RT.length(form) != 3) throw new IllegalArgumentException("Malformed assignment, expecting (set! target val)"); Expr target = analyze(C.EXPRESSION, RT.second(form)); if(!(target instanceof AssignableExpr)) throw new IllegalArgumentException("Invalid assignment target"); return new AssignExpr((AssignableExpr) target, analyze(C.EXPRESSION, RT.third(form))); } }
static class Parser implements IParser{ public Expr parse(C context, Object frm) { int line = (Integer) LINE.deref(); int column = (Integer) COLUMN.deref(); String source = (String) SOURCE.deref(); ISeq form = (ISeq) frm; IPersistentVector loopLocals = (IPersistentVector) LOOP_LOCALS.deref(); if(context != C.RETURN || loopLocals == null) throw new UnsupportedOperationException("Can only recur from tail position"); if(NO_RECUR.deref() != null) throw new UnsupportedOperationException("Cannot recur across try"); PersistentVector args = PersistentVector.EMPTY; for(ISeq s = RT.seq(form.next()); s != null; s = s.next()) { args = args.cons(analyze(C.EXPRESSION, s.first())); } if(args.count() != loopLocals.count()) throw new IllegalArgumentException( String.format("Mismatched argument count to recur, expected: %d args, got: %d", loopLocals.count(), args.count())); for(int i = 0;i< loopLocals.count();i++) { LocalBinding lb = (LocalBinding) loopLocals.nth(i); Class primc = lb.getPrimitiveType(); if(primc != null) { boolean mismatch = false; final Class pc = maybePrimitiveType((Expr) args.nth(i)); if(primc == long.class)
public Object invoke(Object arg1) { try { return Compiler.loadFile((String) arg1); } catch(IOException e) { throw Util.sneakyThrow(e); } } });
throw new IllegalArgumentException("Invalid arity - can't call: " + v + " with " + argcount + " args"); Class retClass = tagClass(tagOf(paramlist)); Class pc = tagClass(tagOf(paramlist.nth(i))); paramClasses.add(pc); paramTypes.add(Type.getType(pc)); Class pc = tagClass(tagOf(paramlist.nth(i))); paramClasses.add(pc); paramTypes.add(Type.getType(pc)); String cname = v.ns.name.name.replace('.', '/').replace('-','_') + "$" + munge(v.sym.name); Type target = Type.getObjectType(cname); argv = argv.cons(analyze(C.EXPRESSION, s.first()));
int line = lineDeref(); int column = columnDeref(); String source = (String) SOURCE.deref(); Class c = maybeClass(RT.second(form), false); instance = analyze(context == C.EVAL ? context : C.EXPRESSION, RT.second(form)); maybeField = Reflector.getMethods(c, 0, munge(sym.name), true).size() == 0; else if(instance != null && instance.hasJavaClass() && instance.getJavaClass() != null) maybeField = Reflector.getMethods(instance.getJavaClass(), 0, munge(sym.name), false).size() == 0; Symbol tag = tagOf(form); if(c != null) { return new StaticFieldExpr(line, column, c, munge(sym.name), tag); } else return new InstanceFieldExpr(line, column, instance, munge(sym.name), tag, (((Symbol)RT.third(form)).name.charAt(0) == '-')); PersistentVector args = PersistentVector.EMPTY; for(ISeq s = RT.next(call); s != null; s = s.next()) args = args.cons(analyze(context == C.EVAL ? context : C.EXPRESSION, s.first())); if(c != null) return new StaticMethodExpr(source, line, column, tag, c, munge(sym.name), args); else return new InstanceMethodExpr(source, line, column, tag, instance, munge(sym.name), args);
throw Util.runtimeException("First argument to def must be a Symbol"); Symbol sym = (Symbol) RT.second(form); Var v = lookupVar(sym, true); if(v == null) throw Util.runtimeException("Can't refer to qualified var that doesn't exist"); mm = (IPersistentMap) elideMeta(mm); Expr meta = mm.count()==0 ? null:analyze(context == C.EVAL ? context : C.EXPRESSION, mm); return new DefExpr((String) SOURCE.deref(), (Integer) LINE.deref(), (Integer) COLUMN.deref(), v, analyze(context == C.EVAL ? context : C.EXPRESSION, RT.third(form), v.sym.name), meta, RT.count(form) == 3, isDynamic);
public Expr parse(C context, Object frm) { int line = lineDeref(); int column = columnDeref(); String source = (String) SOURCE.deref(); for(ISeq s = RT.seq(form.next()); s != null; s = s.next()) args = args.cons(analyze(C.EXPRESSION, s.first())); final Class pc = maybePrimitiveType((Expr) args.nth(i)); if(primc == long.class)
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); try form = macroexpand(form); if(form instanceof ISeq && (Util.equals(RT.first(form), QDO) || Util.equals(RT.first(form), DO))) compile1(gen, objx, RT.first(s)); Expr expr = analyze(C.EVAL, form); objx.keywords = (IPersistentMap) KEYWORDS.deref(); objx.vars = (IPersistentMap) VARS.deref();
public Expr parse(C context, Object frm) { int line = lineDeref(); int column = columnDeref(); ISeq form = (ISeq) frm; //(new Classname args...) if(form.count() < 2) throw Util.runtimeException("wrong number of arguments, expecting: (new Classname args...)"); Class c = HostExpr.maybeClass(RT.second(form), false); if(c == null) throw new IllegalArgumentException("Unable to resolve classname: " + RT.second(form)); PersistentVector args = PersistentVector.EMPTY; for(ISeq s = RT.next(RT.next(form)); s != null; s = s.next()) args = args.cons(analyze(context == C.EVAL ? context : C.EXPRESSION, s.first())); return new NewExpr(c, args, line, column); } }
extypes, cv); addAnnotation(gen,methodMeta); for(int i = 0; i < parms.count(); i++) addParameterAnnotation(gen, meta, i);
for(ISeq s = RT.seq(form.next()); s != null; s = s.next()) args = args.cons(analyze(C.EXPRESSION, s.first())); final Class pc = maybePrimitiveType((Expr) args.nth(i)); if(primc == long.class)
cv.visitSource(source, smap); addAnnotation(cv, classMeta); addAnnotation(fv, RT.meta(lb.sym)); writeClassFile(internalName, bytecode);