| 6898 | } |
| 6899 | |
| 6900 | public static class LetExpr implements Expr, MaybePrimitiveExpr{ |
| 6901 | public final PersistentVector bindingInits; |
| 6902 | public final Expr body; |
| 6903 | public final boolean isLoop; |
| 6904 | |
| 6905 | public LetExpr(PersistentVector bindingInits, Expr body, boolean isLoop){ |
| 6906 | this.bindingInits = bindingInits; |
| 6907 | this.body = body; |
| 6908 | this.isLoop = isLoop; |
| 6909 | } |
| 6910 | |
| 6911 | static class Parser implements IParser{ |
| 6912 | public Expr parse(C context, Object frm) { |
| 6913 | ISeq form = (ISeq) frm; |
| 6914 | //(let [var val var2 val2 ...] body...) |
| 6915 | boolean isLoop = RT.first(form).equals(LOOP); |
| 6916 | if(!(RT.second(form) instanceof IPersistentVector)) |
| 6917 | throw new IllegalArgumentException("Bad binding form, expected vector"); |
| 6918 | |
| 6919 | IPersistentVector bindings = (IPersistentVector) RT.second(form); |
| 6920 | if((bindings.count() % 2) != 0) |
| 6921 | throw new IllegalArgumentException("Bad binding form, expected matched symbol expression pairs"); |
| 6922 | |
| 6923 | ISeq body = RT.next(RT.next(form)); |
| 6924 | |
| 6925 | if(context == C.EVAL |
| 6926 | || (context == C.EXPRESSION && isLoop)) |
| 6927 | return analyze(context, RT.list(RT.list(FNONCE, PersistentVector.EMPTY, form))); |
| 6928 | |
| 6929 | ObjMethod method = (ObjMethod) METHOD.deref(); |
| 6930 | IPersistentMap backupMethodLocals = method.locals; |
| 6931 | IPersistentMap backupMethodIndexLocals = method.indexlocals; |
| 6932 | IPersistentVector recurMismatches = PersistentVector.EMPTY; |
| 6933 | for (int i = 0; i < bindings.count()/2; i++) |
| 6934 | { |
| 6935 | recurMismatches = recurMismatches.cons(RT.F); |
| 6936 | } |
| 6937 | |
| 6938 | //may repeat once for each binding with a mismatch, return breaks |
| 6939 | while(true){ |
| 6940 | IPersistentMap dynamicBindings = RT.map(LOCAL_ENV, LOCAL_ENV.deref(), |
| 6941 | NEXT_LOCAL_NUM, NEXT_LOCAL_NUM.deref()); |
| 6942 | method.locals = backupMethodLocals; |
| 6943 | method.indexlocals = backupMethodIndexLocals; |
| 6944 | |
| 6945 | PathNode looproot = new PathNode(PATHTYPE.PATH, (PathNode) CLEAR_PATH.get()); |
| 6946 | PathNode clearroot = new PathNode(PATHTYPE.PATH,looproot); |
| 6947 | PathNode clearpath = new PathNode(PATHTYPE.PATH,looproot); |
| 6948 | if(isLoop) |
| 6949 | dynamicBindings = dynamicBindings.assoc(LOOP_LOCALS, null); |
| 6950 | |
| 6951 | try |
| 6952 | { |
| 6953 | Var.pushThreadBindings(dynamicBindings); |
| 6954 | |
| 6955 | PersistentVector bindingInits = PersistentVector.EMPTY; |
| 6956 | PersistentVector loopLocals = PersistentVector.EMPTY; |
| 6957 | for(int i = 0; i < bindings.count(); i += 2) |
nothing calls this directly
no outgoing calls
no test coverage detected