[Swift-commit] r5859 - trunk/src/org/griphyn/vdl/karajan/lib

hategan at ci.uchicago.edu hategan at ci.uchicago.edu
Thu Jul 19 00:59:03 CDT 2012


Author: hategan
Date: 2012-07-19 00:59:03 -0500 (Thu, 19 Jul 2012)
New Revision: 5859

Modified:
   trunk/src/org/griphyn/vdl/karajan/lib/SetFieldValue.java
Log:
fix file copying in assignment

Modified: trunk/src/org/griphyn/vdl/karajan/lib/SetFieldValue.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/SetFieldValue.java	2012-07-19 05:57:58 UTC (rev 5858)
+++ trunk/src/org/griphyn/vdl/karajan/lib/SetFieldValue.java	2012-07-19 05:59:03 UTC (rev 5859)
@@ -72,7 +72,6 @@
             // type checking.
 			
    			deepCopy(leaf, value, stack, 0);
-			
 			return null;
 		}
 		catch (FutureFault f) {
@@ -181,10 +180,21 @@
         }
     }
 
+    @SuppressWarnings("unchecked")
     private static void copyStructure(DSHandle dest, DSHandle source,
             VariableStack stack, int level) throws ExecutionException {
         Type type = dest.getType();
-        for (String fname : type.getFieldNames()) {
+        Iterator<String> fni = (Iterator<String>) stack.currentFrame().getVar("it" + level);
+        if (fni == null) {
+            fni = type.getFieldNames().iterator();
+            stack.currentFrame().setVar("it" + level, fni);
+        }
+        String fname = (String) stack.currentFrame().getVar("f" + level);
+        while (fni.hasNext() || fname != null) {
+            if (fname == null) {
+                fname = fni.next();
+                stack.currentFrame().setVar("f" + level, fname);
+            }
             Path fpath = Path.EMPTY_PATH.addFirst(fname);
             try {
                 DSHandle dstf = dest.getField(fpath);
@@ -200,7 +210,11 @@
                 throw new ExecutionException("Internal type inconsistency detected. " + 
                     dest + " claims not to have a " + fname + " field");
             }
+            stack.currentFrame().deleteVar("f" + level);
+            fname = null;
         }
+        stack.currentFrame().deleteVar("it" + level);
+        dest.closeShallow();
     }
 
     private static void copyNonComposite(DSHandle dest, DSHandle source,
@@ -216,7 +230,7 @@
         }
         else {
             if (stack.currentFrame().isDefined("fc")) {
-                FileCopier fc = (FileCopier) stack.currentFrame().getVar("fc");
+                FileCopier fc = (FileCopier) stack.currentFrame().getVarAndDelete("fc");
                 if (!fc.isClosed()) {
                     throw new FutureNotYetAvailable(fc);
                 }
@@ -252,8 +266,12 @@
             it = new PairIterator(source.getArrayValue());
             stack.setVar("it" + level, it);
         }
-        while (it.hasNext()) {
-            Pair pair = (Pair) it.next();
+        Pair pair = (Pair) stack.currentFrame().getVar("p" + level);
+        while (it.hasNext() || pair != null) {
+            if (pair == null) {
+                pair = (Pair) it.next();
+                stack.currentFrame().setVar("p" + level, pair);
+            }
             Comparable<?> lhs = (Comparable<?>) pair.get(0);
             DSHandle rhs = (DSHandle) pair.get(1);
             Path memberPath = Path.EMPTY_PATH.addLast(lhs, true);
@@ -266,6 +284,8 @@
                 throw new ExecutionException("Could not get destination field",ipe);
             }
             deepCopy(field, rhs, stack, level + 1);
+            stack.currentFrame().deleteVar("p" + level);
+            pair = null;
         }
         stack.currentFrame().deleteVar("it" + level);
         dest.closeShallow();




More information about the Swift-commit mailing list