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 12 13 public class setq extends Syntax 14 { 15 public Expression rewriteForm (Pair form, Translator tr) 16 { 17 Object obj = form.cdr; 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.car; 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.cdr; 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.car); 37 obj = pair.cdr; 38 SetExp sexp = new SetExp(name, value); 39 sexp.setFlag(SetExp.PREFER_BINDING2); 40 if (obj == LList.Empty) 41 { 42 sexp.setHasValue(true); 43 if (results == null) 44 return sexp; 45 } 46 if (results == null) 47 results = new Vector (10); 48 results.addElement(sexp); 49 } 50 if (results == null) 51 return CommonLisp.nilExpr; 52 Expression[] stmts = new Expression[results.size()]; 53 results.copyInto(stmts); 54 return new BeginExp(stmts); 55 } 56 } 57 | Popular Tags |