Skip to content

Commit 32cbc8a

Browse files
committed
Scoped ids for fns
1 parent 28f36fc commit 32cbc8a

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/jvm/clojure/lang/Compiler.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ public class Compiler implements Opcodes {
256256

257257
// DynamicClassLoader
258258
static final public Var LOADER = Var.create().setDynamic();
259+
260+
static final public Var NEXT_ID = Var.create(new Atom(1)).setDynamic();
259261

260262
// String
261263
static final public Var SOURCE = Var.intern(
@@ -323,6 +325,13 @@ public static void emitSource(String source) {
323325
sc.println(source);
324326
}
325327
}
328+
329+
public static int nextScopedID() {
330+
Atom n = (Atom) NEXT_ID.deref();
331+
Integer i = (Integer) n.deref();
332+
n.reset(i+1);
333+
return i;
334+
}
326335

327336
public static void emitSource() {
328337
SourceWriter sc = (SourceWriter) SOURCE_WRITER.deref();
@@ -4336,9 +4345,9 @@ static Expr parse(C context, ISeq form, String name, Object defContext) {
43364345
if (RT.second(form) instanceof Symbol)
43374346
name = ((Symbol) RT.second(form)).name;
43384347
String simpleName = name != null ? (munge(name).replace(".", "_DOT_") + (enclosingMethod != null ? "__"
4339-
+ RT.nextID()
4348+
+ nextScopedID()
43404349
: ""))
4341-
: ("fn" + "__" + RT.nextID());
4350+
: ("fn" + "__" + nextScopedID());
43424351

43434352
/*Fix CLJ-1330
43444353
String basename = (enclosingMethod != null ?
@@ -4374,7 +4383,7 @@ PersistentVector.EMPTY, CONSTANT_IDS, new IdentityHashMap(),
43744383
KEYWORDS, PersistentHashMap.EMPTY, VARS, PersistentHashMap.EMPTY,
43754384
KEYWORD_CALLSITES, PersistentVector.EMPTY, PROTOCOL_CALLSITES,
43764385
PersistentVector.EMPTY, VAR_CALLSITES, emptyVarCallSites(),
4377-
NO_RECUR, null));
4386+
NO_RECUR, null, Compiler.NEXT_ID, new Atom(1)));
43784387

43794388
// arglist might be preceded by symbol naming this fn
43804389
if (RT.second(form) instanceof Symbol) {
@@ -8530,7 +8539,7 @@ PersistentVector.EMPTY, CONSTANT_IDS, new IdentityHashMap(),
85308539
KEYWORDS, PersistentHashMap.EMPTY, VARS, PersistentHashMap.EMPTY,
85318540
KEYWORD_CALLSITES, PersistentVector.EMPTY, PROTOCOL_CALLSITES,
85328541
PersistentVector.EMPTY, VAR_CALLSITES, emptyVarCallSites(),
8533-
NO_RECUR, null));
8542+
NO_RECUR, null, Compiler.NEXT_ID, new Atom(1)));
85348543
if (ret.isDeftype()) {
85358544
Var.pushThreadBindings(RT.mapUniqueKeys(METHOD, null, LOCAL_ENV,
85368545
ret.fields, COMPILE_STUB_SYM, Symbol.intern(null, tagName),

src/jvm/clojure/lang/RT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ static public void load(String scriptbase, boolean failIfNotFound) throws IOExce
10031003
|| classURL == null) {
10041004
try {
10051005
Var.pushThreadBindings(
1006-
RT.mapUniqueKeys(CURRENT_NS, CURRENT_NS.deref(),
1006+
RT.mapUniqueKeys(CURRENT_NS, CURRENT_NS.deref(), Compiler.NEXT_ID, new Atom(1),
10071007
WARN_ON_REFLECTION, WARN_ON_REFLECTION.deref()
10081008
,RT.UNCHECKED_MATH, RT.UNCHECKED_MATH.deref()));
10091009
loaded = (loadClassForName(scriptbase.replace('/', '.') + LOADER_SUFFIX) != null);

0 commit comments

Comments
 (0)