Skip to content

Instantly share code, notes, and snippets.

@sunng87
Created October 27, 2012 02:39
Show Gist options
  • Save sunng87/3962750 to your computer and use it in GitHub Desktop.
Save sunng87/3962750 to your computer and use it in GitHub Desktop.
hacking clojure compiler, adding -var-missing
diff --git a/src/jvm/clojure/lang/Compiler.java b/src/jvm/clojure/lang/Compiler.java
index e2146a6..2dfa208 100644
--- a/src/jvm/clojure/lang/Compiler.java
+++ b/src/jvm/clojure/lang/Compiler.java
@@ -6728,6 +6728,16 @@ static Namespace namespaceFor(Namespace inns, Symbol sym){
return ns;
}
+static public Var varMissing(Symbol sym) {
+ if (sym.ns != null) {
+ Namespace ns = namespaceFor(sym);
+ Var missing = ns.findInternedVar(Symbol.intern("-var-missing"));
+ if (missing != null && missing.isBound())
+ return (Var)((IFn)(missing.get())).invoke(sym.name);
+ }
+ return null;
+}
+
static public Object resolveIn(Namespace n, Symbol sym, boolean allowPrivate) {
//note - ns-qualified vars must already exist
if(sym.ns != null)
@@ -6737,9 +6747,12 @@ static public Object resolveIn(Namespace n, Symbol sym, boolean allowPrivate) {
throw Util.runtimeException("No such namespace: " + sym.ns);
Var v = ns.findInternedVar(Symbol.intern(sym.name));
- if(v == null)
- throw Util.runtimeException("No such var: " + sym);
- else if(v.ns != currentNS() && !v.isPublic() && !allowPrivate)
+ if(v == null) {
+ v = varMissing(sym);
+ if (v == null) {
+ throw Util.runtimeException("No such var: " + sym);
+ }
+ } else if(v.ns != currentNS() && !v.isPublic() && !allowPrivate)
throw new IllegalStateException("var: " + sym + " is not public");
return v;
}
@@ -6816,6 +6829,9 @@ static Var lookupVar(Symbol sym, boolean internNew, boolean registerMacro) {
var = currentNS().intern(name);
else
var = ns.findInternedVar(name);
+ if (var == null) {
+ var = varMissing(sym);
+ }
}
else if(sym.equals(NS))
var = RT.NS_VAR;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment