1 package gnu.kawa.reflect; 2 import gnu.bytecode.*; 3 import gnu.mapping.*; 4 import gnu.expr.*; 5 import java.io.*; 6 import java.lang.reflect.Array ; 7 8 public class ArrayGet extends Procedure2 implements Inlineable, Externalizable 9 { 10 Type element_type; 11 12 public ArrayGet (Type element_type) 13 { 14 this.element_type = element_type; 15 } 16 17 public Object apply2 (Object array, Object index) 18 { 19 Object value = Array.get(array, ((Number ) index).intValue()); 20 return element_type.coerceToObject(value); 21 } 22 public void compile (ApplyExp exp, Compilation comp, Target target) 23 { 24 Expression[] args = exp.getArgs(); 25 args[0].compile(comp, ArrayType.make(element_type)); 26 args[1].compile(comp, Type.int_type); 27 CodeAttr code = comp.getCode(); 28 code.emitArrayLoad(element_type); 29 target.compileFromStack(comp, element_type); 30 } 31 32 public gnu.bytecode.Type getReturnType (Expression[] args) 33 { 34 return element_type; 35 } 36 37 public void writeExternal(ObjectOutput out) throws IOException 38 { 39 out.writeObject(element_type); 40 } 41 42 public void readExternal(ObjectInput in) 43 throws IOException, ClassNotFoundException 44 { 45 element_type = (Type) in.readObject(); 46 } 47 } 48 | Popular Tags |