MCPcopy Index your code
hub / github.com/clojure/clojure / macroexpand1

Method macroexpand1

src/jvm/clojure/lang/Compiler.java:7566–7652  ·  view source on GitHub ↗
(Object x)

Source from the content-addressed store, hash-verified

7564}
7565
7566public static Object macroexpand1(Object x) {
7567 if(x instanceof ISeq)
7568 {
7569 ISeq form = (ISeq) x;
7570 Object op = RT.first(form);
7571 if(isSpecial(op))
7572 return x;
7573 //macro expansion
7574 Var v = isMacro(op);
7575 if(v != null)
7576 {
7577 checkSpecs(v, form);
7578
7579 try
7580 {
7581 ISeq args = RT.cons(form, RT.cons(Compiler.LOCAL_ENV.get(), form.next()));
7582 return v.applyTo(args);
7583 }
7584 catch(ArityException e)
7585 {
7586 // hide the 2 extra params for a macro
7587 if(e.name.equals(munge(v.ns.name.name) + "$" + munge(v.sym.name))) {
7588 throw new ArityException(e.actual - 2, e.name);
7589 } else {
7590 throw e;
7591 }
7592 }
7593 catch(CompilerException e)
7594 {
7595 throw e;
7596 }
7597 catch(IllegalArgumentException | IllegalStateException | ExceptionInfo e)
7598 {
7599 throw new CompilerException((String) SOURCE_PATH.deref(), lineDeref(), columnDeref(),
7600 (op instanceof Symbol ? (Symbol) op : null),
7601 CompilerException.PHASE_MACRO_SYNTAX_CHECK,
7602 e);
7603 }
7604 catch(Throwable e)
7605 {
7606 throw new CompilerException((String) SOURCE_PATH.deref(), lineDeref(), columnDeref(),
7607 (op instanceof Symbol ? (Symbol) op : null),
7608 (e.getClass().equals(Exception.class) ? CompilerException.PHASE_MACRO_SYNTAX_CHECK : CompilerException.PHASE_MACROEXPANSION),
7609 e);
7610 }
7611 } else
7612 {
7613 if(op instanceof Symbol)
7614 {
7615 Symbol sym = (Symbol) op;
7616 String sname = sym.name;
7617 //(.substring s 2 5) => (. s substring 2 5)
7618 // ns == null ensures that Class/.instanceMethod isn't expanded to . form
7619 if(sym.name.charAt(0) == '.' && sym.ns == null)
7620 {
7621 if(RT.length(form) < 2)
7622 throw new IllegalArgumentException(
7623 "Malformed member expression, expecting (.member target ...)");

Callers 2

macroexpandMethod · 0.95
analyzeSeqMethod · 0.95

Calls 15

firstMethod · 0.95
isSpecialMethod · 0.95
isMacroMethod · 0.95
checkSpecsMethod · 0.95
consMethod · 0.95
nextMethod · 0.95
applyToMethod · 0.95
mungeMethod · 0.95
lineDerefMethod · 0.95
columnDerefMethod · 0.95
lengthMethod · 0.95
internMethod · 0.95

Tested by

no test coverage detected