diff options
author | Chouser <chouser@n01se.net> | 2008-09-15 01:48:08 +0000 |
---|---|---|
committer | Chouser <chouser@n01se.net> | 2008-09-15 01:48:08 +0000 |
commit | f2483b3b722c6b59bc9ef192f3a7c649f030f768 (patch) | |
tree | ca81817185ae1ccbb085a237ee3b3fb28e80e6c1 /clojurescript/clojurescript-compiler.patch | |
parent | 8ea24c5aeed899f719319187686bf9433740febd (diff) |
ClojureScript: minimal example functioning now
Diffstat (limited to 'clojurescript/clojurescript-compiler.patch')
-rw-r--r-- | clojurescript/clojurescript-compiler.patch | 128 |
1 files changed, 93 insertions, 35 deletions
diff --git a/clojurescript/clojurescript-compiler.patch b/clojurescript/clojurescript-compiler.patch index ad80848f..54210848 100644 --- a/clojurescript/clojurescript-compiler.patch +++ b/clojurescript/clojurescript-compiler.patch @@ -1,5 +1,5 @@ diff --git a/src/jvm/clojure/lang/Compiler.java b/src/jvm/clojure/lang/Compiler.java -index afb25de..832abd8 100644 +index e087d08..659d346 100644 --- a/src/jvm/clojure/lang/Compiler.java +++ b/src/jvm/clojure/lang/Compiler.java @@ -195,7 +195,7 @@ static final public Var RET_LOCAL_NUM = Var.create(); @@ -37,7 +37,7 @@ index afb25de..832abd8 100644 final static Method bindRootMethod = Method.getMethod("void bindRoot(Object)"); final static Method setTagMethod = Method.getMethod("void setTag(clojure.lang.Symbol)"); final static Method setMetaMethod = Method.getMethod("void setMeta(clojure.lang.IPersistentMap)"); -@@ -341,10 +341,9 @@ static class DefExpr implements Expr{ +@@ -346,10 +346,9 @@ static class DefExpr implements Expr{ } } @@ -51,7 +51,7 @@ index afb25de..832abd8 100644 public AssignExpr(AssignableExpr target, Expr val){ this.target = target; -@@ -380,9 +379,9 @@ static class AssignExpr implements Expr{ +@@ -385,9 +384,9 @@ static class AssignExpr implements Expr{ } } @@ -64,7 +64,7 @@ index afb25de..832abd8 100644 final static Method getMethod = Method.getMethod("Object get()"); final static Method setMethod = Method.getMethod("Object set(Object)"); -@@ -426,8 +425,8 @@ static class VarExpr implements Expr, AssignableExpr{ +@@ -431,8 +430,8 @@ static class VarExpr implements Expr, AssignableExpr{ } } @@ -75,7 +75,7 @@ index afb25de..832abd8 100644 public TheVarExpr(Var var){ this.var = var; -@@ -462,8 +461,8 @@ static class TheVarExpr implements Expr{ +@@ -467,8 +466,8 @@ static class TheVarExpr implements Expr{ } } @@ -86,7 +86,7 @@ index afb25de..832abd8 100644 public KeywordExpr(Keyword k){ this.k = k; -@@ -489,7 +488,7 @@ static class KeywordExpr implements Expr{ +@@ -494,7 +493,7 @@ static class KeywordExpr implements Expr{ } } @@ -95,7 +95,7 @@ index afb25de..832abd8 100644 abstract Object val(); public Object eval(){ -@@ -809,11 +808,11 @@ static abstract class FieldExpr extends HostExpr{ +@@ -814,11 +813,11 @@ static abstract class FieldExpr extends HostExpr{ } static class InstanceFieldExpr extends FieldExpr implements AssignableExpr{ @@ -112,7 +112,7 @@ index afb25de..832abd8 100644 final static Method invokeNoArgInstanceMember = Method.getMethod("Object invokeNoArgInstanceMember(Object,String)"); final static Method setInstanceFieldMethod = Method.getMethod("Object setInstanceField(Object,String,Object)"); -@@ -909,9 +908,9 @@ static class InstanceFieldExpr extends FieldExpr implements AssignableExpr{ +@@ -914,9 +913,9 @@ static class InstanceFieldExpr extends FieldExpr implements AssignableExpr{ static class StaticFieldExpr extends FieldExpr implements AssignableExpr{ //final String className; @@ -125,7 +125,7 @@ index afb25de..832abd8 100644 final static Method getStaticFieldMethod = Method.getMethod("Object getStaticField(String,String)"); final static Method setStaticFieldMethod = Method.getMethod("Object setStaticField(String,String,Object)"); final int line; -@@ -1033,11 +1032,11 @@ static abstract class MethodExpr extends HostExpr{ +@@ -1038,11 +1037,11 @@ static abstract class MethodExpr extends HostExpr{ } static class InstanceMethodExpr extends MethodExpr{ @@ -142,7 +142,7 @@ index afb25de..832abd8 100644 final static Method invokeInstanceMethodMethod = Method.getMethod("Object invokeInstanceMethod(Object,String,Object[])"); -@@ -1171,11 +1170,11 @@ static class InstanceMethodExpr extends MethodExpr{ +@@ -1176,11 +1175,11 @@ static class InstanceMethodExpr extends MethodExpr{ static class StaticMethodExpr extends MethodExpr{ //final String className; @@ -159,7 +159,35 @@ index afb25de..832abd8 100644 final static Method invokeStaticMethodMethod = Method.getMethod("Object invokeStaticMethod(String,String,Object[])"); -@@ -1284,8 +1283,8 @@ static class StaticMethodExpr extends MethodExpr{ +@@ -1285,12 +1284,36 @@ static class StaticMethodExpr extends MethodExpr{ + } + } + ++static class UnresolvedVarExpr implements Expr{ ++ public final Symbol symbol; ++ ++ public UnresolvedVarExpr(Symbol symbol) { ++ this.symbol = symbol; ++ } ++ ++ public boolean hasJavaClass(){ ++ return false; ++ } ++ ++ public Class getJavaClass() throws Exception{ ++ throw new IllegalArgumentException( ++ "UnresolvedVarExpr has no Java class"); ++ } ++ ++ public void emit(C context, FnExpr fn, GeneratorAdapter gen){ ++ } ++ ++ public Object eval() throws Exception{ ++ throw new IllegalArgumentException( ++ "UnresolvedVarExpr cannot be evalled"); ++ } ++} + static class ConstantExpr extends LiteralExpr{ //stuff quoted vals in classloader at compile time, pull out at runtime //this won't work for static compilation... @@ -170,7 +198,7 @@ index afb25de..832abd8 100644 public ConstantExpr(Object v){ this.v = v; -@@ -1369,7 +1368,7 @@ static class NilExpr extends LiteralExpr{ +@@ -1374,7 +1397,7 @@ static class NilExpr extends LiteralExpr{ final static NilExpr NIL_EXPR = new NilExpr(); static class BooleanExpr extends LiteralExpr{ @@ -179,7 +207,7 @@ index afb25de..832abd8 100644 public BooleanExpr(boolean val){ -@@ -1404,7 +1403,7 @@ final static BooleanExpr TRUE_EXPR = new BooleanExpr(true); +@@ -1409,7 +1432,7 @@ final static BooleanExpr TRUE_EXPR = new BooleanExpr(true); final static BooleanExpr FALSE_EXPR = new BooleanExpr(false); static class StringExpr extends LiteralExpr{ @@ -188,7 +216,7 @@ index afb25de..832abd8 100644 public StringExpr(String str){ this.str = str; -@@ -1576,17 +1575,17 @@ static class MonitorExitExpr extends UntypedExpr{ +@@ -1581,17 +1604,17 @@ static class MonitorExitExpr extends UntypedExpr{ } static class TryExpr implements Expr{ @@ -214,7 +242,7 @@ index afb25de..832abd8 100644 Label label; Label endLabel; -@@ -1828,7 +1827,7 @@ static class TryExpr implements Expr{ +@@ -1833,7 +1856,7 @@ static class TryExpr implements Expr{ //} static class ThrowExpr extends UntypedExpr{ @@ -223,7 +251,7 @@ index afb25de..832abd8 100644 public ThrowExpr(Expr excExpr){ this.excExpr = excExpr; -@@ -1955,10 +1954,10 @@ static int getMatchingParams(String methodName, ArrayList<Class[]> paramlists, I +@@ -1960,10 +1983,10 @@ static int getMatchingParams(String methodName, ArrayList<Class[]> paramlists, I return matchIdx; } @@ -238,7 +266,7 @@ index afb25de..832abd8 100644 final static Method invokeConstructorMethod = Method.getMethod("Object invokeConstructor(Class,Object[])"); final static Method forNameMethod = Method.getMethod("Class classForName(String)"); -@@ -2170,9 +2169,9 @@ static class NewExpr implements Expr{ +@@ -2175,9 +2198,9 @@ static class NewExpr implements Expr{ // } //} @@ -251,7 +279,7 @@ index afb25de..832abd8 100644 final static Type IOBJ_TYPE = Type.getType(IObj.class); final static Method withMetaMethod = Method.getMethod("clojure.lang.IObj withMeta(clojure.lang.IPersistentMap)"); -@@ -2207,11 +2206,11 @@ static class MetaExpr implements Expr{ +@@ -2212,11 +2235,11 @@ static class MetaExpr implements Expr{ } } @@ -268,7 +296,7 @@ index afb25de..832abd8 100644 public IfExpr(int line, Expr testExpr, Expr thenExpr, Expr elseExpr){ -@@ -2336,8 +2335,8 @@ static public String munge(String name){ +@@ -2341,8 +2364,8 @@ static public String munge(String name){ return sb.toString(); } @@ -279,7 +307,7 @@ index afb25de..832abd8 100644 final static Type HASHMAP_TYPE = Type.getType(PersistentHashMap.class); final static Type HASHSET_TYPE = Type.getType(PersistentHashSet.class); final static Type VECTOR_TYPE = Type.getType(PersistentVector.class); -@@ -2388,8 +2387,8 @@ static class EmptyExpr implements Expr{ +@@ -2393,8 +2416,8 @@ static class EmptyExpr implements Expr{ } } @@ -290,7 +318,7 @@ index afb25de..832abd8 100644 final static Method arrayToListMethod = Method.getMethod("clojure.lang.ISeq arrayToList(Object[])"); -@@ -2421,8 +2420,8 @@ static class ListExpr implements Expr{ +@@ -2426,8 +2449,8 @@ static class ListExpr implements Expr{ } @@ -301,7 +329,7 @@ index afb25de..832abd8 100644 final static Method mapMethod = Method.getMethod("clojure.lang.IPersistentMap map(Object[])"); -@@ -2470,8 +2469,8 @@ static class MapExpr implements Expr{ +@@ -2475,8 +2498,8 @@ static class MapExpr implements Expr{ } } @@ -312,7 +340,7 @@ index afb25de..832abd8 100644 final static Method setMethod = Method.getMethod("clojure.lang.IPersistentSet set(Object[])"); -@@ -2518,8 +2517,8 @@ static class SetExpr implements Expr{ +@@ -2523,8 +2546,8 @@ static class SetExpr implements Expr{ } } @@ -323,7 +351,7 @@ index afb25de..832abd8 100644 final static Method vectorMethod = Method.getMethod("clojure.lang.IPersistentVector vector(Object[])"); -@@ -2563,11 +2562,11 @@ static class VectorExpr implements Expr{ +@@ -2568,11 +2591,11 @@ static class VectorExpr implements Expr{ } @@ -340,7 +368,7 @@ index afb25de..832abd8 100644 public InvokeExpr(int line, Symbol tag, Expr fexpr, IPersistentVector args){ this.fexpr = fexpr; -@@ -2661,7 +2660,7 @@ static public class FnExpr implements Expr{ +@@ -2693,7 +2716,7 @@ static public class FnExpr implements Expr{ String internalName; String thisName; Type fntype; @@ -349,7 +377,7 @@ index afb25de..832abd8 100644 //localbinding->itself IPersistentMap closes = PersistentHashMap.EMPTY; //Keyword->KeywordExpr -@@ -2671,6 +2670,20 @@ static public class FnExpr implements Expr{ +@@ -2703,6 +2726,20 @@ static public class FnExpr implements Expr{ int line; PersistentVector constants; int constantsID; @@ -370,7 +398,7 @@ index afb25de..832abd8 100644 final static Method kwintern = Method.getMethod("clojure.lang.Keyword intern(String, String)"); final static Method symcreate = Method.getMethod("clojure.lang.Symbol create(String)"); -@@ -3098,10 +3111,10 @@ enum PSTATE{ +@@ -3139,10 +3176,10 @@ enum PSTATE{ } @@ -383,7 +411,7 @@ index afb25de..832abd8 100644 //localbinding->localbinding IPersistentMap locals = null; //localbinding->localbinding -@@ -3113,6 +3126,14 @@ static class FnMethod{ +@@ -3154,6 +3191,14 @@ static class FnMethod{ int maxLocal = 0; int line; PersistentHashSet localsUsedInCatchFinally = PersistentHashSet.EMPTY; @@ -398,7 +426,7 @@ index afb25de..832abd8 100644 public FnMethod(FnExpr fn, FnMethod parent){ this.parent = parent; -@@ -3252,12 +3273,12 @@ static class FnMethod{ +@@ -3293,12 +3338,12 @@ static class FnMethod{ } } @@ -417,7 +445,7 @@ index afb25de..832abd8 100644 public LocalBinding(int num, Symbol sym, Symbol tag, Expr init) throws Exception{ if(maybePrimitiveType(init) != null && tag != null) -@@ -3288,9 +3309,9 @@ static class LocalBinding{ +@@ -3329,9 +3374,9 @@ static class LocalBinding{ } } @@ -430,7 +458,7 @@ index afb25de..832abd8 100644 public LocalBindingExpr(LocalBinding b, Symbol tag) throws Exception{ if(b.getPrimitiveType() != null && tag != null) -@@ -3325,8 +3346,9 @@ static class LocalBindingExpr implements Expr, MaybePrimitiveExpr{ +@@ -3366,8 +3411,9 @@ static class LocalBindingExpr implements Expr, MaybePrimitiveExpr{ } @@ -441,7 +469,7 @@ index afb25de..832abd8 100644 public BodyExpr(PersistentVector exprs){ this.exprs = exprs; -@@ -3386,9 +3408,11 @@ static class BodyExpr implements Expr{ +@@ -3427,9 +3473,11 @@ static class BodyExpr implements Expr{ } } @@ -454,7 +482,7 @@ index afb25de..832abd8 100644 public BindingInit(LocalBinding binding, Expr init){ this.binding = binding; -@@ -3396,10 +3420,10 @@ static class BindingInit{ +@@ -3437,10 +3485,10 @@ static class BindingInit{ } } @@ -469,7 +497,7 @@ index afb25de..832abd8 100644 public LetExpr(PersistentVector bindingInits, Expr body, boolean isLoop){ this.bindingInits = bindingInits; -@@ -3522,9 +3546,9 @@ static class LetExpr implements Expr{ +@@ -3563,9 +3611,9 @@ static class LetExpr implements Expr{ } } @@ -482,7 +510,7 @@ index afb25de..832abd8 100644 public RecurExpr(IPersistentVector loopLocals, IPersistentVector args){ this.loopLocals = loopLocals; -@@ -3626,7 +3650,7 @@ private static int getAndIncLocalNum(){ +@@ -3667,7 +3715,7 @@ private static int getAndIncLocalNum(){ return num; } @@ -491,3 +519,33 @@ index afb25de..832abd8 100644 return analyze(context, form, null); } +@@ -3963,6 +4011,8 @@ private static Expr analyzeSymbol(Symbol sym) throws Exception{ + } + else if(o instanceof Class) + return new ConstantExpr(o); ++ else if(o instanceof Symbol) ++ return new UnresolvedVarExpr((Symbol) o); + + throw new Exception("Unable to resolve symbol: " + sym + " in this context"); + +@@ -4008,6 +4058,8 @@ static public Object resolveIn(Namespace n, Symbol sym) throws Exception{ + return RT.NS_VAR; + else if(sym.equals(IN_NS)) + return RT.IN_NS_VAR; ++ else if(RT.booleanCast(RT.ALLOW_UNRESOLVED_VARS.get())) ++ return sym; + else + { + Object o = n.getMapping(sym); +diff --git a/src/jvm/clojure/lang/RT.java b/src/jvm/clojure/lang/RT.java +index 2ce55e4..06379eb 100644 +--- a/src/jvm/clojure/lang/RT.java ++++ b/src/jvm/clojure/lang/RT.java +@@ -198,6 +198,7 @@ final static Var FLUSH_ON_NEWLINE = Var.intern(CLOJURE_NS, Symbol.create("*flush + final static Var PRINT_META = Var.intern(CLOJURE_NS, Symbol.create("*print-meta*"), F); + final static Var PRINT_READABLY = Var.intern(CLOJURE_NS, Symbol.create("*print-readably*"), T); + final static Var WARN_ON_REFLECTION = Var.intern(CLOJURE_NS, Symbol.create("*warn-on-reflection*"), F); ++final static Var ALLOW_UNRESOLVED_VARS = Var.intern(CLOJURE_NS, Symbol.create("*allow-unresolved-vars*"), F); + + final static Var IN_NS_VAR = Var.intern(CLOJURE_NS, Symbol.create("in-ns"), F); + final static Var NS_VAR = Var.intern(CLOJURE_NS, Symbol.create("ns"), F); |