01: package gnu.kawa.reflect;
02:
03: import gnu.bytecode.*;
04: import gnu.mapping.*;
05: import gnu.expr.*;
06: import java.io.*;
07:
08: public class ArraySet extends Procedure3 implements Inlineable,
09: Externalizable {
10: Type element_type;
11:
12: public ArraySet(Type element_type) {
13: this .element_type = element_type;
14: }
15:
16: public Object apply3(Object array, Object index, Object value) {
17: java.lang.reflect.Array.set(array, ((Number) index).intValue(),
18: element_type.coerceFromObject(value));
19: return Values.empty;
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: args[2].compile(comp, element_type);
27: comp.getCode().emitArrayStore(element_type);
28: comp.compileConstant(Values.empty, target);
29: }
30:
31: public gnu.bytecode.Type getReturnType(Expression[] args) {
32: return Type.void_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: }
|