summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2007-07-06 13:15:47 +0000
committerRich Hickey <richhickey@gmail.com>2007-07-06 13:15:47 +0000
commit6458d1bc2e1d9ea332c21f0a46e889a59e0b3fff (patch)
tree93981fce86443f65365f079e9a626d5056dfdc61 /src
parent7ee1a813d0c90a1bde3e8c341d3fc18ba0ad462e (diff)
persistent array cleanup
Diffstat (limited to 'src')
-rw-r--r--src/jvm/clojure/lang/Compiler.java82
1 files changed, 41 insertions, 41 deletions
diff --git a/src/jvm/clojure/lang/Compiler.java b/src/jvm/clojure/lang/Compiler.java
index 69ba89ef..432a60a8 100644
--- a/src/jvm/clojure/lang/Compiler.java
+++ b/src/jvm/clojure/lang/Compiler.java
@@ -104,14 +104,14 @@ static String compile(String ns, String className, LineNumberingPushbackReader..
VARS.pushThreadBinding(null);
METHOD.pushThreadBinding(null);
LOCAL_ENV.pushThreadBinding(null);
- FNS.pushThreadBinding(new PersistentArrayList(4));
+ FNS.pushThreadBinding(PersistentVector.EMPTY);
format("/* Generated by Clojure */~%~%");
format("package ~A;~%", ns);
format("import clojure.lang.*;~%~%");
format("public class ~A{~%", className);
- PersistentArrayList forms = new PersistentArrayList(20);
+ PersistentVector forms = PersistentVector.EMPTY;
for(LineNumberingPushbackReader reader : files)
{
try
@@ -174,7 +174,7 @@ static String compile(String ns, String className, LineNumberingPushbackReader..
//todo declare static members for syms, quoted aggregates
//emit nested static class/method declarations for nested fns
- PersistentArrayList fns = (PersistentArrayList) FNS.currentVal();
+ PersistentVector fns = (PersistentVector) FNS.currentVal();
for(int f = 0; f < fns.count(); f++)
{
FnExpr fn = (FnExpr) fns.nth(f);
@@ -398,7 +398,7 @@ private static Expr analyzeSeq(C context, ISeq form) throws Exception{
return analyzeNot(context, form);
else
{
- PersistentArrayList args = new PersistentArrayList(4);
+ PersistentVector args = PersistentVector.EMPTY;
for(ISeq s = op instanceof InstanceMemberInvoker ? RT.rrest(form) : RT.rest(form); s != null; s = s.rest())
args = args.cons(analyze(C.EXPRESSION, macroexpand(s.first())));
@@ -420,7 +420,7 @@ private static Expr analyzeSeq(C context, ISeq form) throws Exception{
}
}
-private static Expr analyzeInstanceInvoke(InstanceMemberInvoker sym, Expr target, PersistentArrayList args)
+private static Expr analyzeInstanceInvoke(InstanceMemberInvoker sym, Expr target, PersistentVector args)
throws Exception{
Class targetClass = null;
if(sym.className != null)
@@ -434,9 +434,9 @@ private static Expr analyzeInstanceInvoke(InstanceMemberInvoker sym, Expr target
static class InvokeExpr extends AnExpr{
Expr fexpr;
- PersistentArrayList args;
+ PersistentVector args;
- public InvokeExpr(Expr fexpr, PersistentArrayList args){
+ public InvokeExpr(Expr fexpr, PersistentVector args){
this.fexpr = fexpr;
this.args = args;
}
@@ -466,9 +466,9 @@ static class InvokeExpr extends AnExpr{
/*
static class InvokeConstructorExpr extends AHostExpr{
HostClassExpr fexpr;
- PersistentArrayList args;
+ PersistentVector args;
- public InvokeConstructorExpr(ClassSymbol fexpr, PersistentArrayList args) throws Exception{
+ public InvokeConstructorExpr(ClassSymbol fexpr, PersistentVector args) throws Exception{
this.fexpr = new HostClassExpr(fexpr);
this.args = args;
}
@@ -494,11 +494,11 @@ static class InvokeStaticMethodExpr extends AHostExpr{
final StaticMemberInvoker sym;
final String resolvedClassName;
final Class type;
- PersistentArrayList args;
+ PersistentVector args;
final Method method;
final Class returnType;
- public InvokeStaticMethodExpr(StaticMemberInvoker sym, PersistentArrayList args) throws Exception{
+ public InvokeStaticMethodExpr(StaticMemberInvoker sym, PersistentVector args) throws Exception{
this.sym = sym;
this.args = args;
this.resolvedClassName = resolveHostClassname(sym.className);
@@ -538,9 +538,9 @@ static class InvokeStaticMethodExpr extends AHostExpr{
static class InvokeUntypedInstanceMemberExpr extends AnExpr{
final String name;
final Expr target;
- PersistentArrayList args;
+ PersistentVector args;
- public InvokeUntypedInstanceMemberExpr(String name, Expr target, PersistentArrayList args) throws Exception{
+ public InvokeUntypedInstanceMemberExpr(String name, Expr target, PersistentVector args) throws Exception{
this.name = name;
this.args = args;
this.target = target;
@@ -555,13 +555,13 @@ static class InvokeUntypedInstanceMemberExpr extends AnExpr{
static class InvokeInstanceMemberExpr extends AHostExpr{
final String name;
final Expr target;
- PersistentArrayList args;
+ PersistentVector args;
final Class targetType;
final Field field;
final Method method;
final Class returnType;
- public InvokeInstanceMemberExpr(Class targetClass, String name, Expr target, PersistentArrayList args)
+ public InvokeInstanceMemberExpr(Class targetClass, String name, Expr target, PersistentVector args)
throws Exception{
this.name = name;
this.args = args;
@@ -620,7 +620,7 @@ static class InvokeInstanceMemberExpr extends AHostExpr{
}
-static void emitHostArgs(PersistentArrayList args) throws Exception{
+static void emitHostArgs(PersistentVector args) throws Exception{
for(int i = 0; i < args.count(); i++)
{
Expr arg = (Expr) args.nth(i);
@@ -636,7 +636,7 @@ static void emitHostArgs(PersistentArrayList args) throws Exception{
}
-static void emitTypedArgs(Class[] parameterTypes, PersistentArrayList args, boolean isVariadic) throws Exception{
+static void emitTypedArgs(Class[] parameterTypes, PersistentVector args, boolean isVariadic) throws Exception{
for(int i = 0; i < (isVariadic ? parameterTypes.length - 1 : args.count()); i++)
{
Expr arg = (Expr) args.nth(i);
@@ -700,7 +700,7 @@ static void emitCast(Class parameterType, Expr arg) throws Exception {
/*returns null unless single ctor with matching arity, throws if no ctor can handle arity*/
-public static Constructor findSingleConstructor(Class c, PersistentArrayList args) throws Exception{
+public static Constructor findSingleConstructor(Class c, PersistentVector args) throws Exception{
Constructor[] allctors = c.getConstructors();
Constructor found = null;
for(int i = 0; i < allctors.length; i++)
@@ -726,7 +726,7 @@ public static Constructor findSingleConstructor(Class c, PersistentArrayList arg
else returns null
throws if no method can handle arity*/
-public static Object findSingleMethod(Class c, String methodName, PersistentArrayList args, boolean isStatic)
+public static Object findSingleMethod(Class c, String methodName, PersistentVector args, boolean isStatic)
throws Exception{
Method[] allmethods = c.getMethods();
Method found = null;
@@ -774,8 +774,8 @@ private static Expr analyzeLet(C context, ISeq form) throws Exception{
if(context == C.EXPRESSION)
{
//(let (a b) c) -> ((fn (a) c) b)
- PersistentArrayList parms = new PersistentArrayList(4);
- PersistentArrayList args = new PersistentArrayList(4);
+ PersistentVector parms = PersistentVector.EMPTY;
+ PersistentVector args = PersistentVector.EMPTY;
for(ISeq bs = bindings; bs != null; bs = RT.rest(RT.rest(bs)))
{
parms = parms.cons(RT.first(bs));
@@ -784,7 +784,7 @@ private static Expr analyzeLet(C context, ISeq form) throws Exception{
return analyze(context, RT.cons(RT.listStar(FN, RT.seq(parms), body), RT.seq(args)));
}
- PersistentArrayList bindingInits = new PersistentArrayList(4);
+ PersistentVector bindingInits = PersistentVector.EMPTY;
//analyze inits before adding bindings to env
for(ISeq bs = bindings; bs != null; bs = RT.rest(RT.rest(bs)))
{
@@ -823,7 +823,7 @@ private static Expr analyzeLetFn(C context, ISeq form) throws Exception{
LOCAL_ENV.pushThreadBinding(LOCAL_ENV.currentVal());
ISeq bindings = (ISeq) RT.second(form);
ISeq body = RT.rest(RT.rest(form));
- PersistentArrayList bindingPairs = new PersistentArrayList(4);
+ PersistentVector bindingPairs = PersistentVector.EMPTY;
//add all fn names to env before analyzing bodies
for(ISeq bs = bindings; bs != null; bs = RT.rest(bs))
{
@@ -835,7 +835,7 @@ private static Expr analyzeLetFn(C context, ISeq form) throws Exception{
bindingPairs = bindingPairs.cons(PersistentVector.create(lb, RT.cons(FN, RT.rest(bform))));
}
- PersistentArrayList bindingInits = new PersistentArrayList(4);
+ PersistentVector bindingInits = PersistentVector.EMPTY;
for(int i = 0; i < bindingPairs.count(); i++)
{
IPersistentArray bpair = (IPersistentArray) bindingPairs.nth(i);
@@ -868,7 +868,7 @@ private static Expr analyzeLetStar(C context, ISeq form) throws Exception{
try
{
LOCAL_ENV.pushThreadBinding(LOCAL_ENV.currentVal());
- PersistentArrayList bindingInits = new PersistentArrayList(4);
+ PersistentVector bindingInits = PersistentVector.EMPTY;
for(ISeq bs = bindings; bs != null; bs = RT.rest(RT.rest(bs)))
{
LocalBinding lb = new LocalBinding(baseSymbol((Symbol) RT.first(bs)));
@@ -894,10 +894,10 @@ private static Expr analyzeLetStar(C context, ISeq form) throws Exception{
}
static class LetExpr extends AnExpr{
- PersistentArrayList bindingInits;
+ PersistentVector bindingInits;
Expr body;
- public LetExpr(PersistentArrayList bindingInits, Expr body){
+ public LetExpr(PersistentVector bindingInits, Expr body){
this.bindingInits = bindingInits;
this.body = body;
}
@@ -941,16 +941,16 @@ private static Expr analyzeAnd(C context, ISeq form) throws Exception{
else if(RT.count(form) == 2)
return analyze(context, macroexpand(RT.second(form)));
- PersistentArrayList exprs = new PersistentArrayList(2);
+ PersistentVector exprs = PersistentVector.EMPTY;
for(ISeq es = RT.rest(form); es != null; es = es.rest())
exprs = exprs.cons(analyze(C.EXPRESSION, macroexpand(es.first())));
return new AndExpr(exprs);
}
static class AndExpr extends AnExpr{
- final PersistentArrayList exprs;
+ final PersistentVector exprs;
- public AndExpr(PersistentArrayList exprs){
+ public AndExpr(PersistentVector exprs){
this.exprs = exprs;
}
@@ -994,17 +994,17 @@ private static Expr analyzeOr(C context, ISeq form) throws Exception{
registerLocal(tb);
}
- PersistentArrayList exprs = new PersistentArrayList(2);
+ PersistentVector exprs = PersistentVector.EMPTY;
for(ISeq es = RT.rest(form); es != null; es = es.rest())
exprs = exprs.cons(analyze(C.EXPRESSION, macroexpand(es.first())));
return new OrExpr(exprs, tb);
}
static class OrExpr extends AnExpr{
- final PersistentArrayList exprs;
+ final PersistentVector exprs;
final LocalBinding tb;
- public OrExpr(PersistentArrayList exprs, LocalBinding tb){
+ public OrExpr(PersistentVector exprs, LocalBinding tb){
this.exprs = exprs;
this.tb = tb;
}
@@ -1119,7 +1119,7 @@ static class IfExpr extends AnExpr{
}
private static Expr analyzeBody(C context, ISeq forms) throws Exception{
- PersistentArrayList exprs = new PersistentArrayList(4);
+ PersistentVector exprs = PersistentVector.EMPTY;
for(; forms != null; forms = forms.rest())
{
Expr e = (context == C.STATEMENT || RT.rest(forms) != null) ?
@@ -1132,9 +1132,9 @@ private static Expr analyzeBody(C context, ISeq forms) throws Exception{
}
static class BodyExpr extends AnExpr{
- PersistentArrayList exprs;
+ PersistentVector exprs;
- public BodyExpr(PersistentArrayList exprs){
+ public BodyExpr(PersistentVector exprs){
this.exprs = exprs;
}
@@ -1239,10 +1239,10 @@ static class FnExpr extends AnExpr{
}
public void emitDeclaration() throws Exception{
- PersistentArrayList closesDecls = null;
+ PersistentVector closesDecls = null;
if(closes != null)
{
- closesDecls = new PersistentArrayList(closes.count() * 2);
+ closesDecls = PersistentVector.EMPTY;
for(ISeq s = RT.seq(closes); s != null; s = s.rest())
{
LocalBinding b = (LocalBinding) ((IMapEntry) s.first()).key();
@@ -1385,8 +1385,8 @@ static class FnMethod{
//localbinding->localbinding
IPersistentMap locals = null;
//localbinding->localbinding
- PersistentArrayList reqParms = new PersistentArrayList(4);
- PersistentArrayList keyParms = null;
+ PersistentVector reqParms = PersistentVector.EMPTY;
+ PersistentVector keyParms = null;
LocalBindingExpr restParm = null;
Expr body = null;
FnExpr fn;
@@ -1430,7 +1430,7 @@ private static FnMethod analyzeMethod(FnExpr fn, ISeq form) throws Exception{
if(state == PSTATE.REQ)
{
state = PSTATE.KEY;
- method.keyParms = new PersistentArrayList(4);
+ method.keyParms = PersistentVector.EMPTY;
}
else
throw new Exception("Invalid parameter list");