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

wozniak at ci.uchicago.edu wozniak at ci.uchicago.edu
Sat Oct 22 23:03:13 CDT 2011


Author: wozniak
Date: 2011-10-22 23:03:13 -0500 (Sat, 22 Oct 2011)
New Revision: 5258

Modified:
   trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Assert.java
   trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Fprintf.java
   trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Sprintf.java
Log:
New formatter %b (boolean); fixes for toString/getValue, PathParser


Modified: trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Assert.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Assert.java	2011-10-23 04:00:52 UTC (rev 5257)
+++ trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Assert.java	2011-10-23 04:03:13 UTC (rev 5258)
@@ -1,6 +1,6 @@
 package org.griphyn.vdl.karajan.lib.swiftscript;
 
-import org.apache.log4j.Logger;
+// import org.apache.log4j.Logger;
 import org.globus.cog.karajan.arguments.Arg;
 import org.globus.cog.karajan.stack.VariableStack;
 import org.globus.cog.karajan.workflow.ExecutionException;
@@ -16,8 +16,8 @@
  */
 public class Assert extends VDLFunction {
 
-    private static final Logger logger = 
-        Logger.getLogger(Assert.class);
+    //    private static final Logger logger = 
+    //    Logger.getLogger(Assert.class);
     
     static {
         setArguments(Assert.class, new Arg[] { Arg.VARGS });
@@ -31,7 +31,7 @@
         
         if (args.length == 2)
             if (args[1].getType() == Types.STRING)
-                message = args[1].toString();
+                message = (String) args[1].getValue();
             else
                 throw new ExecutionException
                 ("Second argument to assert() must be a String!");
@@ -50,8 +50,8 @@
                 success = false;
         }
         else if (value.getType() == Types.INT) {
-            double d = ((Double) value.getValue()).doubleValue();
-            if (d == 0.0)
+            double d = ((Integer) value.getValue()).intValue();
+            if (d == 0)
                 success = false;
         } 
         else 

Modified: trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Fprintf.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Fprintf.java	2011-10-23 04:00:52 UTC (rev 5257)
+++ trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Fprintf.java	2011-10-23 04:03:13 UTC (rev 5258)
@@ -39,8 +39,8 @@
         
         check(args);
         
-        String filename = args[0].toString();
-        String spec = args[1].toString(); 
+        String filename = (String) args[0].getValue();
+        String spec = (String) args[1].getValue(); 
         DSHandle[] vars = Sprintf.copyArray(args, 2, args.length-2);
         
         StringBuilder output = new StringBuilder();
@@ -59,10 +59,10 @@
             ("fprintf(): requires at least 2 arguments!");
         if (! args[0].getType().equals(Types.STRING))
             throw new ExecutionException
-            ("fprintf(): first argument is a string filename!");
+            ("fprintf(): first argument must be a string filename!");
         if (! args[0].getType().equals(Types.STRING))
             throw new ExecutionException
-            ("fprintf(): second argument is a string specifier!");
+            ("fprintf(): second argument must be a string specifier!");
     }
     
     private static void write(String filename, String msg) 

Modified: trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Sprintf.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Sprintf.java	2011-10-23 04:00:52 UTC (rev 5257)
+++ trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Sprintf.java	2011-10-23 04:03:13 UTC (rev 5258)
@@ -23,6 +23,7 @@
       %%: % sign. <br>
       %M: Filename output: waits for close
       %p: Not typechecked, output as in trace(). <br>
+      %b: Typechecked boolean output. <br>
       %f: Typechecked float output. <br>
       %i: Typechecked int output. <br>
       %s: Typechecked string output. <br>
@@ -119,6 +120,9 @@
         if (c == 'M') {
             append_M(vars[arg], output);
         }
+        else if (c == 'b') { 
+            append_b(vars[arg], output);
+        }
         else if (c == 'f') {
             append_f(vars[arg], output);
         }
@@ -161,6 +165,17 @@
         }
     }
     
+    private static void append_b(DSHandle arg, StringBuilder output) 
+    throws ExecutionException {
+        if (arg.getType() == Types.BOOLEAN) {
+            output.append(arg.getValue());
+        }
+        else {
+            throw new ExecutionException
+            ("tracef(): %b requires a boolean!");
+        }
+    }
+    
     private static void append_f(DSHandle arg, StringBuilder output) 
     throws ExecutionException {
         if (arg.getType() == Types.FLOAT) {
@@ -192,7 +207,7 @@
             try {
                 int size = node.size();
                 for (int i = 0; i < size; i++) {
-                    String entry = ""+i; 
+                    String entry = "["+i+"]"; 
                     DSHandle handle = 
                         node.getField(Path.parse(entry));
                     output.append(handle.getValue());




More information about the Swift-commit mailing list