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 ArrayNew extends Procedure1 implements Inlineable,
09: Externalizable {
10: Type element_type;
11:
12: public ArrayNew(Type element_type) {
13: this .element_type = element_type;
14: }
15:
16: public Object apply1(Object count) {
17: return java.lang.reflect.Array.newInstance(element_type
18: .getReflectClass(), ((Number) count).intValue());
19: }
20:
21: public void compile(ApplyExp exp, Compilation comp, Target target) {
22: exp.getArgs()[0].compile(comp, Type.int_type);
23: CodeAttr code = comp.getCode();
24: code.emitNewArray(element_type);
25: target.compileFromStack(comp, ArrayType.make(element_type));
26: }
27:
28: public gnu.bytecode.Type getReturnType(Expression[] args) {
29: return ArrayType.make(element_type);
30: }
31:
32: public void writeExternal(ObjectOutput out) throws IOException {
33: out.writeObject(element_type);
34: }
35:
36: public void readExternal(ObjectInput in) throws IOException,
37: ClassNotFoundException {
38: element_type = (Type) in.readObject();
39: }
40: }
|