01: package gnu.commonlisp.lang;
02:
03: import gnu.mapping.*;
04: import gnu.expr.*;
05: import gnu.lists.*;
06: import kawa.lang.*;
07: import java.util.Vector;
08:
09: /**
10: * The Syntax transformer that re-writes the `setq' builtin.
11: * @author Per Bothner
12: */
13:
14: public class setq extends Syntax {
15: public Expression rewriteForm(Pair form, Translator tr) {
16: Object obj = form.cdr;
17: Vector results = null;
18: while (obj != LList.Empty) {
19: if (!(obj instanceof Pair))
20: return tr.syntaxError("invalid syntax for setq");
21: Pair pair = (Pair) obj;
22: Object sym = pair.car;
23: Object name;
24: if (sym instanceof Symbol || sym instanceof String)
25: name = sym;
26: else if (sym == CommonLisp.FALSE)
27: name = "nil";
28: else
29: return tr.syntaxError("invalid variable name in setq");
30: obj = pair.cdr;
31: if (!(obj instanceof Pair))
32: return tr
33: .syntaxError("wrong number of arguments for setq");
34: pair = (Pair) obj;
35: Expression value = tr.rewrite(pair.car);
36: obj = pair.cdr;
37: SetExp sexp = new SetExp(name, value);
38: sexp.setFlag(SetExp.PREFER_BINDING2);
39: if (obj == LList.Empty) {
40: sexp.setHasValue(true);
41: if (results == null)
42: return sexp;
43: }
44: if (results == null)
45: results = new Vector(10);
46: results.addElement(sexp);
47: }
48: if (results == null)
49: return CommonLisp.nilExpr;
50: Expression[] stmts = new Expression[results.size()];
51: results.copyInto(stmts);
52: return new BeginExp(stmts);
53: }
54: }
|