commit c835b1772fc487087d5f5f6c45b251dbe1174f30
parent 7335d5822c39a73f69e4e8bc48a8b1437f630149
Author: tomas <tomas@logand.com>
Date: Wed, 7 Oct 2009 21:16:31 +0200
added 'intern', *Args and implemented fully applyC
Diffstat:
M | wl.java | | | 91 | +++++++++++++++++++++++++++++++++---------------------------------------------- |
1 file changed, 38 insertions(+), 53 deletions(-)
diff --git a/wl.java b/wl.java
@@ -156,6 +156,7 @@ class wl implements Runnable {
final Any Qte = mkIsym("quote", NIL, NIL);
final Any Dot = mkIsym(".", NIL, NIL);
final Any At = mkIsym("@", NIL, NIL);
+ final Any Args = mkIsym("*Args", NIL, NIL);
class In {
Character c;
@@ -301,13 +302,28 @@ class wl implements Runnable {
restoreV(Fa, O);
return Z;
}
+ Any mapcarEval(Any E) {
+ Any A = mkCons(NIL, NIL);
+ Any Z = A;
+ while(E.isCons()) {
+ Z.con(mkCons(eval(E.car()), NIL));
+ Z = Z.cdr();
+ E = E.cdr();
+ }
+ return A.cdr();
+ }
Any saveV(Any Fa, Any A) {
Any O = NIL;
if(Fa.isIsym()) {
if(NIL != Fa) {
- O = mkCons(Fa.cdr(), NIL);
- Fa.con(A);
- } // TODO @
+ if(At == Fa) {
+ O = mkCons(Args.cdr(), NIL);
+ Args.con(mkCons(NIL, mapcarEval(A)));
+ } else {
+ O = mkCons(Fa.cdr(), NIL);
+ Fa.con(A);
+ }
+ }
} else if(Fa.isCons()) {
Any B = mkCons(NIL, NIL);
Any Z = B;
@@ -322,17 +338,24 @@ class wl implements Runnable {
}
if(NIL != Fa) {
if(!Fa.isIsym()) err(Fa, "Isym expected in saveV");
- Z.con(mkCons(Fa.cdr(), NIL));
- Fa.con(A);
- } // TODO (X Y . @)
+ if(At == Fa) {
+ Z.con(mkCons(Args.cdr(), NIL));
+ Args.con(mkCons(NIL, mapcarEval(A)));
+ } else {
+ Z.con(mkCons(Fa.cdr(), NIL));
+ Fa.con(A);
+ }
+ }
O = B.cdr();
} else err(Fa, "Don't know how to saveV");
return O;
}
void restoreV(Any Fa, Any O) {
if(Fa.isIsym()) {
- if(NIL != Fa) Fa.con(O.car());
- // TODO @
+ if(NIL != Fa) {
+ if(At == Fa) Args.con(O.car());
+ else Fa.con(O.car());
+ }
} else if(Fa.isCons()) {
while(Fa.isCons()) {
Any X = Fa.car();
@@ -343,8 +366,9 @@ class wl implements Runnable {
}
if(NIL != Fa) {
if(!Fa.isIsym()) err(Fa, "Isym expected in saveV");
- Fa.con(O.car());
- } // TODO (X Y . @)
+ if(At == Fa) Args.con(O.car());
+ else Fa.con(O.car());
+ }
} else err(Fa, "Don't know how to restoreV");
}
Any japplyC(Any E, Any O) { // 'obj 'meth [arg ...]
@@ -390,6 +414,7 @@ class wl implements Runnable {
Sd.put("quote", Qte);
Sd.put(".", Dot);
Sd.put("@", At);
+ Sd.put("*Args", Args);
Sd.put("*In", In);
Sd.put("*Out", Out);
Sd.put("java.lang.Class", mkObj(java.lang.Class.class));
@@ -570,50 +595,10 @@ class wl implements Runnable {
Any X = E.cdr();
return mkCons(eval(X.car()), eval(X.cdr().car()));
}});
+ fn("intern", new Fn() {public Any fn(Any E) {
+ return intern((String) eval(E.cdr().car()).cxr());
+ }});
- // fn("jclass", new Fn() {public Any fn(Any E) { // jclass 'sym
- // Any X = E.cdr();
- // String N = evStr(X.car());
- // Any Z = NIL;
- // try {
- // Class C = Class.forName(N);
- // Z = mkObj(C);
- // } catch(ClassNotFoundException e) {
- // }
- // return Z;
- // }});
- // fn("jcall", new Fn() {public Any fn(Any E) { // jcall 'fn 'obj [arg ...]
- // Any I = E.cdr();
- // Any F = eval(I.car());
- // I = I.cdr();
- // Any O = eval(I.car());
- // Any A = I.cdr();
- // Any Z = NIL;
- // ArrayList<Object> a = new ArrayList();
- // ArrayList<Class> t = new ArrayList();
- // for(Any X = A; NIL != X; X = X.cdr()) {
- // // TODO handle non-native?
- // Any Y = eval(X.car());
- // a.add(Y.cxr());
- // t.add(Y.cxr().getClass());
- // }
- // Object[] aa = a.toArray();
- // Class[] ta = (Class[]) t.toArray(new Class[aa.length]);
- // try {
- // Object o = O.cxr();
- // Class c = o instanceof Class ? (Class) o : o.getClass();
- // Method m = c.getMethod(F.nm(), ta);
- // Object r = m.invoke(o, aa);
- // Z = mkObj(r);
- // } catch(NoSuchMethodException e) {
- // err(E, "NoSuchMethodException");
- // } catch(IllegalAccessException e) {
- // err(E, "IllegalAccessException");
- // } catch(InvocationTargetException e) {
- // err(E, "InvocationTargetException");
- // }
- // return Z;
- // }});
fn("jnew", new Fn() {public Any fn(Any E) { // jnew 'cls [arg ...]
Any I = E.cdr();
Any C = eval(I.car());