From 4496b1ab302d5be8b337e9048dcdf6ba6ddda182 Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Sun, 1 Feb 2015 23:08:42 +0400 Subject: [PATCH] Add sample application to show how CPS generator works --- teavm-samples/pom.xml | 1 + teavm-samples/teavm-samples-async/.gitignore | 4 + teavm-samples/teavm-samples-async/pom.xml | 93 +++++++++++++++++++ .../org/teavm/samples/async/AsyncProgram.java | 59 ++++++++++++ .../src/main/webapp/WEB-INF/web.xml | 21 +++++ .../src/main/webapp/index.html | 27 ++++++ 6 files changed, 205 insertions(+) create mode 100644 teavm-samples/teavm-samples-async/.gitignore create mode 100644 teavm-samples/teavm-samples-async/pom.xml create mode 100644 teavm-samples/teavm-samples-async/src/main/java/org/teavm/samples/async/AsyncProgram.java create mode 100644 teavm-samples/teavm-samples-async/src/main/webapp/WEB-INF/web.xml create mode 100644 teavm-samples/teavm-samples-async/src/main/webapp/index.html diff --git a/teavm-samples/pom.xml b/teavm-samples/pom.xml index bcc56b08c..6513d89c4 100644 --- a/teavm-samples/pom.xml +++ b/teavm-samples/pom.xml @@ -34,5 +34,6 @@ teavm-samples-benchmark teavm-samples-storage teavm-samples-video + teavm-samples-async \ No newline at end of file diff --git a/teavm-samples/teavm-samples-async/.gitignore b/teavm-samples/teavm-samples-async/.gitignore new file mode 100644 index 000000000..c708c363d --- /dev/null +++ b/teavm-samples/teavm-samples-async/.gitignore @@ -0,0 +1,4 @@ +/target +/.settings +/.classpath +/.project diff --git a/teavm-samples/teavm-samples-async/pom.xml b/teavm-samples/teavm-samples-async/pom.xml new file mode 100644 index 000000000..b04494c1b --- /dev/null +++ b/teavm-samples/teavm-samples-async/pom.xml @@ -0,0 +1,93 @@ + + + 4.0.0 + + org.teavm + teavm-samples + 0.3.0-SNAPSHOT + + teavm-samples-async + + war + + TeaVM CPS demo + TeaVM application that demonstrates continuation-passing style generator + + + + org.teavm + teavm-classlib + ${project.version} + + + + + + + maven-war-plugin + 2.4 + + + + ${project.build.directory}/generated/js + + + + + + org.teavm + teavm-maven-plugin + ${project.version} + + + web-client + prepare-package + + build-javascript + + + ${project.build.directory}/generated/js/teavm + org.teavm.samples.async.AsyncProgram + SEPARATE + false + true + true + true + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + ../../checkstyle.xml + config_loc=${basedir}/../.. + + + + org.apache.maven.plugins + maven-source-plugin + + + org.apache.maven.plugins + maven-javadoc-plugin + + + + \ No newline at end of file diff --git a/teavm-samples/teavm-samples-async/src/main/java/org/teavm/samples/async/AsyncProgram.java b/teavm-samples/teavm-samples-async/src/main/java/org/teavm/samples/async/AsyncProgram.java new file mode 100644 index 000000000..fca37cc4a --- /dev/null +++ b/teavm-samples/teavm-samples-async/src/main/java/org/teavm/samples/async/AsyncProgram.java @@ -0,0 +1,59 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.samples.async; + +/** + * + * @author Alexey Andreev + */ +public final class AsyncProgram { + private AsyncProgram() { + } + + public static void main(String[] args) throws InterruptedException { + withoutAsync(); + System.out.println(); + withAsync(); + } + + private static void withoutAsync() { + System.out.println("Start sync"); + for (int i = 0; i < 20; ++i) { + for (int j = 0; j <= i; ++j) { + System.out.print(j); + System.out.print(' '); + } + System.out.println(); + } + System.out.println("Complete sync"); + } + + private static void withAsync() throws InterruptedException { + System.out.println("Start async"); + for (int i = 0; i < 20; ++i) { + for (int j = 0; j <= i; ++j) { + System.out.print(j); + System.out.print(' '); + } + System.out.println(); + if (i % 3 == 0) { + System.out.println("Suspend for a second"); + Thread.sleep(1000); + } + } + System.out.println("Complete async"); + } +} diff --git a/teavm-samples/teavm-samples-async/src/main/webapp/WEB-INF/web.xml b/teavm-samples/teavm-samples-async/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..6471cd77a --- /dev/null +++ b/teavm-samples/teavm-samples-async/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,21 @@ + + + + \ No newline at end of file diff --git a/teavm-samples/teavm-samples-async/src/main/webapp/index.html b/teavm-samples/teavm-samples-async/src/main/webapp/index.html new file mode 100644 index 000000000..96817c4a0 --- /dev/null +++ b/teavm-samples/teavm-samples-async/src/main/webapp/index.html @@ -0,0 +1,27 @@ + + + + + Continuation-passing style demo + + + + + +

Please, open developer's console to view program's output

+ + \ No newline at end of file