From 60175168ede43fff58accc2f5f8cb6981b3e1b13 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Thu, 1 Jun 2006 18:22:58 +0000 Subject: [PATCH] Check example code in. --- Robust/src/Tests/TaskExample.java | 45 +++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Robust/src/Tests/TaskExample.java 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}; +} -- 2.34.1