1 package gnu.commonlisp.lang; 2 import gnu.mapping.*; 3 import gnu.expr.*; 4 import gnu.lists.*; 5 import kawa.lang.*; 6 7 11 12 public class defun extends Syntax 13 { 14 kawa.lang.Lambda lambdaSyntax; 15 16 public defun (kawa.lang.Lambda lambdaSyntax) 17 { 18 this.lambdaSyntax = lambdaSyntax; 19 } 20 21 public boolean scanForDefinitions (Pair st, java.util.Vector forms, 22 ScopeExp defs, Translator tr) 23 { 24 Pair p; 25 if (! (st.cdr instanceof Pair) 26 || ! (((p = (Pair) st.cdr).car instanceof String ) 27 || p.car instanceof Symbol)) 28 return super.scanForDefinitions(st, forms, defs, tr); 29 Object sym = p.car; 30 Declaration decl = defs.lookup(sym); 31 if (decl == null) 32 { 33 decl = new Declaration(sym); 34 decl.setProcedureDecl(true); 35 defs.addDeclaration(decl); 36 } 37 else 38 tr.error('w', "duplicate declaration for `"+sym+"'"); 39 40 if (defs instanceof ModuleExp) 41 decl.setCanRead(true); 42 st = Translator.makePair(st, this, Translator.makePair(p, decl, p.cdr)); 43 forms.addElement (st); 44 return true; 45 } 46 47 public Expression rewriteForm (Pair form, Translator tr) 48 { 49 Object obj = form.cdr; 50 Object name = null; 51 Expression value = null; 52 Declaration decl = null; 53 54 if (obj instanceof Pair) 55 { 56 Pair p1 = (Pair) obj; 57 58 if (p1.car instanceof Symbol || p1.car instanceof String ) 59 { 60 name = p1.car.toString(); 61 } 62 else if (p1.car instanceof Declaration) 63 { 64 decl = (Declaration) p1.car; 65 name = decl.getSymbol(); 66 } 67 if (name != null && p1.cdr instanceof Pair) 68 { 69 Pair p2 = (Pair) p1.cdr; 70 LambdaExp lexp = new LambdaExp(); 71 lambdaSyntax.rewrite(lexp, p2.car, p2.cdr, tr, null); 72 lexp.setSymbol(name); 73 if (p2 instanceof PairWithPosition) 74 lexp.setLocation((PairWithPosition) p2); 75 value = lexp; 76 SetExp sexp = new SetExp (name, value); 77 sexp.setDefining(true); 78 sexp.setFuncDef(true); 79 if (decl != null) 80 { 81 sexp.setBinding(decl); 82 if (decl.context instanceof ModuleExp && decl.getCanWrite()) 83 value = null; 84 decl.noteValue(value); 85 } 86 return sexp; 87 } 88 } 89 return tr.syntaxError ("invalid syntax for "+getName()); 90 } 91 } 92 | Popular Tags |