Thread: [Mathlib-commitlog] SF.net SVN: mathlib:[618] JMathLib/trunk/src/jmathlib/core/functions/ UserFunct
Status: Beta
Brought to you by:
st_mueller
|
From: <st_...@us...> - 2009-01-05 15:05:06
|
Revision: 618
http://mathlib.svn.sourceforge.net/mathlib/?rev=618&view=rev
Author: st_mueller
Date: 2009-01-05 15:05:03 +0000 (Mon, 05 Jan 2009)
Log Message:
-----------
changed handling of global variables
Modified Paths:
--------------
JMathLib/trunk/src/jmathlib/core/functions/UserFunction.java
Modified: JMathLib/trunk/src/jmathlib/core/functions/UserFunction.java
===================================================================
--- JMathLib/trunk/src/jmathlib/core/functions/UserFunction.java 2009-01-05 15:02:49 UTC (rev 617)
+++ JMathLib/trunk/src/jmathlib/core/functions/UserFunction.java 2009-01-05 15:05:03 UTC (rev 618)
@@ -13,7 +13,7 @@
/** The code of the current m-function */
private OperandToken code;
- /**The names of the paramater values*/
+ /**The names of the parameter values*/
private ArrayList parameterVariables;
/**The names of the return values*/
@@ -25,9 +25,6 @@
/**Creates a user function */
public UserFunction()
{
- //VariableList localVariables = new VariableList();
- //functionContext = getContextList().createContext(localVariables);
-
parameterVariables = new ArrayList();
returnVariables = new ArrayList();
}
@@ -97,10 +94,10 @@
Errors.throwMathLibException("UserFunction: "+name+" number of parameters to large");
// set the variable NARGIN to the number of parameters of the calling function
- getVariables().createVariable("nargin").assign(new DoubleNumberToken(opLength));
+ createVariable("nargin").assign(new DoubleNumberToken(opLength));
// set the variable NARGOUT to the number of return values
- getVariables().createVariable("nargout").assign(new DoubleNumberToken(returnVariables.size()));
+ createVariable("nargout").assign(new DoubleNumberToken(returnVariables.size()));
//set the input parameters for the function
@@ -113,7 +110,7 @@
{
String parameterName = (String)parameterVariables.get(paramNo);
//System.out.println("UserFunction: "+parameterName);
- getVariables().createVariable(parameterName).assign((OperandToken)operands[paramNo]);
+ createVariable(parameterName).assign((OperandToken)operands[paramNo]);
}
}
else
@@ -127,7 +124,7 @@
{
String parameterName = (String)parameterVariables.get(paramNo);
ErrorLogger.debugLine("UserF: params: "+parameterName);
- getVariables().createVariable(parameterName).assign((OperandToken)operands[paramNo]);
+ createVariable(parameterName).assign((OperandToken)operands[paramNo]);
}
ErrorLogger.debugLine("UserF: remainingOps: "+ remainingOps);
@@ -144,13 +141,13 @@
values[i][0] = (OperandToken)operands[parameterVariables.size()-1+i];
}
CellArrayToken cell = new CellArrayToken(values);
- getVariables().createVariable("varargin").assign(cell);
+ createVariable("varargin").assign(cell);
}
else
{
// varargin is empty
CellArrayToken cell = new CellArrayToken();
- getVariables().createVariable("varargin").assign(cell);
+ createVariable("varargin").assign(cell);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <st_...@us...> - 2009-01-24 19:39:56
|
Revision: 755
http://mathlib.svn.sourceforge.net/mathlib/?rev=755&view=rev
Author: st_mueller
Date: 2009-01-24 19:39:52 +0000 (Sat, 24 Jan 2009)
Log Message:
-----------
changed signature of evaluate(Token[] operands)
to
evaluate(Token[] operands, GlobalValues globals)
Modified Paths:
--------------
JMathLib/trunk/src/jmathlib/core/functions/UserFunction.java
Modified: JMathLib/trunk/src/jmathlib/core/functions/UserFunction.java
===================================================================
--- JMathLib/trunk/src/jmathlib/core/functions/UserFunction.java 2009-01-24 19:37:02 UTC (rev 754)
+++ JMathLib/trunk/src/jmathlib/core/functions/UserFunction.java 2009-01-24 19:39:52 UTC (rev 755)
@@ -30,9 +30,11 @@
}
/**Executes a user function
- @param operands - the array of parameters
- @return the result of the function as an OperandToken*/
- public OperandToken evaluate(Token[] operands)
+ * @param operands - the array of parameters
+ * @param globals
+ * @return the result of the function as an OperandToken
+ * */
+ public OperandToken evaluate(Token[] operands, GlobalValues globals)
{
Context functionContext; // The context of the function
OperandToken result = null;
@@ -43,7 +45,7 @@
{
// evaluate m-script
if (code!=null)
- result = code.evaluate(null);
+ result = code.evaluate(null, globals);
}
else
{
@@ -51,7 +53,7 @@
// m-functions have a local context (local variables)
VariableList localVariables = new VariableList();
- functionContext = getContextList().createContext(localVariables);
+ functionContext = globals.getContextList().createContext(localVariables);
//if nescessary create a context and store on list
//if(activeContext == null)
@@ -94,10 +96,10 @@
Errors.throwMathLibException("UserFunction: "+name+" number of parameters to large");
// set the variable NARGIN to the number of parameters of the calling function
- createVariable("nargin").assign(new DoubleNumberToken(opLength));
+ globals.createVariable("nargin").assign(new DoubleNumberToken(opLength));
// set the variable NARGOUT to the number of return values
- createVariable("nargout").assign(new DoubleNumberToken(returnVariables.size()));
+ globals.createVariable("nargout").assign(new DoubleNumberToken(returnVariables.size()));
//set the input parameters for the function
@@ -110,7 +112,7 @@
{
String parameterName = (String)parameterVariables.get(paramNo);
//System.out.println("UserFunction: "+parameterName);
- createVariable(parameterName).assign((OperandToken)operands[paramNo]);
+ globals.createVariable(parameterName).assign((OperandToken)operands[paramNo]);
}
}
else
@@ -124,7 +126,7 @@
{
String parameterName = (String)parameterVariables.get(paramNo);
ErrorLogger.debugLine("UserF: params: "+parameterName);
- createVariable(parameterName).assign((OperandToken)operands[paramNo]);
+ globals.createVariable(parameterName).assign((OperandToken)operands[paramNo]);
}
ErrorLogger.debugLine("UserF: remainingOps: "+ remainingOps);
@@ -141,13 +143,13 @@
values[i][0] = (OperandToken)operands[parameterVariables.size()-1+i];
}
CellArrayToken cell = new CellArrayToken(values);
- createVariable("varargin").assign(cell);
+ globals.createVariable("varargin").assign(cell);
}
else
{
// varargin is empty
CellArrayToken cell = new CellArrayToken();
- createVariable("varargin").assign(cell);
+ globals.createVariable("varargin").assign(cell);
}
}
@@ -157,7 +159,7 @@
{
// must clone function code, so that the original code remains untouched
OperandToken codeLocal = (OperandToken)code.clone();
- result = codeLocal.evaluate(null);
+ result = codeLocal.evaluate(null, globals);
// result should be DoubleNumberToken e.g. 1+2 -> >3<
@@ -167,7 +169,7 @@
String name = (String)returnVariables.get(0);
//System.out.println("UserFunction: returnVariable "+name);
//Variable var = (Variable)getVariables().getVariable(name);
- Variable var = getVariable(name);
+ Variable var = globals.getVariable(name);
result = var.getData();
}
else if (returnVariables.size() > 1)
@@ -181,7 +183,7 @@
{
String name = (String)returnVariables.get(i);
//Variable retVar = ((Variable)getVariables().getVariable(name));
- Variable retVar = getVariable(name);
+ Variable retVar = globals.getVariable(name);
// check if return variable has been used before
if (retVar != null)
values[0][i] = retVar.getData();
@@ -194,17 +196,17 @@
//reset to the previous variable frame
- getContextList().popContext();
+ globals.getContextList().popContext();
}
catch(ControlException e)
{
// assign return values
- getContextList().popContext();
+ globals.getContextList().popContext();
//activeContext = null;
}
catch (Exception e)
{
- getContextList().popContext();
+ globals.getContextList().popContext();
throwMathLibException(e.getMessage());
}
@@ -238,134 +240,45 @@
return equal;
}
- /**Returns the number of return variables of this function
- @return returnCount = number of return variables */
- //public int getReturnCount()
- //{
- // return returnVariables.size();
- //}
-
- /**Returns the number of parameters of this function
- @return parameterCount = number of parameters */
- //public int getParameterCount()
- //{
- // return paramaterNames.size();
- //}
-
+ /**
+ *
+ * @param _parameterVariables
+ */
public void setParameterVariables(ArrayList _parameterVariables)
{
//getLocalVariables().createVariable(name);
parameterVariables = _parameterVariables;
}
+ /**
+ *
+ * @param _returnVariables
+ */
public void setReturnVariables(ArrayList _returnVariables)
{
//getLocalVariables().createVariable(name);
returnVariables = _returnVariables;
}
- /**Sets the number of parameters of this function
- @param parameterCount = number of parameters */
- //public void setParameterCount(int _parameterCount)
- //{
- // //parameterCount = _parameterCount;
- //}
-
- /**Returns the name of this function
- @return name = name of this function */
- //public String getName()
- //{
- // return name;
- //}
-
- /**Sets the name of this function
- @param name = name of this function */
- //public void setName(String _name)
- //{
- // name = _name;
- //}
-
/**Sets the parsed code as a token tree
- @param code = parsed code of this function */
+ * @param code = parsed code of this function
+ */
public void setCode(OperandToken _code)
{
code = _code;
}
- /**Returns the local variables
- @return localVariables = local variables of this function */
- //public VariableList getLocalVariables()
- //{
- // //return functionContext.getVariables();
- // return getVariables();
- //}
-
-/* public void setFunctionParameters(Token[] operands)
- {
- //set the parameters for the function
- int noParameters =0;
- if (operands!=null) noParameters = operands.length;
-
- int parameterCount = getParameterCount();
-
- if(noParameters < parameterCount)
- {
- Errors.throwMathLibException(ERR_INSUFFICIENT_PARAMETERS, new Object[] {new DoubleNumberToken(parameterCount)});
- }
- else if(noParameters > parameterCount)
- {
- //set last param to be a list of parameters
- OperandToken[][] values = new OperandToken[1][noParameters - parameterCount + 1];
-
- for(int index = parameterCount - 1; index < noParameters; index++)
- {
- values[0][index - parameterCount + 1] = (OperandToken)operands[index];
- }
-
- operands[parameterCount - 1] = new MatrixToken(values);
- }
-
- for(int paramNo = 0; paramNo < parameterCount; paramNo++)
- {
- getVariables().setVariable(((String)parameterVariables.get(paramNo)), (OperandToken)operands[paramNo]);
- }
- }
-*/
-
- //public OperandToken getFunctionResult()
- //{
- // OperandToken result = null;
- // int returnCount = getReturnCount();
-
- // //acess the return values for the function
- // if(returnCount == 1)
- // {
- // String name = ((String)returnNames.get(0));
- // result = ((Variable)getVariables().getVariable(name)).getData();
- // }
- // else
- // {
- // OperandToken[][] values = new OperandToken[1][returnCount];
-
- // for(int index = 0; index < returnCount; index++)
- // {
- // String name = ((String)returnNames.get(index));
- // values[0][index] = ((Variable)getVariables().getVariable(name)).getData();
- // }
-
- // result = new MatrixToken(values);
- // }
-
- // return result;
- //}
-
- /** set true if this is a m-script file and not a function */
+ /** set true if this is a m-script file and not a function
+ * @param
+ */
public void setScript(boolean _mScriptB)
{
mScriptB = _mScriptB;
}
- /** returns true if this is a m-script file */
+ /** returns true if this is a m-script file
+ * @return
+ */
public boolean isScript()
{
return mScriptB;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|