1 4 package gnu.expr; 5 import gnu.bytecode.*; 6 import gnu.kawa.reflect.OccurrenceType; 7 import gnu.kawa.reflect.SingletonType; 8 9 11 12 public class SeriesTarget extends Target 13 { 14 15 public Declaration param; 16 17 18 public Label function; 19 20 22 public Label done; 23 24 29 public Scope scope; 30 31 public void compileFromStackSimple(Compilation comp, Type stackType) 32 { 33 CodeAttr code = comp.getCode(); 34 StackTarget.convert(comp, stackType, param.getType()); 35 param.compileStore(comp); 36 code.emitJsr(function); 37 if (done != null && code.reachableHere()) 38 code.emitGoto(done); 39 code.locals.preserveVariablesUpto(scope); 43 } 44 45 public void compileFromStack(Compilation comp, Type stackType) 46 { 47 CodeAttr code = comp.getCode(); 48 49 if (OccurrenceType.itemCountIsOne(stackType)) 50 { 51 compileFromStackSimple(comp, stackType); 52 return; 53 } 54 55 67 Variable indexVar = code.addLocal(Type.int_type); 68 Variable valuesVar = code.addLocal(Type.pointer_type); 69 Variable nextVar = code.addLocal(Type.int_type); 70 Label doneLabel = done; 71 boolean doneGiven; 72 if (doneLabel == null) 73 { 74 doneGiven = false; 75 doneLabel = new Label(code); 76 } 77 else 78 { 79 doneGiven = true; 80 done = null; } 82 StackTarget.convert(comp, stackType, Type.pointer_type); 83 code.emitStore(valuesVar); 84 code.emitPushInt(0); 85 code.emitStore(indexVar); 86 87 Label top = new Label(code); 88 top.define(code); 89 code.emitLoad(valuesVar); 90 code.emitLoad(indexVar); 91 code.emitInvokeStatic(Compilation.typeValues.getDeclaredMethod("nextIndex", 2)); 92 code.emitDup(Type.int_type); 93 code.emitStore(nextVar); 94 code.emitGotoIfIntLtZero(doneLabel); 95 code.emitLoad(valuesVar); 96 code.emitLoad(indexVar); 97 code.emitInvokeStatic(Compilation.typeValues.getDeclaredMethod("nextValue", 2)); 98 compileFromStackSimple(comp, SingletonType.getInstance()); 99 code.emitLoad(nextVar); 100 code.emitStore(indexVar); 101 code.emitGoto(top); 102 if (doneGiven) 103 done = doneLabel; 104 else 105 doneLabel.define(code); 106 107 120 } 121 122 public String toString() 123 { 124 return "SeriesTarget[param: "+param+"; func:"+function+" done:"+done+"]"; 125 } 126 127 public Type getType() { return Type.pointer_type; } 128 } 129 | Popular Tags |