[Swift-commit] r6249 - in branches/faster/src/org/griphyn/vdl/karajan/lib: . swiftscript
hategan at ci.uchicago.edu
hategan at ci.uchicago.edu
Fri Feb 8 23:26:59 CST 2013
Author: hategan
Date: 2013-02-08 23:26:59 -0600 (Fri, 08 Feb 2013)
New Revision: 6249
Added:
branches/faster/src/org/griphyn/vdl/karajan/lib/SwiftBinaryOp.java
branches/faster/src/org/griphyn/vdl/karajan/lib/SwiftUnaryOp.java
Modified:
branches/faster/src/org/griphyn/vdl/karajan/lib/Operators.java
branches/faster/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java
Log:
fixed all operators to wait for handle value
Modified: branches/faster/src/org/griphyn/vdl/karajan/lib/Operators.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/lib/Operators.java 2013-02-09 05:26:03 UTC (rev 6248)
+++ branches/faster/src/org/griphyn/vdl/karajan/lib/Operators.java 2013-02-09 05:26:59 UTC (rev 6249)
@@ -22,8 +22,6 @@
import org.apache.log4j.Logger;
import org.globus.cog.karajan.compiled.nodes.Node;
-import org.globus.cog.karajan.compiled.nodes.functions.BinaryOp;
-import org.globus.cog.karajan.compiled.nodes.functions.UnaryOp;
import org.griphyn.vdl.mapping.AbstractDataNode;
import org.griphyn.vdl.mapping.DSHandle;
import org.griphyn.vdl.mapping.RootDataNode;
@@ -99,9 +97,9 @@
}
}
- public static class Sum extends BinaryOp<DSHandle, DSHandle> {
+ public static class Sum extends SwiftBinaryOp {
@Override
- protected DSHandle value(DSHandle v1, DSHandle v2) {
+ protected DSHandle value(AbstractDataNode v1, AbstractDataNode v2) {
Type t = type(v1, v2);
DSHandle r;
if (t == Types.STRING) {
@@ -118,9 +116,9 @@
}
}
- public static class Difference extends BinaryOp<DSHandle, DSHandle> {
+ public static class Difference extends SwiftBinaryOp {
@Override
- protected DSHandle value(DSHandle v1, DSHandle v2) {
+ protected DSHandle value(AbstractDataNode v1, AbstractDataNode v2) {
Type t = type(v1, v2);
DSHandle r;
if (t == Types.INT) {
@@ -134,9 +132,9 @@
}
}
- public static class Product extends BinaryOp<DSHandle, DSHandle> {
+ public static class Product extends SwiftBinaryOp {
@Override
- protected DSHandle value(DSHandle v1, DSHandle v2) {
+ protected DSHandle value(AbstractDataNode v1, AbstractDataNode v2) {
Type t = type(v1, v2);
DSHandle r;
if (t == Types.INT) {
@@ -150,9 +148,9 @@
}
}
- public static class FQuotient extends BinaryOp<DSHandle, DSHandle> {
+ public static class FQuotient extends SwiftBinaryOp {
@Override
- protected DSHandle value(DSHandle v1, DSHandle v2) {
+ protected DSHandle value(AbstractDataNode v1, AbstractDataNode v2) {
DSHandle r = new RootDataNode(Types.FLOAT, getFloat(this, v1) / getFloat(this, v2));
logBinaryProvenance("fquotient", v1, v2, r);
return r;
@@ -162,18 +160,18 @@
public static class Quotient extends FQuotient {
}
- public static class IQuotient extends BinaryOp<DSHandle, DSHandle> {
+ public static class IQuotient extends SwiftBinaryOp {
@Override
- protected DSHandle value(DSHandle v1, DSHandle v2) {
+ protected DSHandle value(AbstractDataNode v1, AbstractDataNode v2) {
DSHandle r = new RootDataNode(Types.INT, getInt(this, v1) / getInt(this, v2));
logBinaryProvenance("iquotient", v1, v2, r);
return r;
}
}
- public static class Remainder extends BinaryOp<DSHandle, DSHandle> {
+ public static class Remainder extends SwiftBinaryOp {
@Override
- protected DSHandle value(DSHandle v1, DSHandle v2) {
+ protected DSHandle value(AbstractDataNode v1, AbstractDataNode v2) {
Type t = type(v1, v2);
DSHandle r;
if (t == Types.INT) {
@@ -187,81 +185,81 @@
}
}
- public static class LE extends BinaryOp<DSHandle, DSHandle> {
+ public static class LE extends SwiftBinaryOp {
@Override
- protected DSHandle value(DSHandle v1, DSHandle v2) {
+ protected DSHandle value(AbstractDataNode v1, AbstractDataNode v2) {
DSHandle r = new RootDataNode(Types.BOOLEAN, getFloat(this, v1) <= getFloat(this, v2));
logBinaryProvenance("le", v1, v2, r);
return r;
}
}
- public static class GE extends BinaryOp<DSHandle, DSHandle> {
+ public static class GE extends SwiftBinaryOp {
@Override
- protected DSHandle value(DSHandle v1, DSHandle v2) {
+ protected DSHandle value(AbstractDataNode v1, AbstractDataNode v2) {
DSHandle r = new RootDataNode(Types.BOOLEAN, getFloat(this, v1) >= getFloat(this, v2));
logBinaryProvenance("ge", v1, v2, r);
return r;
}
}
- public static class LT extends BinaryOp<DSHandle, DSHandle> {
+ public static class LT extends SwiftBinaryOp {
@Override
- protected DSHandle value(DSHandle v1, DSHandle v2) {
+ protected DSHandle value(AbstractDataNode v1, AbstractDataNode v2) {
DSHandle r = new RootDataNode(Types.BOOLEAN, getFloat(this, v1) < getFloat(this, v2));
logBinaryProvenance("lt", v1, v2, r);
return r;
}
}
- public static class GT extends BinaryOp<DSHandle, DSHandle> {
+ public static class GT extends SwiftBinaryOp {
@Override
- protected DSHandle value(DSHandle v1, DSHandle v2) {
+ protected DSHandle value(AbstractDataNode v1, AbstractDataNode v2) {
DSHandle r = new RootDataNode(Types.BOOLEAN, getFloat(this, v1) > getFloat(this, v2));
logBinaryProvenance("gt", v1, v2, r);
return r;
}
}
- public static class EQ extends BinaryOp<DSHandle, DSHandle> {
+ public static class EQ extends SwiftBinaryOp {
@Override
- protected DSHandle value(DSHandle v1, DSHandle v2) {
+ protected DSHandle value(AbstractDataNode v1, AbstractDataNode v2) {
DSHandle r = new RootDataNode(Types.BOOLEAN, v1.getValue().equals(v2.getValue()));
logBinaryProvenance("eq", v1, v2, r);
return r;
}
}
- public static class NE extends BinaryOp<DSHandle, DSHandle> {
+ public static class NE extends SwiftBinaryOp {
@Override
- protected DSHandle value(DSHandle v1, DSHandle v2) {
+ protected DSHandle value(AbstractDataNode v1, AbstractDataNode v2) {
DSHandle r = new RootDataNode(Types.BOOLEAN, !v1.getValue().equals(v2.getValue()));
logBinaryProvenance("ne", v1, v2, r);
return r;
}
}
- public static class And extends BinaryOp<DSHandle, DSHandle> {
+ public static class And extends SwiftBinaryOp {
@Override
- protected DSHandle value(DSHandle v1, DSHandle v2) {
+ protected DSHandle value(AbstractDataNode v1, AbstractDataNode v2) {
DSHandle r = new RootDataNode(Types.BOOLEAN, getBool(this, v1) && getBool(this, v2));
logBinaryProvenance("and", v1, v2, r);
return r;
}
}
- public static class Or extends BinaryOp<DSHandle, DSHandle> {
+ public static class Or extends SwiftBinaryOp {
@Override
- protected DSHandle value(DSHandle v1, DSHandle v2) {
+ protected DSHandle value(AbstractDataNode v1, AbstractDataNode v2) {
DSHandle r = new RootDataNode(Types.BOOLEAN, getBool(this, v1) || getBool(this, v2));
logBinaryProvenance("or", v1, v2, r);
return r;
}
}
- public static class Not extends UnaryOp<DSHandle, DSHandle> {
+ public static class Not extends SwiftUnaryOp {
@Override
- protected DSHandle value(DSHandle v) {
+ protected DSHandle value(AbstractDataNode v) {
DSHandle r = new RootDataNode(Types.BOOLEAN, !getBool(this, v));
logUnaryProvenance("not", v, r);
return r;
Added: branches/faster/src/org/griphyn/vdl/karajan/lib/SwiftBinaryOp.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/lib/SwiftBinaryOp.java (rev 0)
+++ branches/faster/src/org/griphyn/vdl/karajan/lib/SwiftBinaryOp.java 2013-02-09 05:26:59 UTC (rev 6249)
@@ -0,0 +1,28 @@
+//----------------------------------------------------------------------
+//This code is developed as part of the Java CoG Kit project
+//The terms of the license can be found at http://www.cogkit.org/license
+//This message may not be removed or altered.
+//----------------------------------------------------------------------
+
+/*
+ * Created on Feb 4, 2013
+ */
+package org.griphyn.vdl.karajan.lib;
+
+import k.rt.Stack;
+
+import org.globus.cog.karajan.compiled.nodes.functions.BinaryOp;
+import org.griphyn.vdl.mapping.AbstractDataNode;
+import org.griphyn.vdl.mapping.DSHandle;
+
+public abstract class SwiftBinaryOp extends BinaryOp<AbstractDataNode, DSHandle> {
+
+ @Override
+ public DSHandle function(Stack stack) {
+ AbstractDataNode v1 = this.v1.getValue(stack);
+ v1.waitFor(this);
+ AbstractDataNode v2 = this.v2.getValue(stack);
+ v2.waitFor(this);
+ return value(v1, v2);
+ }
+}
Added: branches/faster/src/org/griphyn/vdl/karajan/lib/SwiftUnaryOp.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/lib/SwiftUnaryOp.java (rev 0)
+++ branches/faster/src/org/griphyn/vdl/karajan/lib/SwiftUnaryOp.java 2013-02-09 05:26:59 UTC (rev 6249)
@@ -0,0 +1,26 @@
+//----------------------------------------------------------------------
+//This code is developed as part of the Java CoG Kit project
+//The terms of the license can be found at http://www.cogkit.org/license
+//This message may not be removed or altered.
+//----------------------------------------------------------------------
+
+/*
+ * Created on Feb 4, 2013
+ */
+package org.griphyn.vdl.karajan.lib;
+
+import k.rt.Stack;
+
+import org.globus.cog.karajan.compiled.nodes.functions.UnaryOp;
+import org.griphyn.vdl.mapping.AbstractDataNode;
+import org.griphyn.vdl.mapping.DSHandle;
+
+public abstract class SwiftUnaryOp extends UnaryOp<AbstractDataNode, DSHandle> {
+
+ @Override
+ public DSHandle function(Stack stack) {
+ AbstractDataNode v1 = this.v1.getValue(stack);
+ v1.waitFor(this);
+ return value(v1);
+ }
+}
Modified: branches/faster/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java 2013-02-09 05:26:03 UTC (rev 6248)
+++ branches/faster/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java 2013-02-09 05:26:59 UTC (rev 6249)
@@ -326,7 +326,7 @@
@Override
protected Signature getSignature() {
- return new Signature(params("array", optional("delim", new RootDataNode(Types.STRING, ", "))));
+ return new Signature(params("array", "delim"));
}
@Override
@@ -419,7 +419,7 @@
@Override
protected Signature getSignature() {
- return new Signature(params("str"));
+ return new Signature(params("str"), returns(channel("...", 1)));
}
@Override
@@ -450,9 +450,20 @@
@Override
public Object function(Stack stack) {
AbstractDataNode hstr = str.getValue(stack);
- String str = SwiftFunction.unwrap(this, hstr);
+ Object obj = SwiftFunction.unwrap(this, hstr);
- DSHandle handle = new RootDataNode(Types.FLOAT, Double.valueOf(str));
+ DSHandle handle;
+
+ if (obj instanceof String) {
+ handle = new RootDataNode(Types.FLOAT, Double.valueOf((String) obj));
+ }
+ else if (obj instanceof Number) {
+ handle = new RootDataNode(Types.FLOAT, ((Number) obj).doubleValue());
+ }
+ else {
+ throw new ExecutionException("Expected a string or int. Got " + obj);
+ }
+
if (PROVENANCE_ENABLED) {
int provid = SwiftFunction.nextProvenanceID();
More information about the Swift-commit
mailing list