diff --git a/examples/dynamic/README b/examples/dynamic/README index 4b8c397cc556dcf4158670c63eb8f765e47de45e..2895d7345f6a56f8944f3bde7af9e9bfb098afd5 100644 --- a/examples/dynamic/README +++ b/examples/dynamic/README @@ -1,9 +1,33 @@ This directory contains an embryo of an example of how to generate and compile a labcomm endpoint on the fly. -NB! There is currently no connection between the files StaticPart.java, DynamicPart.java, and -TestLabCommCompiler.java +NB! There is currently no connection to the StaticPart.java + +the runme.sh script builds and runs the TestLabCommGen, which illustrates the +on-the-fly compilation to RAM, reading the labcomm declarations and handlers from file + +The handlers declaration (in handlers.txt) is experimental, and has the following format: + +<sample name>:handler(<data type> <variable name>) { + <handler method code> +}### + +where the end marker (}###) is a kludge to avoid having to parse the method body while still allowing +it to contain blocks. Thus, having the sequence "}###" in the method body breaks this. Caveat hacker! + +An example handlers declaration: + +foo:handler(foo value) { + System.out.println("foo handler from handlers.txt"); + System.out.println(value.x); + System.out.println(value.y); + System.out.println(value.z); + for(int i=0; i<value.x; i++){ + System.out.print("."+(value.x-i)); + } + System.out.println(); +}### +bar:handler(int value) { + System.out.println(value); +}### -the runme.sh script builds and runs the TestLabCommCompiler, which illustrates the -on-the-fly compilation to RAM, reading the labcomm declarations from file but with the -handlers hard coded in the test program. diff --git a/examples/dynamic/TestLabcommGen.java b/examples/dynamic/TestLabcommGen.java index a028e3843e91d2bfd4a0d9cf864873dfe1927b19..c5b852aa66dc21bcf4209c8d19fe7baecfe17d8f 100644 --- a/examples/dynamic/TestLabcommGen.java +++ b/examples/dynamic/TestLabcommGen.java @@ -103,9 +103,9 @@ public class TestLabcommGen { } else { System.out.println("expeced handler decl:\n"+srcStr.substring(pos)); } - int bodyEnd = srcStr.indexOf('}', pos); // HERE BE DRAGONS! too brittle + int bodyEnd = srcStr.indexOf("}###", pos); // HERE BE DRAGONS! a bit brittle String body = srcStr.substring(pos, bodyEnd+1); - pos = bodyEnd+2; + pos = bodyEnd+5; // System.out.println("body:"); // System.out.println(body);