01: /*
02: * @(#)arraycopy.java 1.2 04/12/06
03: *
04: * Copyright (c) 1997-2004 Sun Microsystems, Inc. All Rights Reserved.
05: *
06: * See the file "LICENSE.txt" for information on usage and redistribution
07: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
08: */
09: package org.pnuts.lib;
10:
11: import pnuts.lang.*;
12: import pnuts.lang.Runtime;
13: import java.io.*;
14: import java.lang.reflect.*;
15:
16: public class arraycopy extends PnutsFunction {
17:
18: public arraycopy() {
19: super ("arraycopy");
20: }
21:
22: public boolean defined(int narg) {
23: return (narg == 2 || narg == 5);
24: }
25:
26: protected Object exec(Object[] args, Context context) {
27: int nargs = args.length;
28: if (nargs == 2) {
29: Object src = args[0];
30: System.arraycopy(src, 0, args[1], 0, Runtime
31: .getArrayLength(src));
32: } else if (nargs == 5) {
33: System.arraycopy(args[0], ((Integer) args[1]).intValue(),
34: args[2], ((Integer) args[3]).intValue(),
35: ((Integer) args[4]).intValue());
36: } else {
37: undefined(args, context);
38: }
39: return null;
40: }
41:
42: public String toString() {
43: return "function arraycopy(src, dest) or (src, srcindex, dst, dstindex, len)";
44: }
45: }
|