Check example code in.
authorbdemsky <bdemsky>
Thu, 1 Jun 2006 18:22:58 +0000 (18:22 +0000)
committerbdemsky <bdemsky>
Thu, 1 Jun 2006 18:22:58 +0000 (18:22 +0000)
Robust/src/Tests/TaskExample.java [new file with mode: 0644]

diff --git a/Robust/src/Tests/TaskExample.java b/Robust/src/Tests/TaskExample.java
new file mode 100644 (file)
index 0000000..dcaf950
--- /dev/null
@@ -0,0 +1,45 @@
+class Example {
+    flag needoperation;
+    flag needprinting;
+    
+    int operation;
+    int x;
+    int y;
+    int z;
+}
+
+/* Startup object is generated with the initialstate flag set by the
+ *  system to start the computation up */
+
+task Startup(StartupObject s {initialstate}) {
+    for(int i=0;i<10;i++) {
+       Example e=new Example() {needoperation};
+       e.x=i;
+       e.y=2;
+       e.operation=i%2;
+    }
+    
+    taskexit(s {!initialstate}); /* Turns initial state flag off, so this task won't refire */
+}
+
+/* Fails for x=1 */
+
+task DoOperation(Example e{needoperation}) {
+    e.z=10*e.y/(e.x-1);
+
+    if (e.operation==0)
+       /* Print the result */
+       taskexit(e {!needoperation, needprinting});
+    else
+       /* Don't print the result */
+       taskexit(e {!needoperation});
+}
+
+/* Note that we can write arbitrary boolean expressions for flag
+ * expressions.  For example, needprinting && ! needoperation would
+ * also be a legal flag expression */
+
+task DoPrint(Example e{needprinting}) {
+    System.printInt(e.z);
+    taskexit(e {!needprinting};
+}