1 package gnu.xquery.util; 2 import gnu.lists.*; 3 import gnu.mapping.*; 4 import gnu.expr.*; 5 import gnu.bytecode.*; 6 7 35 36 public class OrderedMap extends MethodProc 37 implements CanInline, Inlineable 38 { 39 public static final OrderedMap orderedMap = new OrderedMap(); 40 41 public static Object [] makeTuple$V (Object [] values) 42 { 43 return values; 44 } 45 46 static final ClassType typeTuples 47 = ClassType.make("gnu.xquery.util.OrderedTuples"); 48 49 public Expression inline (ApplyExp exp, ExpWalker walker) 50 { 51 Expression[] args = exp.getArgs(); 52 if (args.length > 2) 53 { 54 Expression[] rargs = new Expression[args.length-1]; 55 System.arraycopy(args, 1, rargs, 0, rargs.length); 56 Expression[] xargs = new Expression[2]; 57 Method makeTupleMethod = typeTuples.getDeclaredMethod("make$V", 2); 58 xargs[0] = args[0]; 59 xargs[1] = new ApplyExp(makeTupleMethod, rargs); 60 return new ApplyExp(this, xargs); 61 } 62 return exp; 63 } 64 65 public void apply (CallContext ctx) throws Throwable 66 { 67 Consumer out = ctx.consumer; 68 Object [] args = ctx.getArgs(); 69 Object values = args[0]; 70 OrderedTuples tuples; 71 if (args.length == 2) 72 { 73 tuples = (OrderedTuples) args[1]; 74 } 75 else 76 { 77 Object [] comps = new Object [args.length-2]; 78 System.arraycopy(args, 2, comps, 0, comps.length); 79 tuples = OrderedTuples.make$V((Procedure) args[1], comps); 80 } 81 Values.writeValues(values, tuples); 82 tuples.run$X(ctx); 83 } 84 85 public void compile (ApplyExp exp, Compilation comp, Target target) 86 { 87 Expression[] args = exp.getArgs(); 88 if (args.length != 2) 89 { 90 ApplyExp.compile(exp, comp, target); 91 return; 92 } 93 CodeAttr code = comp.getCode(); 94 Scope scope = code.pushScope(); 95 Variable consumer = scope.addVariable(code, typeTuples, null); 96 args[1].compile(comp, Target.pushValue(typeTuples)); 97 code.emitStore(consumer); 98 ConsumerTarget ctarget = new ConsumerTarget(consumer); 99 args[0].compile(comp, ctarget); 100 Method mm = typeTuples.getDeclaredMethod("run$X", 1); 101 code.emitLoad(consumer); 102 PrimProcedure.compileInvoke(comp, mm, target, exp.isTailCall(), 103 182, Type.pointer_type); 104 code.popScope(); 105 } 106 107 public gnu.bytecode.Type getReturnType (Expression[] args) 108 { 109 return Type.pointer_type; } 111 } 112 | Popular Tags |