[Swift-commit] r2377 - in trunk: src/org/griphyn/vdl/karajan/lib src/org/griphyn/vdl/mapping tests/language-behaviour

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Tue Dec 16 17:31:37 CST 2008


Author: benc
Date: 2008-12-16 17:31:36 -0600 (Tue, 16 Dec 2008)
New Revision: 2377

Added:
   trunk/tests/language-behaviour/027-array-assignment.out.expected
   trunk/tests/language-behaviour/027-array-assignment.swift
   trunk/tests/language-behaviour/028-array-assignment.swift
   trunk/tests/language-behaviour/array_multidimensional_assign.swift
Modified:
   trunk/src/org/griphyn/vdl/karajan/lib/SetFieldValue.java
   trunk/src/org/griphyn/vdl/mapping/AbstractDataNode.java
Log:
makes it so you can assign arrays in SwiftScript in a similar way to assigning primitive values

Modified: trunk/src/org/griphyn/vdl/karajan/lib/SetFieldValue.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/SetFieldValue.java	2008-12-16 02:46:26 UTC (rev 2376)
+++ trunk/src/org/griphyn/vdl/karajan/lib/SetFieldValue.java	2008-12-16 23:31:36 UTC (rev 2377)
@@ -4,12 +4,16 @@
 package org.griphyn.vdl.karajan.lib;
 
 import org.apache.log4j.Logger;
+import org.griphyn.vdl.karajan.Pair;
+import org.griphyn.vdl.karajan.FuturePairIterator;
 import org.griphyn.vdl.karajan.PairIterator;
+import org.griphyn.vdl.karajan.VDL2FutureException;
 import org.globus.cog.karajan.arguments.Arg;
 import org.globus.cog.karajan.stack.VariableStack;
 import org.globus.cog.karajan.workflow.ExecutionException;
 import org.globus.cog.karajan.workflow.futures.FutureNotYetAvailable;
 import org.griphyn.vdl.mapping.DSHandle;
+import org.griphyn.vdl.mapping.InvalidPathException;
 import org.griphyn.vdl.mapping.Path;
 
 public class SetFieldValue extends VDLFunction {
@@ -30,24 +34,17 @@
 			if (logger.isInfoEnabled()) {
 				logger.info("Setting " + leaf + " to " + value);
 			}
-			synchronized (leaf) {
+			synchronized (var.getRoot()) {
 // TODO want to do a type check here, for runtime type checking
 // and pull out the appropriate internal value from value if it
 // is a DSHandle. There is no need (I think? maybe numerical casting?)
 // for type conversion here; but would be useful to have
 // type checking.
-				// leaf.setValue(internalValue(leaf.getType(), value));
-				if( (value instanceof DSHandle && ((DSHandle)value).getType().isArray()) || (value instanceof PairIterator)) {
-					logger.warn("Warning: array assignment outside of initialisation does not work correctly.");
-				} else {
-					synchronized(value.getRoot()) {
-						if (!value.isClosed()) {
-							throw new FutureNotYetAvailable(addFutureListener(stack,value));
-						} else {
-							leaf.setValue(value.getValue());
-							closeShallow(stack, leaf);
-						}
+				synchronized(value.getRoot()) {
+					if(!value.isClosed()) {
+						throw new FutureNotYetAvailable(addFutureListener(stack, value));
 					}
+					deepCopy(leaf,value,stack);
 				}
 			}
 			return null;
@@ -60,4 +57,31 @@
 		}
 	}
 
+	/** make dest look like source - if its a simple value, copy that
+	    and if its an array then recursively copy */
+	void deepCopy(DSHandle dest, DSHandle source, VariableStack stack) throws ExecutionException {
+		if(source.getType().isPrimitive()) {
+			dest.setValue(source.getValue());
+		} else if(source.getType().isArray()) {
+			PairIterator it = new PairIterator(source.getArrayValue());
+			while(it.hasNext()) {
+				Pair pair = (Pair) it.next();
+				Object lhs = pair.get(0);
+				DSHandle rhs = (DSHandle) pair.get(1);
+				Path memberPath = Path.EMPTY_PATH.addLast(String.valueOf(lhs),true);
+				DSHandle field;
+				try {
+					field = dest.getField(memberPath);
+				} catch(InvalidPathException ipe) {
+					throw new ExecutionException("Could not get destination field",ipe);
+				}
+				deepCopy(field,rhs,stack);
+			}
+			closeShallow(stack, dest);
+		} else {
+			// TODO implement this
+			throw new RuntimeException("Deep non-array structure copying not implemented");
+		}
+	}
+
 }

Modified: trunk/src/org/griphyn/vdl/mapping/AbstractDataNode.java
===================================================================
--- trunk/src/org/griphyn/vdl/mapping/AbstractDataNode.java	2008-12-16 02:46:26 UTC (rev 2376)
+++ trunk/src/org/griphyn/vdl/mapping/AbstractDataNode.java	2008-12-16 23:31:36 UTC (rev 2377)
@@ -303,6 +303,7 @@
 					+ " is already assigned with a value of " + this.value);
 		}
 		this.value = value;
+		closeShallow();
 	}
 
 	public Collection getFringePaths() throws HandleOpenException {

Added: trunk/tests/language-behaviour/027-array-assignment.out.expected
===================================================================
--- trunk/tests/language-behaviour/027-array-assignment.out.expected	                        (rev 0)
+++ trunk/tests/language-behaviour/027-array-assignment.out.expected	2008-12-16 23:31:36 UTC (rev 2377)
@@ -0,0 +1 @@
+two

Added: trunk/tests/language-behaviour/027-array-assignment.swift
===================================================================
--- trunk/tests/language-behaviour/027-array-assignment.swift	                        (rev 0)
+++ trunk/tests/language-behaviour/027-array-assignment.swift	2008-12-16 23:31:36 UTC (rev 2377)
@@ -0,0 +1,15 @@
+type messagefile {}
+
+(messagefile t) greeting(string m[]) {
+    app {
+        echo m[1] stdout=@filename(t);
+    }
+}
+
+messagefile outfile <"027-array-assignment.out">;
+
+string msg[];
+msg = [ "one", "two" ];
+
+outfile = greeting(msg);
+

Added: trunk/tests/language-behaviour/028-array-assignment.swift
===================================================================
--- trunk/tests/language-behaviour/028-array-assignment.swift	                        (rev 0)
+++ trunk/tests/language-behaviour/028-array-assignment.swift	2008-12-16 23:31:36 UTC (rev 2377)
@@ -0,0 +1,18 @@
+type messagefile {}
+
+(messagefile t) greeting(string m[]) {
+    app {
+        echo m[1] stdout=@filename(t);
+    }
+}
+
+messagefile outfile <"027-array-assignment.out">;
+
+string msg[];
+string baz[];
+
+baz = msg;
+msg = [ "one", "two" ];
+
+outfile = greeting(baz);
+

Added: trunk/tests/language-behaviour/array_multidimensional_assign.swift
===================================================================
--- trunk/tests/language-behaviour/array_multidimensional_assign.swift	                        (rev 0)
+++ trunk/tests/language-behaviour/array_multidimensional_assign.swift	2008-12-16 23:31:36 UTC (rev 2377)
@@ -0,0 +1,16 @@
+type file {}
+
+(file t) echo_array (string s[][]) {
+    app {
+        echo s[0][0] s[1][0] s[1][1] stdout=@filename(t);
+    }
+}
+
+string greetings[][];
+
+greetings = [ [ "left", "right" ], ["up", "down"]];
+
+file hw <"array_multidimensional_assign.out">;
+
+hw = echo_array(greetings);
+




More information about the Swift-commit mailing list