Changeset 4026
- Timestamp:
- 09/23/03 15:43:08 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/j/src/org/armedbear/lisp/Primitives.java
r4023 r4026 3 3 * 4 4 * Copyright (C) 2002-2003 Peter Graves 5 * $Id: Primitives.java,v 1.43 1 2003-09-23 15:27:50piso Exp $5 * $Id: Primitives.java,v 1.432 2003-09-23 15:43:08 piso Exp $ 6 6 * 7 7 * This program is free software; you can redistribute it and/or … … 1527 1527 }; 1528 1528 1529 // ### dolist1530 private static final SpecialOperator DOLIST = new SpecialOperator("dolist")1531 {1532 public LispObject execute(LispObject args, Environment env)1533 throws ConditionThrowable1534 {1535 LispObject bodyForm = args.cdr();1536 args = args.car();1537 Symbol var = checkSymbol(args.car());1538 LispObject listForm = args.cadr();1539 final LispThread thread = LispThread.currentThread();1540 LispObject resultForm = args.cdr().cdr().car();1541 Environment oldDynEnv = thread.getDynamicEnvironment();1542 int depth = thread.getStackDepth();1543 try {1544 LispObject list = checkList(eval(listForm, env, thread));1545 // Look for tags.1546 Binding tags = null;1547 LispObject remaining = bodyForm;1548 while (remaining != NIL) {1549 LispObject current = remaining.car();1550 remaining = remaining.cdr();1551 if (current instanceof Cons)1552 continue;1553 // It's a tag.1554 tags = new Binding(current, remaining, tags);1555 }1556 while (list != NIL) {1557 Environment ext = new Environment(env);1558 bind(var, list.car(), ext);1559 LispObject body = bodyForm;1560 while (body != NIL) {1561 LispObject current = body.car();1562 if (current instanceof Cons) {1563 try {1564 // Handle GO inline if possible.1565 if (current.car() == Symbol.GO) {1566 LispObject code = null;1567 LispObject tag = current.cadr();1568 for (Binding binding = tags; binding != null; binding = binding.next) {1569 if (binding.symbol.eql(tag)) {1570 code = binding.value;1571 break;1572 }1573 }1574 if (code != null) {1575 body = code;1576 continue;1577 }1578 throw new Go(tag);1579 }1580 eval(current, ext, thread);1581 }1582 catch (Go go) {1583 LispObject code = null;1584 LispObject tag = go.getTag();1585 for (Binding binding = tags; binding != null; binding = binding.next) {1586 if (binding.symbol.eql(tag)) {1587 code = binding.value;1588 break;1589 }1590 }1591 if (code != null) {1592 body = code;1593 thread.setStackDepth(depth);1594 continue;1595 }1596 throw go;1597 }1598 }1599 body = body.cdr();1600 }1601 list = list.cdr();1602 }1603 Environment ext = new Environment(env);1604 bind(var, NIL, ext);1605 LispObject result = eval(resultForm, ext, thread);1606 return result;1607 }1608 catch (Return ret) {1609 if (ret.getTag() == NIL) {1610 thread.setStackDepth(depth);1611 return ret.getResult();1612 }1613 throw ret;1614 }1615 finally {1616 thread.setDynamicEnvironment(oldDynEnv);1617 }1618 }1619 };1620 1621 1529 // ### handler-bind 1622 1530 private static final SpecialOperator HANDLER_BIND =
Note: See TracChangeset
for help on using the changeset viewer.