[Swift-commit] r4774 - in trunk: resources src/org/griphyn/vdl/karajan/lib src/org/griphyn/vdl/mapping
hategan at ci.uchicago.edu
hategan at ci.uchicago.edu
Tue Jul 5 15:41:06 CDT 2011
Author: hategan
Date: 2011-07-05 15:41:06 -0500 (Tue, 05 Jul 2011)
New Revision: 4774
Modified:
trunk/resources/Karajan.stg
trunk/src/org/griphyn/vdl/karajan/lib/InfiniteCountingWhile.java
trunk/src/org/griphyn/vdl/mapping/RootDataNode.java
Log:
fixed iterate to conform better to what one would expect from it
Modified: trunk/resources/Karajan.stg
===================================================================
--- trunk/resources/Karajan.stg 2011-07-05 20:40:07 UTC (rev 4773)
+++ trunk/resources/Karajan.stg 2011-07-05 20:41:06 UTC (rev 4774)
@@ -186,13 +186,7 @@
iterate(declarations,statements,cond,var,cleanups) ::= <<
-<vdl:infinitecountingwhile>
- <set names="\$\$">
- <each items="{\$}"/>
- </set>
- <set name="$var$">
- <vdl:new type="int" value="{\$\$}" />
- </set>
+<vdl:infinitecountingwhile var="$var$">
$sub_comp(declarations=declarations, statements=statements, cleanups=cleanups)$
<sys:if>
<vdl:getfieldvalue>$cond$</vdl:getfieldvalue>
Modified: trunk/src/org/griphyn/vdl/karajan/lib/InfiniteCountingWhile.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/InfiniteCountingWhile.java 2011-07-05 20:40:07 UTC (rev 4773)
+++ trunk/src/org/griphyn/vdl/karajan/lib/InfiniteCountingWhile.java 2011-07-05 20:41:06 UTC (rev 4774)
@@ -6,33 +6,34 @@
package org.griphyn.vdl.karajan.lib;
-import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
+import org.globus.cog.karajan.arguments.Arg;
import org.globus.cog.karajan.stack.VariableStack;
import org.globus.cog.karajan.util.ThreadingContext;
-import org.globus.cog.karajan.util.TypeUtil;
-import org.globus.cog.karajan.workflow.Condition;
import org.globus.cog.karajan.workflow.ExecutionException;
import org.globus.cog.karajan.workflow.nodes.FlowElement;
import org.globus.cog.karajan.workflow.nodes.Sequential;
import org.globus.cog.karajan.workflow.nodes.While;
+import org.griphyn.vdl.mapping.RootDataNode;
+import org.griphyn.vdl.type.Types;
public class InfiniteCountingWhile extends Sequential {
- public static final String VAR = "##infinitecountingwhile:var";
+
+ public static final String COUNTER_NAME = "$";
+ public static final Arg.Positional VAR = new Arg.Positional("var");
public InfiniteCountingWhile() {
setOptimize(false);
}
public void pre(VariableStack stack) throws ExecutionException {
- stack.setVar("#condition", new Condition());
ThreadingContext tc = (ThreadingContext)stack.getVar("#thread");
stack.setVar("#iteratethread", tc);
stack.setVar("#thread", tc.split(0));
- stack.setVar(VAR, "$");
- String counterName = (String)stack.getVar(VAR);
- stack.setVar(counterName, Arrays.asList(new Integer[] {new Integer(0)}));
+ stack.setVar(COUNTER_NAME, Collections.singletonList(0));
+ stack.setVar((String) VAR.getStatic(this), new RootDataNode(Types.INT, 0.0));
super.pre(stack);
}
@@ -48,28 +49,23 @@
}
FlowElement fn = null;
- Condition condition = (Condition) stack.getVar("#condition");
- if (condition.getValue() != null) {
- boolean cond = TypeUtil.toBoolean(condition.getValue());
- if (!cond) {
- post(stack);
- return;
- }
+ if (index == elementCount() - 1) {
+ // the condition is always compiled as the last thing in the loop
+ // but the increment needs to happen before the condition is
+ // evaluated
+ @SuppressWarnings("unchecked")
+ List<Integer> c = (List<Integer>) stack.getVar(COUNTER_NAME);
+ int i = c.get(0).intValue();
+ i++;
+ ThreadingContext tc = (ThreadingContext)stack.getVar("#iteratethread");
+ stack.setVar("#thread", tc.split(i));
+ stack.setVar(COUNTER_NAME, Collections.singletonList(i));
+ stack.setVar((String) VAR.getStatic(this), new RootDataNode(Types.INT, Double.valueOf(i)));
}
if (index >= elementCount()) {
// starting new iteration
setIndex(stack, 1);
fn = getElement(0);
-
- String counterName = (String) stack.getVar(VAR);
- @SuppressWarnings("unchecked")
- List<Integer> l = (List<Integer>) stack.getVar(counterName);
- Integer wrappedi = l.get(0);
- int i = wrappedi.intValue();
- i++;
- ThreadingContext tc = (ThreadingContext)stack.getVar("#iteratethread");
- stack.setVar("#thread", tc.split(i));
- stack.setVar(counterName, Arrays.asList(new Integer[] {new Integer(i)}));
}
else {
fn = getElement(index++);
Modified: trunk/src/org/griphyn/vdl/mapping/RootDataNode.java
===================================================================
--- trunk/src/org/griphyn/vdl/mapping/RootDataNode.java 2011-07-05 20:40:07 UTC (rev 4773)
+++ trunk/src/org/griphyn/vdl/mapping/RootDataNode.java 2011-07-05 20:41:06 UTC (rev 4774)
@@ -33,6 +33,11 @@
public RootDataNode(Type type) {
super(Field.Factory.createField(null, type));
}
+
+ public RootDataNode(Type type, Object value) {
+ this(type);
+ setValue(value);
+ }
public void init(Map<String,Object> params) {
this.params = params;
More information about the Swift-commit
mailing list