From: bdemsky Date: Thu, 1 Jun 2006 18:22:58 +0000 (+0000) Subject: Check example code in. X-Git-Tag: preEdgeChange~874 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=60175168ede43fff58accc2f5f8cb6981b3e1b13;p=IRC.git Check example code in. --- diff --git a/Robust/src/Tests/TaskExample.java b/Robust/src/Tests/TaskExample.java new file mode 100644 index 00000000..dcaf9506 --- /dev/null +++ b/Robust/src/Tests/TaskExample.java @@ -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}; +}