Skip to content

Commit d19acfb

Browse files
committed
Fix macroexpansion to make it behave like the official compiler
See flow-storm/flow-storm-debugger#210
1 parent c241328 commit d19acfb

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<artifactId>clojure</artifactId>
66
<name>clojure</name>
77
<packaging>jar</packaging>
8-
<version>1.12.3-1</version>
8+
<version>1.12.3-4</version>
99
<url>http://clojure.org/</url>
1010
<description>Clojure core environment and runtime library.</description>
1111

src/jvm/clojure/lang/Compiler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7812,7 +7812,7 @@ public static void checkSpecs(Var v, ISeq form) {
78127812
}
78137813

78147814
public static Object macroexpand1(Object x) {
7815-
IPersistentMap xMeta = RT.meta(x);
7815+
IPersistentMap stormMeta = Utils.stormMeta(RT.meta(x));
78167816

78177817
if(x instanceof ISeq)
78187818
{
@@ -7829,7 +7829,7 @@ public static Object macroexpand1(Object x) {
78297829
try
78307830
{
78317831
ISeq args = RT.cons(form, RT.cons(Compiler.LOCAL_ENV.get(), form.next()));
7832-
return Utils.mergeMeta(v.applyTo(args), xMeta);
7832+
return Utils.mergeMeta(v.applyTo(args), stormMeta);
78337833
}
78347834
catch(ArityException e)
78357835
{
@@ -7877,7 +7877,7 @@ public static Object macroexpand1(Object x) {
78777877
{
78787878
target = ((IObj)RT.list(IDENTITY, target)).withMeta(RT.map(RT.TAG_KEY,CLASS));
78797879
}
7880-
return Utils.mergeMeta(preserveTagAndCoord(form, RT.listStar(DOT, target, meth, form.next().next())), xMeta);
7880+
return Utils.mergeMeta(preserveTagAndCoord(form, RT.listStar(DOT, target, meth, form.next().next())), stormMeta);
78817881
}
78827882
else
78837883
{
@@ -7893,7 +7893,7 @@ public static Object macroexpand1(Object x) {
78937893
//(StringBuilder. "foo") => (new StringBuilder "foo")
78947894
//else
78957895
if(idx == sname.length() - 1)
7896-
return Utils.mergeMeta(RT.listStar(NEW, Symbol.intern(sname.substring(0, idx)), form.next()), xMeta);
7896+
return Utils.mergeMeta(RT.listStar(NEW, Symbol.intern(sname.substring(0, idx)), form.next()), stormMeta);
78977897
}
78987898
}
78997899
}

src/jvm/clojure/storm/Utils.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636

3737
public class Utils {
3838

39-
private static final Keyword TAG_KEY = Keyword.intern(null, "tag");
40-
4139
public static Object mergeMeta(Object x, IPersistentMap m) {
4240
if (x instanceof clojure.lang.IObj && RT.count(m) > 0) {
4341
// if x supports meta and there is meta to merge
@@ -56,9 +54,7 @@ public static Object mergeMeta(Object x, IPersistentMap m) {
5654
// m meta overrides the input Object meta when both have
5755
for (Object meo : m) {
5856
IMapEntry me = (IMapEntry) meo;
59-
if (!TAG_KEY.equals(me.key())) {
60-
retMeta = retMeta.assoc(me.key(), me.val());
61-
}
57+
retMeta = retMeta.assoc(me.key(), me.val());
6258
}
6359

6460
return o.withMeta(retMeta);
@@ -67,6 +63,26 @@ public static Object mergeMeta(Object x, IPersistentMap m) {
6763
}
6864
}
6965

66+
public static IPersistentMap stormMeta(IPersistentMap m) {
67+
if (m != null && RT.count(m) > 0) {
68+
IPersistentMap retMeta = PersistentHashMap.EMPTY;
69+
70+
for (Object meObj : m) {
71+
IMapEntry me = (IMapEntry) meObj;
72+
if (me.key().equals(LispReader.COORD_KEY) ||
73+
me.key().equals(Compiler.STORM_COORDS_EMITTED_COORDS_KEY) ||
74+
me.key().equals(Compiler.SKIP_TRACE_KEY) ||
75+
me.key().equals(Compiler.FN_TRACE_SYM_KEY)) {
76+
retMeta = retMeta.assoc(me.key(), me.val());
77+
}
78+
}
79+
return retMeta;
80+
} else {
81+
return m;
82+
}
83+
}
84+
85+
7086
public static Symbol maybeGetTraceSymbol(Symbol sym, ISeq form){
7187
// If the form is the expansion of a defmethod we use the symbol of
7288
// the defmethod as a trace symbol.

0 commit comments

Comments
 (0)