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