public static Expr Parse(ParserContext pcon, ISeq form)
{
pcon = pcon.EvalOrExpr();
Expr fexpr = Compiler.Analyze(pcon, form.first());
VarExpr varFexpr = fexpr as VarExpr;
if (varFexpr != null && varFexpr.Var.Equals(Compiler.InstanceVar))
{
if (RT.second(form) is Symbol)
{
Type t = HostExpr.MaybeType(RT.second(form), false);
if (t != null)
{
return(new InstanceOfExpr((string)Compiler.SourceVar.deref(), (IPersistentMap)Compiler.SourceSpanVar.deref(), t, Compiler.Analyze(pcon, RT.third(form))));
}
}
}
if (varFexpr != null && pcon.Rhc != RHC.Eval)
{
Var v = varFexpr.Var;
object arglists = RT.get(RT.meta(v), Compiler.ArglistsKeyword);
int arity = RT.count(form.next());
for (ISeq s = RT.seq(arglists); s != null; s = s.next())
{
IPersistentVector sargs = (IPersistentVector)s.first();
if (sargs.count() == arity)
{
string primc = FnMethod.PrimInterface(sargs);
if (primc != null)
{
return(Compiler.Analyze(pcon,
RT.listStar(Symbol.intern(".invokePrim"),
((Symbol)form.first()).withMeta(RT.map(RT.TagKey, Symbol.intern(primc))),
form.next())));
}
break;
}
}
}
KeywordExpr kwFexpr = fexpr as KeywordExpr;
if (kwFexpr != null && RT.count(form) == 2 && Compiler.KeywordCallsitesVar.isBound)
{
Expr target = Compiler.Analyze(pcon, RT.second(form));
return(new KeywordInvokeExpr((string)Compiler.SourceVar.deref(), (IPersistentMap)Compiler.SourceSpanVar.deref(), Compiler.TagOf(form), kwFexpr, target));
}
IPersistentVector args = PersistentVector.EMPTY;
for (ISeq s = RT.seq(form.next()); s != null; s = s.next())
{
args = args.cons(Compiler.Analyze(pcon, s.first()));
}
//if (args.count() > Compiler.MAX_POSITIONAL_ARITY)
// throw new ArgumentException(String.Format("No more than {0} args supported", Compiler.MAX_POSITIONAL_ARITY));
return(new InvokeExpr((string)Compiler.SourceVar.deref(),
(IPersistentMap)Compiler.SourceSpanVar.deref(), //Compiler.GetSourceSpanMap(form),
Compiler.TagOf(form),
fexpr,
args));
}