source: branches/0.17.x/abcl/src/org/armedbear/lisp/LispStackFrame.java

Last change on this file was 12254, checked in by ehuelsmann, 16 years ago

Remove 'throws ConditionThrowable?' method annotations:

it's an unchecked exception now, so no need to declare it thrown.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.7 KB
Line 
1/*
2 * LispStackFrame.java
3 *
4 * Copyright (C) 2009 Mark Evenson
5 * $Id: LispStackFrame.java 12254 2009-11-06 20:07:54Z ehuelsmann $
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 *
21 * As a special exception, the copyright holders of this library give you
22 * permission to link this library with independent modules to produce an
23 * executable, regardless of the license terms of these independent
24 * modules, and to copy and distribute the resulting executable under
25 * terms of your choice, provided that you also meet, for each linked
26 * independent module, the terms and conditions of the license of that
27 * module.  An independent module is a module which is not derived from
28 * or based on this library.  If you modify this library, you may extend
29 * this exception to your version of the library, but you are not
30 * obligated to do so.  If you do not wish to do so, delete this
31 * exception statement from your version.
32 */
33
34package org.armedbear.lisp;
35
36public class LispStackFrame 
37  extends StackFrame
38{
39  public final LispObject operator;
40  private final LispObject first;
41  private final LispObject second;
42  private final LispObject third;
43  private final LispObject[] args;
44
45  private final class UnavailableArgument extends LispObject
46  {
47    public UnavailableArgument () { }
48    @Override
49    public String writeToString() { 
50      return unreadableString("unavailable arg", false); 
51    }
52  }
53
54  private final LispObject UNAVAILABLE_ARG = new UnavailableArgument();
55
56  public LispStackFrame(LispObject operator)
57  {
58    this.operator = operator;
59    first = null;
60    second = null;
61    third = null;
62    args = null;
63  }
64
65  public LispStackFrame(LispObject operator, LispObject arg)
66  {
67    this.operator = operator;
68    first = arg;
69    second = null;
70    third = null;
71    args = null;
72  }
73
74  public LispStackFrame(LispObject operator, LispObject first,
75      LispObject second)
76  {
77    this.operator = operator;
78    this.first = first;
79    this.second = second;
80    third = null;
81    args = null;
82  }
83
84  public LispStackFrame(LispObject operator, LispObject first,
85      LispObject second, LispObject third)
86
87  {
88    this.operator = operator;
89    this.first = first;
90    this.second = second;
91    this.third = third;
92    args = null;
93  }
94
95  public LispStackFrame(LispObject operator, LispObject... args)
96  {
97    this.operator = operator;
98    first = null;
99    second = null;
100    third = null;
101    this.args = args;
102  }
103
104   @Override
105   public LispObject typeOf() { 
106     return Symbol.LISP_STACK_FRAME; 
107   }
108 
109   @Override
110   public LispObject classOf() { 
111     return BuiltInClass.LISP_STACK_FRAME; 
112   }
113
114   @Override
115   public String writeToString() 
116   { 
117     String result = "";
118     final String LISP_STACK_FRAME = "LISP-STACK-FRAME";
119     try {
120       result =  unreadableString(LISP_STACK_FRAME + " " 
121          + toLispString().getStringValue());
122     } catch (Throwable t) {
123       Debug.trace("Serious printing error: ");
124       Debug.trace(t);
125       result = unreadableString(LISP_STACK_FRAME);
126     }
127     return result;
128   }
129
130  @Override
131  public LispObject typep(LispObject typeSpecifier) 
132
133  {
134    if (typeSpecifier == Symbol.LISP_STACK_FRAME)
135      return T;
136    if (typeSpecifier == BuiltInClass.LISP_STACK_FRAME)
137      return T;
138    return super.typep(typeSpecifier);
139   }
140
141  public LispObject toLispList() 
142
143  {
144    LispObject result = argsToLispList();
145    if (operator instanceof Operator) {
146      LispObject lambdaName = ((Operator)operator).getLambdaName();
147      if (lambdaName != null && lambdaName != Lisp.NIL)
148  return result.push(lambdaName);
149    }
150    return result.push(operator);
151  }
152
153  private LispObject argsToLispList() 
154
155  {
156    LispObject result = Lisp.NIL;
157    if (args != null) {
158      for (int i = 0; i < args.length; i++)
159        // `args' come here from LispThread.execute. I don't know
160        // how it comes that some callers pass NULL ptrs around but
161        // we better do not create conses with their CAR being NULL;
162        // it'll horribly break printing such a cons; and probably
163        // other bad things may happen, too. --TCR, 2009-09-17.
164        if (args[i] == null)
165          result = result.push(UNAVAILABLE_ARG);
166        else
167          result = result.push(args[i]);
168    } else {
169      do {
170  if (first != null)
171    result = result.push(first);
172  else
173    break;
174  if (second != null)
175    result = result.push(second);
176  else
177    break;
178  if (third != null)
179    result = result.push(third);
180  else
181    break;
182      } while (false);
183    }
184    return result.nreverse();
185  }
186
187  public SimpleString toLispString() 
188
189  {
190    String result;
191    try {
192      result = this.toLispList().writeToString();
193    } catch (Throwable t) {
194      Debug.trace("Serious printing error: ");
195      Debug.trace(t);
196      result = unreadableString("LISP-STACK-FRAME");
197    }
198    return new SimpleString(result);
199  }
200
201  public LispObject getOperator() {
202    return operator;
203  }
204
205  @Override 
206  public LispObject getParts() 
207
208  {
209    LispObject result = NIL;
210    result = result.push(new Cons("OPERATOR", getOperator()));
211    LispObject args = argsToLispList();
212    if (args != NIL) {
213      result = result.push(new Cons("ARGS", args));
214    }
215       
216    return result.nreverse();
217  }
218}
Note: See TracBrowser for help on using the repository browser.