mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Add sample application to show how CPS generator works
This commit is contained in:
parent
071f2bb46c
commit
4496b1ab30
|
@ -34,5 +34,6 @@
|
|||
<module>teavm-samples-benchmark</module>
|
||||
<module>teavm-samples-storage</module>
|
||||
<module>teavm-samples-video</module>
|
||||
<module>teavm-samples-async</module>
|
||||
</modules>
|
||||
</project>
|
4
teavm-samples/teavm-samples-async/.gitignore
vendored
Normal file
4
teavm-samples/teavm-samples-async/.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
/target
|
||||
/.settings
|
||||
/.classpath
|
||||
/.project
|
93
teavm-samples/teavm-samples-async/pom.xml
Normal file
93
teavm-samples/teavm-samples-async/pom.xml
Normal file
|
@ -0,0 +1,93 @@
|
|||
<!--
|
||||
Copyright 2014 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.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.teavm</groupId>
|
||||
<artifactId>teavm-samples</artifactId>
|
||||
<version>0.3.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>teavm-samples-async</artifactId>
|
||||
|
||||
<packaging>war</packaging>
|
||||
|
||||
<name>TeaVM CPS demo</name>
|
||||
<description>TeaVM application that demonstrates continuation-passing style generator</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.teavm</groupId>
|
||||
<artifactId>teavm-classlib</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<configuration>
|
||||
<webResources>
|
||||
<resource>
|
||||
<directory>${project.build.directory}/generated/js</directory>
|
||||
</resource>
|
||||
</webResources>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.teavm</groupId>
|
||||
<artifactId>teavm-maven-plugin</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>web-client</id>
|
||||
<phase>prepare-package</phase>
|
||||
<goals>
|
||||
<goal>build-javascript</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory>
|
||||
<mainClass>org.teavm.samples.async.AsyncProgram</mainClass>
|
||||
<runtime>SEPARATE</runtime>
|
||||
<minifying>false</minifying>
|
||||
<debugInformationGenerated>true</debugInformationGenerated>
|
||||
<sourceMapsGenerated>true</sourceMapsGenerated>
|
||||
<sourceFilesCopied>true</sourceFilesCopied>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<configuration>
|
||||
<configLocation>../../checkstyle.xml</configLocation>
|
||||
<propertyExpansion>config_loc=${basedir}/../..</propertyExpansion>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -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 <konsoletyper@gmail.com>
|
||||
*/
|
||||
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");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
|
||||
version="3.0">
|
||||
</web-app>
|
27
teavm-samples/teavm-samples-async/src/main/webapp/index.html
Normal file
27
teavm-samples/teavm-samples-async/src/main/webapp/index.html
Normal file
|
@ -0,0 +1,27 @@
|
|||
<!--
|
||||
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.
|
||||
-->
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Continuation-passing style demo</title>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
||||
<script type="text/javascript" charset="utf-8" src="teavm/runtime.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="teavm/classes.js"></script>
|
||||
</head>
|
||||
<body onload="main()">
|
||||
<p>Please, open developer's console to view program's output</p>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user