KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > kawa > reflect > ArraySet


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