[Swift-commit] r7262 - in trunk/src: . org/griphyn/vdl/engine org/griphyn/vdl/karajan/lib/swiftscript
hategan at ci.uchicago.edu
hategan at ci.uchicago.edu
Fri Nov 1 02:43:37 CDT 2013
Author: hategan
Date: 2013-11-01 02:43:35 -0500 (Fri, 01 Nov 2013)
New Revision: 7262
Modified:
trunk/src/
trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java
trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java
Log:
changed format function to format(spec, ...), implementing exactly what java.lang.String.format implements; the previous version, I did not understand what it did or why
Property changes on: trunk/src
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/release-0.94/src:6283-6619,6999-7001
/trunk/src:6214,6255,6275-6618
+ /branches/release-0.94/src:6283-6619,6999-7001,7125
/trunk/src:6214,6255,6275-6618
Modified: trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java
===================================================================
--- trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java 2013-11-01 00:15:48 UTC (rev 7261)
+++ trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java 2013-11-01 07:43:35 UTC (rev 7262)
@@ -202,7 +202,7 @@
add(functionsMap, "toFloat", returns(FLOAT), args(ANY));
add(functionsMap, "toString", returns(STRING), args(ANY));
- add(functionsMap, "format", returns(STRING), args(FLOAT, INT));
+ add(functionsMap, "format", returns(STRING), args(VARGS));
add(functionsMap, "pad", returns(STRING), args(INT, INT));
add(functionsMap, "java", returns(ANY), args(VARGS));
Modified: trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java 2013-11-01 00:15:48 UTC (rev 7261)
+++ trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java 2013-11-01 07:43:35 UTC (rev 7262)
@@ -477,29 +477,30 @@
* Takes in a float and formats to desired precision and returns a string
*/
public static class Format extends AbstractSingleValuedFunction {
- private ArgRef<AbstractDataNode> format;
- private ArgRef<AbstractDataNode> value;
+ private ChannelRef<AbstractDataNode> c_vargs;
@Override
protected Signature getSignature() {
- return new Signature(params("format", "value"));
+ return new Signature(params("..."));
}
@Override
public Object function(Stack stack) {
- AbstractDataNode hformat = this.format.getValue(stack);
- String format = SwiftFunction.unwrap(this, hformat);
- AbstractDataNode hvalue = this.value.getValue(stack);
- Double value = SwiftFunction.unwrap(this, hvalue);
+ Channel<AbstractDataNode> vargs = c_vargs.get(stack);
+ Channel<Object> args = SwiftFunction.unwrapAll(this, vargs);
- DSHandle handle = new RootDataNode(Types.STRING,
- String.format("%." + format + "f", value));
+ if (args.size() == 0) {
+ throw new ExecutionException(this, "Missing format specification");
+ }
+
+ String format = (String) args.get(0);
+ Object[] a = args.subChannel(1).toArray();
+
+ DSHandle handle = new RootDataNode(Types.STRING, String.format(format, a));
if (PROVENANCE_ENABLED) {
int provid = SwiftFunction.nextProvenanceID();
SwiftFunction.logProvenanceResult(provid, handle, "format");
- SwiftFunction.logProvenanceParameter(provid, hformat, "format");
- SwiftFunction.logProvenanceParameter(provid, hvalue, "value");
}
return handle;
}
More information about the Swift-commit
mailing list