/*
* $Id: FunctionDispatcher.java,v 1.2 2002/09/16 08:05:04 jkl Exp $
*
* Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
*
* Use is subject to license terms, as defined in
* Anvil Sofware License, Version 1.1. See LICENSE
* file, or http://njet.org/license-1.1.txt
*/
package anvil.script.compiler;
import anvil.core.Any;
import anvil.core.AnyTuple;
import anvil.core.Array;
import anvil.script.Function;
import anvil.script.Context;
public abstract class FunctionDispatcher implements Function
{
public FunctionDispatcher()
{
}
public abstract Any execute(Context context, Object self, Any parameters[]);
public static final Array rest1(Any[] parameters, int start)
{
Array array = new Array();
int n = parameters.length;
while(start < n) {
array.append(parameters[start++]);
}
return array;
}
public static final Any[] rest2(Any[] parameters, int start)
{
if (start == 0) {
return parameters;
}
int n = parameters.length;
int m = n - start;
if (m == 0) {
return Any.ARRAY0;
}
Any[] rest = new Any[m];
System.arraycopy(parameters, start, rest, 0, m);
return rest;
}
public static final AnyTuple rest3(Any[] parameters, int start)
{
if (start == 0) {
return new AnyTuple(parameters);
}
int n = parameters.length;
int m = n - start;
if (m == 0) {
return Any.EMPTY_TUPLE;
}
Any[] rest = new Any[m];
System.arraycopy(parameters, start, rest, 0, m);
return new AnyTuple(rest);
}
}