Skip to content

Instantly share code, notes, and snippets.

@exterm
Created May 4, 2010 10:57
Show Gist options
  • Select an option

  • Save exterm/389263 to your computer and use it in GitHub Desktop.

Select an option

Save exterm/389263 to your computer and use it in GitHub Desktop.
public static Object eval(Object form) throws Exception{
boolean createdLoader = false;
if(true)//!LOADER.isBound())
{
Var.pushThreadBindings(RT.map(LOADER, RT.makeClassLoader()));
createdLoader = true;
}
try
{
if(form instanceof IPersistentCollection
&& !(RT.first(form) instanceof Symbol
&& ((Symbol) RT.first(form)).name.startsWith("def")))
{
FnExpr fexpr = (FnExpr) analyze(C.EXPRESSION, RT.list(FN, PersistentVector.EMPTY, form), "eval");
IFn fn = (IFn) fexpr.eval();
return fn.invoke();
}
else
{
Expr expr = analyze(C.EVAL, form);
return expr.eval();
}
}
catch(Throwable e)
{
if(!(e instanceof CompilerException))
throw new CompilerException((String) SOURCE.deref(), (Integer) LINE.deref(), e);
else
throw (CompilerException) e;
}
finally
{
if(createdLoader)
Var.popThreadBindings();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment