Update readme

This commit is contained in:
konsoletyper 2014-10-05 16:45:44 +04:00
parent 9e09c247e6
commit 137c7f633d

View File

@ -4,25 +4,25 @@ TeaVM
What is TeaVM? What is TeaVM?
-------------- --------------
In short, TeaVM gets a bytecode, running over JVM, and translates it to the JavaScript code, TeaVM is an ahead-of-time translator from Java bytecode to JVM.
which does exactly the same thing as the original bytecode does. It can be compared with GWT, however TeaVM does not require source code of your application and
It is based on its cross-compiler which transforms `class` files to JavaScript. all required libraries.
But there is something more: You can use TeaVM for building applications for the browser, due to the following features:
* a sophisticated per-method dependency manager, which greatly reduces the JavaScript output; * per-method dependency analyzer, that determines a set of methods that are really needed
* an optimizer capable of things like devirtualization, inlining, constant propagation, to run your application, so TeaVM won't translate whole JAR files;
loop invariant motion and many other; * fast JavaScript; for now it is almost as fast as the JavaScript, generated by GWT;
* implementation of subset of core Java library; * Java class library emulation;
* integration with Maven and Eclipse;
* generation of source maps;
* debugger;
* interoperation with JavaScript libraries together with the set of predefined browser interfaces.
How to use How to use
---------- ----------
There is no TeaVM artifacts in the central Maven repository yet. There are several options of using TeaVM. One is the Maven build. First, you write your code as if it were an
So first you need to clone project and install it into the local repository. ordinary Java application:
In order to install project, just run `mvn install` when you are in the project's root directory.
There are several options of using TeaVM. One is the maven build. First, you write your code as if it were an
ordinary Java project:
```Java ```Java
package org.teavm.samples; package org.teavm.samples;
@ -40,12 +40,12 @@ Second, you include the following plugin in your `pom.xml` build section:
<plugin> <plugin>
<groupId>org.teavm</groupId> <groupId>org.teavm</groupId>
<artifactId>teavm-maven-plugin</artifactId> <artifactId>teavm-maven-plugin</artifactId>
<version>0.1</version> <version>0.2</version>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.teavm</groupId> <groupId>org.teavm</groupId>
<artifactId>teavm-classlib</artifactId> <artifactId>teavm-classlib</artifactId>
<version>0.1</version> <version>0.2</version>
</dependency> </dependency>
</dependencies> </dependencies>
<executions> <executions>
@ -69,8 +69,7 @@ Now you can execute `mvn clean package` and get the generated JavaScript files i
Just open `target/javascript/main.html` page in your browser, open developer's console and press *Refresh* and Just open `target/javascript/main.html` page in your browser, open developer's console and press *Refresh* and
see what happen. see what happen.
There is [teavm-samples](teavm-samples) module, There is also the [teavm-samples](teavm-samples) module, containing examples of TeaVM-based projects.
containing a complete buildable and runnable example.
DukeScript DukeScript
---------- ----------
@ -92,40 +91,4 @@ and [HTML page](http://source.apidesign.org/hg/html~demo/file/4dce5ea7e13a/mines
Another example is avaialble [here](http://graphhopper.com/teavm/). Another example is avaialble [here](http://graphhopper.com/teavm/).
It uses [GraphHopper](https://github.com/graphhopper/graphhopper/) to build route in browser. It uses [GraphHopper](https://github.com/graphhopper/graphhopper/) to build route in browser.
Unlike original GraphHopper example it works completely in browser instead of querying server. Unlike original GraphHopper example it works completely in browser instead of querying server.
Thanks to [Peter Karich](https://github.com/karussell). Thanks to [Peter Karich](https://github.com/karussell).
Advantages over GWT
-------------------
You may notice that TeaVM idea is much similar to GWT. So why we need TeaVM instead of GWT?
Unlinke GWT, TeaVM gets the compiled bytecode, not Java sources.
Thereby it **does not depend on a specific language syntax**. Even not on a specific language.
So, when the next Java version gets a new feature, you can use it in your source code
and TeaVM compiler remains unbroken. Also you may want thigs Scala, Kotlin or Ceilon. TeaVM supports them.
To represent a source code, GWT uses abstract syntax trees (AST).
TeaVM uses control flow graph (CFG) of methods. CFG are much easier to optimize,
so TeaVM **applies aggressive optimizations** to you code to make it running faster.
TeaVM compiler is faster. And TeaVM does not produce permutations.
So with TeaVM you have no permutation explosion problem.
Advantages over JavaScript
--------------------------
JavaScript suffers of its dynamic typing. When you write a new code, dynamic typing accelerates
the development process, allowing you to write less boilerplate code.
But when you are to maintain a large code base, you may need static typing.
Also, it is not dynamic typing that really makes code short.
Good static typed languages can [infer variable types for you](http://en.wikipedia.org/wiki/Type_inference).
And they usually have a lot more useful features like [lambda functions](http://en.wikipedia.org/wiki/Lambda_function),
[lexical closures](http://en.wikipedia.org/wiki/Closure_%28computer_science%29),
[implicit type casting](http://en.wikipedia.org/wiki/Type_conversion#Implicit_type_conversion), etc.
With JavaScript you sometimes have to include large library for only one feature. Or you include many different
libraries for different purposes and your project size grows. TeaVM translates only the methods which
are really needed. So you can depend on as much libraries as you want and get
With JavaScript you are limited to one language. TeaVM supports many of the JVM languages.