public static Object macroexpand1(Object x) {
if (x instanceof ISeq) {
ISeq form = (ISeq)x;
Object op = RT.first(form);
if (isSpecial(op)) {
return x;
}
Var v = isMacro(op);
if (v != null) {
ISeq args = RT.cons(form, RT.cons(LOCAL_ENV.get(), form.next()));
return v.applyTo(args);
}
// 这里如果是 java.util.Date/pares 等形式. 则变(展开)成 new 或 dot(.) special form
if (op instanceof Symbol) {
Symbol sym = (Symbol)op;
String sname = sym.name;
Symbol target;
if (sym.name.charAt(0) == '.') {
if (RT.length(form) < 2) {
throw new IllegalArgumentException("Malformed member expression, expecting (.member target ...)");
}
target = Symbol.intern(sname.substring(1));
Object target = RT.second(form);
if (Compiler.HostExpr.maybeClass(target, false) != null) {
target = ((IObj)RT.list(IDENTITY, target)).withMeta(RT.map(new Object[]{RT.TAG_KEY, CLASS}));
}
return preserveTag(form, RT.listStar(DOT, target, target, form.next().next()));
}
if (namesStaticMember(sym)) {
target = Symbol.intern(sym.ns);
Class c = Compiler.HostExpr.maybeClass(target, false);
if (c != null) {
Symbol meth = Symbol.intern(sym.name);
return preserveTag(form, RT.listStar(DOT, target, meth, form.next()));
}
} else {
int idx = sname.lastIndexOf(46);
if (idx == sname.length() - 1) {
return RT.listStar(NEW, Symbol.intern(sname.substring(0, idx)), form.next());
}
}
}
}
return x;
}
网友评论