[Swift-commit] r3431 - in trunk: libexec resources src/org/griphyn/vdl/engine src/org/griphyn/vdl/karajan/lib/swiftscript

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Sat Jul 10 22:38:07 CDT 2010


Author: jonmon
Date: 2010-07-10 22:38:07 -0500 (Sat, 10 Jul 2010)
New Revision: 3431

Modified:
   trunk/libexec/vdl-lib.xml
   trunk/resources/swiftscript.g
   trunk/src/org/griphyn/vdl/engine/Karajan.java
   trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java
   trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java
Log:
o src/org/griphyn/vdl/engine/Karajan.java
o resources/swiftscript.g
  -- Modifications to allow the import directive to accept a relative or absolute path to the script being imported.

o src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java
o src/org/griphyn/vdl/engine/ProcedureSignature.java
o libexec/vdl-lib.xml
  -- Added tofloat function. Takes in a string and converts the string to a floating point type.
  -- Added %f to tracef. This allows tracef to print out the floating point type.
  -- Fixed toint function. When a floating type string representation was passed to toint, the value was not truncated, an error was thrown instead.



Modified: trunk/libexec/vdl-lib.xml
===================================================================
--- trunk/libexec/vdl-lib.xml	2010-07-08 02:19:22 UTC (rev 3430)
+++ trunk/libexec/vdl-lib.xml	2010-07-11 03:38:07 UTC (rev 3431)
@@ -12,6 +12,7 @@
 	<export name="strsplit"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
 	<export name="regexp"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
 	<export name="toint"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
+	<export name="tofloat"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
 	<export name="tostring"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
 	<export name="trace"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
 	<export name="tracef"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>

Modified: trunk/resources/swiftscript.g
===================================================================
--- trunk/resources/swiftscript.g	2010-07-08 02:19:22 UTC (rev 3430)
+++ trunk/resources/swiftscript.g	2010-07-11 03:38:07 UTC (rev 3431)
@@ -78,7 +78,7 @@
     ;
 
 importStatement [StringTemplate code]
-    : "import" name:ID SEMI {
+    : "import" name:STRING_LITERAL SEMI {
         StringTemplate i = template("import");
         i.setAttribute("target", name.getText());
         code.setAttribute("imports", i);

Modified: trunk/src/org/griphyn/vdl/engine/Karajan.java
===================================================================
--- trunk/src/org/griphyn/vdl/engine/Karajan.java	2010-07-08 02:19:22 UTC (rev 3430)
+++ trunk/src/org/griphyn/vdl/engine/Karajan.java	2010-07-11 03:38:07 UTC (rev 3431)
@@ -155,19 +155,20 @@
 		Imports imports = prog.getImports();
 		if(imports!=null) {
 			logger.debug("Processing SwiftScript imports");
-// process imports in reverse order
+            // process imports in reverse order
 			for(int i = imports.sizeOfImportArray() - 1 ;  i >=0 ; i--) {
 				String moduleToImport = imports.getImportArray(i);
 				logger.debug("Importing module "+moduleToImport);
 				if(!importedNames.contains(moduleToImport)) {
 
 					// TODO PATH/PERL5LIB-style path handling
-					String swiftfilename = "./"+moduleToImport+".swift";
-					String xmlfilename = "./"+moduleToImport+".xml";
+					//String swiftfilename = "./"+moduleToImport+".swift";
+					//String xmlfilename = "./"+moduleToImport+".xml";
+					String swiftfilename = moduleToImport+".swift";
+					String xmlfilename = moduleToImport+".xml";
 
-
 					try {
-        	    				VDLt2VDLx.compile(new FileInputStream(swiftfilename),new PrintStream(new FileOutputStream(xmlfilename)));
+        	    		VDLt2VDLx.compile(new FileInputStream(swiftfilename),new PrintStream(new FileOutputStream(xmlfilename)));
 						logger.debug("Compiled. Now reading in compiled XML for "+moduleToImport);
 						Program importedProgram = parseProgramXML(xmlfilename).getProgram();
 						logger.debug("Read in compiled XML for "+moduleToImport);

Modified: trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java
===================================================================
--- trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java	2010-07-08 02:19:22 UTC (rev 3430)
+++ trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java	2010-07-11 03:38:07 UTC (rev 3431)
@@ -188,7 +188,7 @@
 		filenames.addOutputArg(filenamesOut1);
 		functionsMap.put(filenames.getName(), filenames);
 
-                ProcedureSignature dirname = new ProcedureSignature("dirname");
+        ProcedureSignature dirname = new ProcedureSignature("dirname");
 		FormalArgumentSignature dirnameIn1 = new FormalArgumentSignature(true); /* dir can be specified as any type */
 		dirname.addInputArg(dirnameIn1);
 		FormalArgumentSignature dirnameOut1 = new FormalArgumentSignature("string");
@@ -245,6 +245,13 @@
 		FormalArgumentSignature toOut1 = new FormalArgumentSignature("int");
 		toint.addOutputArg(toOut1);
 		functionsMap.put(toint.getName(), toint);
+
+		ProcedureSignature tofloat = new ProcedureSignature("tofloat");
+		FormalArgumentSignature tofloatIn1 = new FormalArgumentSignature("string");
+		tofloat.addInputArg(tofloatIn1);
+		FormalArgumentSignature tofloatOut1 = new FormalArgumentSignature("float");
+		tofloat.addOutputArg(tofloatOut1);
+		functionsMap.put(tofloat.getName(), tofloat);
 		
 		ProcedureSignature tostring = new ProcedureSignature("tostring");
 		FormalArgumentSignature tostringIn1 = new FormalArgumentSignature(true);

Modified: trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java	2010-07-08 02:19:22 UTC (rev 3430)
+++ trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java	2010-07-11 03:38:07 UTC (rev 3431)
@@ -41,10 +41,11 @@
 		setArguments("swiftscript_tracef", new Arg[] { Arg.VARGS });
 		setArguments("swiftscript_strcat", new Arg[] { Arg.VARGS });
 		setArguments("swiftscript_strcut", new Arg[] { PA_INPUT, PA_PATTERN });
-                setArguments("swiftscript_strstr", new Arg[] { PA_INPUT, PA_PATTERN });
+        setArguments("swiftscript_strstr", new Arg[] { PA_INPUT, PA_PATTERN });
 		setArguments("swiftscript_strsplit", new Arg[] { PA_INPUT, PA_PATTERN });
 		setArguments("swiftscript_regexp", new Arg[] { PA_INPUT, PA_PATTERN, PA_TRANSFORM });
 		setArguments("swiftscript_toint", new Arg[] { PA_INPUT });
+		setArguments("swiftscript_tofloat", new Arg[] { PA_INPUT });
 		setArguments("swiftscript_tostring", new Arg[] { PA_INPUT });
                 setArguments("swiftscript_dirname", new Arg[] { Arg.VARGS });
 	}
@@ -171,6 +172,14 @@
 	        else {
 	            throw new ExecutionException("tracef(): %i requires an int!");
 	        }
+        }
+	    else if (c == 'f') {
+	        if (args[arg].getType() == Types.FLOAT) {
+	            output.append(args[arg]).toString();
+	        }
+	        else {
+	            throw new ExecutionException("tracef(): %f requires a float!");
+	        }
 	    }
 	    else if (c == 'q') {
 	        if (args[arg] instanceof ArrayDataNode) {
@@ -358,6 +367,11 @@
 	public DSHandle swiftscript_toint(VariableStack stack) throws ExecutionException, NoSuchTypeException,
 			InvalidPathException {
 		String inputString = TypeUtil.toString(PA_INPUT.getValue(stack));
+		int i = inputString.indexOf(".");
+		if( i >= 0 )
+		{
+			inputString = inputString.substring(0, i);
+		}
 		DSHandle handle = new RootDataNode(Types.INT);
 		handle.setValue(new Double(Integer.parseInt(inputString)));
 		handle.closeShallow();
@@ -366,6 +380,18 @@
 		VDLFunction.logProvenanceParameter(provid, PA_INPUT.getRawValue(stack), "string");
 		return handle;
 	}
+
+	public DSHandle swiftscript_tofloat(VariableStack stack) throws ExecutionException, NoSuchTypeException,
+			InvalidPathException {
+		String inputString = TypeUtil.toString(PA_INPUT.getValue(stack));
+		DSHandle handle = new RootDataNode(Types.FLOAT);
+		handle.setValue(new Double(inputString));
+		handle.closeShallow();
+		int provid=VDLFunction.nextProvenanceID();
+		VDLFunction.logProvenanceResult(provid, handle, "tofloat");
+		VDLFunction.logProvenanceParameter(provid, PA_INPUT.getRawValue(stack), "string");
+		return handle;
+	}
 	
 	public DSHandle swiftscript_tostring(VariableStack stack)
                 throws ExecutionException, NoSuchTypeException,




More information about the Swift-commit mailing list