Changeset 4023
- Timestamp:
- 09/23/03 15:27:50 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/j/src/org/armedbear/lisp/Primitives.java
r4022 r4023 3 3 * 4 4 * Copyright (C) 2002-2003 Peter Graves 5 * $Id: Primitives.java,v 1.43 0 2003-09-23 15:17:01piso Exp $5 * $Id: Primitives.java,v 1.431 2003-09-23 15:27:50 piso Exp $ 6 6 * 7 7 * This program is free software; you can redistribute it and/or … … 1528 1528 1529 1529 // ### dolist 1530 private static final SpecialOperator DOLIST = new SpecialOperator("dolist") { 1530 private static final SpecialOperator DOLIST = new SpecialOperator("dolist") 1531 { 1531 1532 public LispObject execute(LispObject args, Environment env) 1532 1533 throws ConditionThrowable … … 1537 1538 LispObject listForm = args.cadr(); 1538 1539 final LispThread thread = LispThread.currentThread(); 1539 LispObject list = checkList(eval(listForm, env, thread));1540 1540 LispObject resultForm = args.cdr().cdr().car(); 1541 1541 Environment oldDynEnv = thread.getDynamicEnvironment(); 1542 while (list != NIL) { 1543 Environment ext = new Environment(env); 1544 bind(var, list.car(), ext); 1545 LispObject body = bodyForm; 1546 int depth = thread.getStackDepth(); 1547 try { 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; 1548 1560 while (body != NIL) { 1549 LispObject result = eval(body.car(), ext, thread); 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 } 1550 1599 body = body.cdr(); 1551 1600 } 1552 } 1553 catch (Return ret) { 1554 if (ret.getTag() == NIL) { 1555 thread.setStackDepth(depth); 1556 return ret.getResult(); 1557 } 1558 throw ret; 1559 } 1560 list = list.cdr(); 1561 } 1562 Environment ext = new Environment(env); 1563 bind(var, NIL, ext); 1564 LispObject result = eval(resultForm, ext, thread); 1565 thread.setDynamicEnvironment(oldDynEnv); 1566 return result; 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 } 1567 1618 } 1568 1619 };
Note: See TracChangeset
for help on using the changeset viewer.