(C context, Object form)
| 523 | |
| 524 | static class Parser implements IParser{ |
| 525 | public Expr parse(C context, Object form) { |
| 526 | //(def x) or (def x initexpr) or (def x "docstring" initexpr) |
| 527 | String docstring = null; |
| 528 | if(RT.count(form) == 4 && (RT.third(form) instanceof String)) { |
| 529 | docstring = (String) RT.third(form); |
| 530 | form = RT.list(RT.first(form), RT.second(form), RT.fourth(form)); |
| 531 | } |
| 532 | if(RT.count(form) > 3) |
| 533 | throw Util.runtimeException("Too many arguments to def"); |
| 534 | else if(RT.count(form) < 2) |
| 535 | throw Util.runtimeException("Too few arguments to def"); |
| 536 | else if(!(RT.second(form) instanceof Symbol)) |
| 537 | throw Util.runtimeException("First argument to def must be a Symbol"); |
| 538 | Symbol sym = (Symbol) RT.second(form); |
| 539 | Var v = lookupVar(sym, true); |
| 540 | if(v == null) |
| 541 | throw Util.runtimeException("Can't refer to qualified var that doesn't exist"); |
| 542 | if(!v.ns.equals(currentNS())) |
| 543 | { |
| 544 | if(sym.ns == null) |
| 545 | { |
| 546 | v = currentNS().intern(sym); |
| 547 | registerVar(v); |
| 548 | } |
| 549 | // throw Util.runtimeException("Name conflict, can't def " + sym + " because namespace: " + currentNS().name + |
| 550 | // " refers to:" + v); |
| 551 | else |
| 552 | throw Util.runtimeException("Can't create defs outside of current ns"); |
| 553 | } |
| 554 | IPersistentMap mm = sym.meta(); |
| 555 | boolean isDynamic = RT.booleanCast(RT.get(mm,dynamicKey)); |
| 556 | if(isDynamic) |
| 557 | v.setDynamic(); |
| 558 | if(!isDynamic && sym.name.startsWith("*") && sym.name.endsWith("*") && sym.name.length() > 2) |
| 559 | { |
| 560 | RT.errPrintWriter().format("Warning: %1$s not declared dynamic and thus is not dynamically rebindable, " |
| 561 | +"but its name suggests otherwise. Please either indicate ^:dynamic %1$s or change the name. (%2$s:%3$d)\n", |
| 562 | sym, SOURCE_PATH.get(), LINE.get()); |
| 563 | } |
| 564 | if(RT.booleanCast(RT.get(mm, arglistsKey))) |
| 565 | { |
| 566 | IPersistentMap vm = v.meta(); |
| 567 | //vm = (IPersistentMap) RT.assoc(vm,staticKey,RT.T); |
| 568 | //drop quote |
| 569 | vm = (IPersistentMap) RT.assoc(vm,arglistsKey,RT.second(mm.valAt(arglistsKey))); |
| 570 | v.setMeta(vm); |
| 571 | } |
| 572 | Object source_path = SOURCE_PATH.get(); |
| 573 | source_path = source_path == null ? "NO_SOURCE_FILE" : source_path; |
| 574 | mm = (IPersistentMap) RT.assoc(mm, RT.LINE_KEY, LINE.get()).assoc(RT.COLUMN_KEY, COLUMN.get()).assoc(RT.FILE_KEY, source_path); |
| 575 | if (docstring != null) |
| 576 | mm = (IPersistentMap) RT.assoc(mm, RT.DOC_KEY, docstring); |
| 577 | // mm = mm.without(RT.DOC_KEY) |
| 578 | // .without(Keyword.intern(null, "arglists")) |
| 579 | // .without(RT.FILE_KEY) |
| 580 | // .without(RT.LINE_KEY) |
| 581 | // .without(RT.COLUMN_KEY) |
| 582 | // .without(Keyword.intern(null, "ns")) |
nothing calls this directly
no test coverage detected