Giter VIP home page Giter VIP logo

jwebassembly's Introduction

JWebAssembly

Build Status License Coverage Status Download

JWebAssembly is a Java bytecode to WebAssembly compiler. It uses Java class files as input. That it can compile any language that compile to Java bytecode like Clojure, Groovy, JRuby, Jython, Kotlin and Scala. As output it generates the binary format (.wasm file) or the text format (.wat file). The target is to run Java natively in the browser with WebAssembly.

The difference to similar projects is that not a complete VM with GC and memory management should be ported. It's more like a 1: 1 conversion. The generated WebAssembly code is similar in size to the original Java class files.

Documentation

The documentation can be found in the wiki.

Roadmap

The project is currently not production ready but you can run already some tests.

Version 1.0 (Milestone 1)

Desired Features

  • Java byte code parser
  • test framework
  • Public API of the Compiler see class JWebAssembly
  • Gradle Plugin
  • Emulator
  • Binary format file writer and Text format file writer
  • Support for native methods #2
  • Memory Management - currently with a polyfill on JavaScript side
  • invoke static method calls
  • invoke instance method calls
  • invoke interface method calls
  • invoke dynamic method calls (lambdas)
  • invoke default method calls
  • String support
  • Simple Class object support
  • static constructors
  • Optimizer - Optimize the WASM output of a single method after transpiling before writing to output
  • Hello World sample (live), (source code)

Status of Required WebAssembly Features

The following table shows the status of future WebAssembly features required by JWebAssembly in nightly builds in various implementations. These features are already used by the trunk version of JWebAssembly. If you want know the status of your current browser then look for your browser support.

Feature Importance V8/Chrome SpiderMonkey/FF WABT
Mutable Globals high yes yes yes
float-to-int high yes yes yes
Sign-extension high yes yes yes
Reference Types high yes yes yes
JavaScript BigInt medium yes yes yes
Multi-value medium yes - yes

To use it also some flags and switches are currently needed.

Importance: All with high marked features are required for a hello word sample. For a first version that can be used for production.

Version 2.0 (Milestone 2)

Desired Features

Version 3.0 (Milestone 3)

Desired Features

  • Exception handling - required the next version of WebAssembly
  • Multiple threads - required the next version of WebAssembly
  • Memory Management with build in GC without JavaScript polyfill
  • More Optimize like Tail Calls

Status of Required WebAssembly Features

Feature Importance V8/Chrome SpiderMonkey/FF WABT
Garbage collection medium - partly -
Exceptions low partly - partly
Threads low yes ? yes
Tail call very low yes ? yes

Required Java Version

The JWebAssembly compiler requires Java SE 8 or higher. It is tested with Java SE 8 on travis-ci.org.

Usage

Exporting functions

To export a Java function to make it accessible from JavaScript, you must add the annotation de.inetsoftware.jwebassembly.api.annotation.Export.

import de.inetsoftware.jwebassembly.api.annotation.Export;

@Export
public static int add( int a, int b ) {
    return a + b;
}

importing functions

To import a JavaScript function to make it accessible from Java, you must add the annotation de.inetsoftware.jwebassembly.api.annotation.Import. The method can be declared native or can have a Java implementation which will be ignored on compiling.

import de.inetsoftware.jwebassembly.api.annotation.Import;

@Import( module = "global.Math", name = "max" )
static int max( int a, int b) {
    return Math.max( a, b );
}

Java Limits

In version 1 of WebAssembly you can only compile:

  • static methods
  • use the data types int, long float and double

This is state of JWebAssembly 0.1. With version 0.2 you can use Objects via JavaScript polyfill.

Alternatives

For Tool Developer

If you want to develop some tools like plugins for a build system or an IDE, then you need

jwebassembly's People

Contributors

horcrux7 avatar hcientist avatar aleksrutins avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.