(C context, Object frm)
| 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) |
| 6958 | { |
| 6959 | if(!(bindings.nth(i) instanceof Symbol)) |
| 6960 | throw new IllegalArgumentException( |
| 6961 | "Bad binding form, expected symbol, got: " + bindings.nth(i)); |
| 6962 | Symbol sym = (Symbol) bindings.nth(i); |
| 6963 | if(sym.getNamespace() != null) |
| 6964 | throw Util.runtimeException("Can't let qualified name: " + sym); |
| 6965 | Expr init = analyze(C.EXPRESSION, bindings.nth(i + 1), sym.name); |
| 6966 | if(isLoop) |
| 6967 | { |
| 6968 | if(recurMismatches != null && RT.booleanCast(recurMismatches.nth(i/2))) |
| 6969 | { |
nothing calls this directly
no test coverage detected