return isVector;\r
}\r
\r
+ private Object subscript(IEnvironment environment, IExpression[] subscripts, int position) {\r
+ \r
+ IExpression e = subscripts[position];\r
+ int index = Utils.getIndex(e.evaluate(environment));\r
+ if(index == -2) {\r
+ Array ret = new Array();\r
+ for(Object element : elements) {\r
+ // Last position should not be array\r
+ if(position == subscripts.length-1) {\r
+ if(element instanceof Array) throw new IllegalStateException();\r
+ if(element instanceof IExpression) {\r
+ IExpression exp = (IExpression)element;\r
+ return exp.evaluate(environment);\r
+ } else {\r
+ ret.addElement(element);\r
+ }\r
+ } else {\r
+ if(element instanceof Array) {\r
+ return ret.addElement(((Array)element).subscript(environment, subscripts, position+1));\r
+ } else {\r
+ throw new IllegalStateException();\r
+ }\r
+ }\r
+ }\r
+ return ret;\r
+ } else {\r
+ Object element = element(index);\r
+ // Last position should not be array\r
+ if(position == subscripts.length-1) {\r
+ if(element instanceof Array) throw new IllegalStateException();\r
+ if(element instanceof IExpression) {\r
+ IExpression exp = (IExpression)element;\r
+ return exp.evaluate(environment);\r
+ } else {\r
+ return element;\r
+ }\r
+ } else {\r
+ if(element instanceof Array) {\r
+ return ((Array)element).subscript(environment, subscripts, position+1);\r
+ } else {\r
+ throw new IllegalStateException();\r
+ }\r
+ }\r
+ }\r
+ \r
+ }\r
+ \r
+ public Object subscript(IEnvironment environment, IExpression[] subscripts) {\r
+ return subscript(environment, subscripts, 0);\r
+ }\r
+\r
}\r
public Object evaluate(IEnvironment environment, int argc) {\r
Object value = environment.getValue(0);\r
if(value instanceof Double) {\r
- return ((Double)value).intValue();\r
+ double d = ((Double)value).intValue(); \r
+ return d;\r
} else if(value instanceof Array) {\r
return ((Array)value).copy(new Modifier() {\r
\r
@Override\r
public Object modify(Object o) {\r
if(o instanceof Double) {\r
- return ((Double)o).intValue();\r
+ double d = ((Double)o).intValue(); \r
+ return d;\r
} else {\r
throw new IllegalStateException();\r
}\r
ArrayList<Object> os = (ArrayList<Object>)os_;\r
for(Object o : os) {\r
VariableDeclaration decl = (VariableDeclaration)o;\r
- function.internals.add(decl);\r
+ if("input".equals(decl.direction)) function.inputs.add(decl);\r
+ else if ("output".equals(decl.direction)) function.outputs.add(decl);\r
+ else function.internals.add(decl);\r
}\r
}\r
}\r
VariableDeclaration decl = (VariableDeclaration)os_;\r
if("input".equals(decl.direction)) function.inputs.add(decl);\r
else if ("output".equals(decl.direction)) function.outputs.add(decl);\r
- else throw new IllegalStateException();\r
+ else function.internals.add(decl);\r
} else {\r
ArrayList<Object> os = (ArrayList<Object>)os_;\r
for(Object o : os) {\r
VariableDeclaration decl = (VariableDeclaration)o;\r
if("input".equals(decl.direction)) function.inputs.add(decl);\r
else if ("output".equals(decl.direction)) function.outputs.add(decl);\r
- else throw new IllegalStateException();\r
+ else function.internals.add(decl);\r
}\r
}\r
}\r
return result;\r
}\r
\r
- private boolean hasScalarSubscript(IExpression[] subscripts) {\r
- if(subscripts == null) return false;\r
- else return true;\r
- }\r
+// private boolean hasScalarSubscript(IExpression[] subscripts) {\r
+// if(subscripts == null) return false;\r
+// else return true;\r
+// }\r
\r
public int intoArray(IEnvironment env, int index, int d, Array target) {\r
\r
if(isStoredAsArray(environment)) {\r
\r
Array array = (Array)environment.getValue(index);\r
- if(hasScalarSubscript(subscripts)) {\r
- Object o = getArrayIndex(environment, subscripts, array);\r
- if(o instanceof Variable) throw new IllegalStateException();\r
- if(o instanceof Array)\r
- throw new IllegalStateException();\r
- return o;\r
+ if(subscripts != null) {\r
+ return array.subscript(environment, subscripts);\r
}\r
else return array;\r
\r