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