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