1 package kawa.standard; 2 import kawa.lang.*; 3 import gnu.lists.*; 4 import gnu.mapping.*; 5 import gnu.mapping.Location; import gnu.expr.*; 7 import gnu.bytecode.*; 8 import gnu.kawa.reflect.Invoke; 9 10 14 15 public class location extends Syntax 16 { 17 public static final location location = new location(); 18 static { location.setName("location"); } 19 20 public Expression rewrite (Object obj, Translator tr) 21 { 22 if (! (obj instanceof Pair)) 23 return tr.syntaxError ("missing argument to location"); 24 Pair pair = (Pair) obj; 25 if (pair.cdr != LList.Empty) 26 return tr.syntaxError ("extra arguments to location"); 27 Expression[] args = { location.rewrite(tr.rewrite(pair.car), tr) }; 29 return Invoke.makeInvokeStatic(thisType, "makeLocationProc", args); 30 } 31 32 private static ClassType thisType = ClassType.make("kawa.standard.location"); 33 34 public static Expression rewrite (Expression arg, Translator tr) 35 { 36 if (arg instanceof ReferenceExp) 37 { 38 ReferenceExp rexp = (ReferenceExp) arg; 39 rexp.setDontDereference(true); 40 Declaration decl = rexp.getBinding(); 41 if (decl != null) 42 { 43 if (decl.isLexical()) 44 decl.setIndirectBinding(true); 45 decl = Declaration.followAliases(decl); 46 decl.setCanRead(true); 47 decl.setCanWrite(true); 48 } 49 return rexp; 50 } 51 if (arg instanceof ApplyExp) 52 { 53 ApplyExp aexp = (ApplyExp) arg; 54 Expression[] args = new Expression[aexp.getArgs().length + 1]; 55 args[0] = aexp.getFunction(); 56 System.arraycopy(aexp.getArgs(), 0, args, 1, args.length-1); 57 return Invoke.makeInvokeStatic(thisType, "makeProcLocation", args); 58 } 59 return tr.syntaxError("invalid argument to location"); 60 } 61 62 public static Location 63 makeProcLocation$V (Procedure proc, Object [] args) 64 { 65 int nargs = args.length; 66 if (proc instanceof gnu.kawa.functions.ApplyToArgs 67 && nargs > 0 68 && args[0] instanceof Procedure) { 70 proc = (Procedure) args[0]; 71 if (proc instanceof LocationProc && nargs == 1) 72 return ((LocationProc) proc).getLocation(); 73 Object [] rargs = new Object [nargs-1]; 74 System.arraycopy(args, 1, rargs, 0, rargs.length); 75 return new ProcLocation(proc, rargs); 76 } 77 if (proc instanceof LocationProc && nargs == 0) 78 return ((LocationProc) proc).getLocation(); 79 return new ProcLocation(proc, args); 80 } 81 82 public static Procedure 83 makeLocationProc (Location loc) 84 { 85 return new LocationProc(loc); 86 } 87 } 88 | Popular Tags |