All Projects → jtransc → Jtransc

jtransc / Jtransc

Licence: apache-2.0
Bytecode to source converting Java & Kotlin code into JavaScript, C++, D, C#, PHP, AS3, Dart and Haxe and run it everywhere. Also use JVM code in your favourite language as a library.

Programming Languages

javascript
184084 projects - #8 most used programming language
java
68154 projects - #9 most used programming language
kotlin
9241 projects
scala
5932 projects
dart
5743 projects
cpp
1120 projects
csharp
926 projects
haxe
709 projects
d
599 projects

Projects that are alternatives of or similar to Jtransc

Jphp
JPHP - an implementation of PHP on Java VM
Stars: ✭ 1,665 (+212.97%)
Mutual labels:  compiler, jvm
Openj9
Eclipse OpenJ9: A Java Virtual Machine for OpenJDK that's optimized for small footprint, fast start-up, and high throughput. Builds on Eclipse OMR (https://github.com/eclipse/omr) and combines with the Extensions for OpenJDK for OpenJ9 repo.
Stars: ✭ 2,802 (+426.69%)
Mutual labels:  compiler, jvm
Perlito
"Perlito" Perl programming language compiler
Stars: ✭ 396 (-25.56%)
Mutual labels:  compiler, jvm
Dynarmic
An ARM dynamic recompiler.
Stars: ✭ 475 (-10.71%)
Mutual labels:  compiler
Luaj
Lightweight, fast, Java-centric Lua interpreter written for JME and JSE, with string, table, package, math, io, os, debug, coroutine & luajava libraries, JSR-223 bindings, all metatags, weak tables and unique direct lua-to-java-bytecode compiling.
Stars: ✭ 477 (-10.34%)
Mutual labels:  jvm
Awesome Tensor Compilers
A list of awesome compiler projects and papers for tensor computation and deep learning.
Stars: ✭ 490 (-7.89%)
Mutual labels:  compiler
Flow9
Platform for safe, easy and productive programming of complex, multi-platform apps with a modern user interface
Stars: ✭ 520 (-2.26%)
Mutual labels:  compiler
Pdf
编程电子书,电子书,编程书籍,包括C,C#,Docker,Elasticsearch,Git,Hadoop,HeadFirst,Java,Javascript,jvm,Kafka,Linux,Maven,MongoDB,MyBatis,MySQL,Netty,Nginx,Python,RabbitMQ,Redis,Scala,Solr,Spark,Spring,SpringBoot,SpringCloud,TCPIP,Tomcat,Zookeeper,人工智能,大数据类,并发编程,数据库类,数据挖掘,新面试题,架构设计,算法系列,计算机类,设计模式,软件测试,重构优化,等更多分类
Stars: ✭ 12,009 (+2157.33%)
Mutual labels:  jvm
Javakeeper
✍️ Java 工程师必备架构体系知识总结:涵盖分布式、微服务、RPC等互联网公司常用架构,以及数据存储、缓存、搜索等必备技能
Stars: ✭ 502 (-5.64%)
Mutual labels:  jvm
Openrndr
OPENRNDR. A Kotlin/JVM library for creative coding, real-time and interactive graphics
Stars: ✭ 486 (-8.65%)
Mutual labels:  jvm
Pikelet
A friendly little systems language with first-class types. Very WIP! 🚧 🚧 🚧
Stars: ✭ 485 (-8.83%)
Mutual labels:  compiler
Eslisp
un-opinionated S-expression syntax and macro system for JavaScript
Stars: ✭ 481 (-9.59%)
Mutual labels:  compiler
Red
Red is a next-generation programming language strongly inspired by Rebol, but with a broader field of usage thanks to its native-code compiler, from system programming to high-level scripting and cross-platform reactive GUI, while providing modern support for concurrency, all in a zero-install, zero-config, single 1MB file!
Stars: ✭ 4,725 (+788.16%)
Mutual labels:  compiler
Nimporter
Compile Nim Extensions for Python On Import!
Stars: ✭ 474 (-10.9%)
Mutual labels:  compiler
Libfsm
DFA regular expression library & friends
Stars: ✭ 512 (-3.76%)
Mutual labels:  compiler
Dotty
The Scala 3 compiler, also known as Dotty.
Stars: ✭ 4,836 (+809.02%)
Mutual labels:  compiler
Langcraft
Compiler from LLVM IR to Minecraft datapacks.
Stars: ✭ 495 (-6.95%)
Mutual labels:  compiler
Mvikotlin
Extendable MVI framework for Kotlin Multiplatform with powerful debugging tools (logging and time travel)
Stars: ✭ 483 (-9.21%)
Mutual labels:  jvm
Opal
Ruby ♥︎ JavaScript
Stars: ✭ 4,552 (+755.64%)
Mutual labels:  compiler
Turboscript
Super charged typed JavaScript dialect for parallel programming which compiles to WebAssembly
Stars: ✭ 487 (-8.46%)
Mutual labels:  compiler

JTRANSC

JTransc

Maven Version Build Status Build status Code coverage gitter

Documentation

You can find documentation at the wiki.

What is this?

JTransc (Java Trans Compiler) is an AOT (ahead of time compiler) that compiles .class and .jar files into a target programming language / executable bundling all the required dependencies in a single file or folder, without requiring a jitter or an external runtime.

Why using JTransc?

There are a lot of technologies in order to convert languages into other ones. For example, converting Java into JavaScript. Or KotlinJS Kotlin backend that already targets JavaScript. So why using JTransc?

Mixed input code:

One reason is that JTransc allows mixed projects. You can use Java libraries with Kotlin code for example.

Multiple targets:

Instead of using several technologies, JTransc allows you to target to several languages and platforms.

Consistency:

Using just one technology guarantees consistency between targets. For example, Kotlin JS doesn't support full Java reflection.

Native:

Instead of generating C++ and then using emscripten or other technologies, JTransc allows you to generate code that is native to your platform. For example: when targeting JS you will use native JS best-in-class GC instead of a GC emulated in C++ & emscripten. And no need to know a proper heap size beforehand targeting JS.

Native facilities:

Some classes like String, StringBuilder or ArrayList are implemented in a way that it uses native JavaScript/AS3/Dart... facilities. Like JavaScript String, Array and so on.

Treeshaking:

Instead of generating huge projects including everything, or having complex proguard configuration files. JTransc includes treeshaking in a simple way. You can use annotations to keep methods, classes and fields or another annotations. It works for all targets and it is fully integrated in the workflow.

Thread and sync I/O support in JS:

JTransc supports plain Java applications using Threads and sync I/O in JS converting that into an asynchronous version in JS using await/async detecting branches not using Threads/sync I/O for fastest performance.

Support this project

Along JTransc, I'm writting a set of libraries to be able to use JTransc.

https://github.com/soywiz/korlibs

Kotlin Game Engine that uses JTransc for multiplatform: https://github.com/soywiz/korge

Also there is a GDX backend using JTransc+Haxe: https://github.com/jtransc/gdx-backend-jtransc

JTransc

Detailed: What is this?

JTransc (Java Trans Compiler) is an AOT (ahead of time compiler) that compiles .class and .jar files into a target programming language / executable bundling all the required dependencies in a single file or folder, without requiring a jitter or an external runtime.

At the beginning it generated as3 and javascript, but right now there are several targets: Javascript, Haxe, C++, and D. Haxe itself allow to target several other languages: JS, AS3, C++, C#, Java, PHP and Python. This in turn allows running the program on different platforms such as desktop, browsers and mobile.

The aim of this project is to bring the high productivity of Kotlin (and other JVM languages) to the highly portable Haxe platform. It already supports most of the core Java APIs and plain Java reflection API out of the box.

The initial focus is on JVM6, Kotlin and Games, but it will get better in the future supporting newer jvm versions, and other use cases like frontend and backend applications.

Right now JTransc support Java8 lambdas and default methods.

There is a module called jtransc-rt-core that could be included in any project (whether using JTransc or not). It provides the com.jtransc package, specific annotations, fast memory access and asynchronous APIs, that will use JTransc features when compiling using JTransc.

These is also a couple of projects for multimedia applications using jtransc:

  • jtransc-media - Which provides a very simple and portable high-level API for multimedia
  • gdx-backend-jtransc - Which provides a gdx-compatible backend so any gdx project will be able to work (still some rough edges)

How to use it?

You can find examples here jtransc/jtransc-examples.

Plain:

# jtransc script can be found under the jtransc-main-run folder
javac com/test/Main.java -d target/classes
jtransc dependency.jar target/classes -main com.test.Main -out program.js
node program.js

Gradle:

This is the preferred way of using JTransc. You can include it from maven central or directly from gradle plugins repository:

plugins {
  id "com.jtransc" version "0.6.8"
}

This will add several tasks for building your application. There is a gradle block called jtransc, that allows you to specify stuff for the build.

For example gradle runJs would generate a JS file at build/jtransc-js/program.js and run it using node.js.

You can see how to use it in the documentation.

Maven:

You can also use Maven, though due to the nature of JTransc gradle fits better. You can see how to use it in the documentation.

intelliJ:

There is a plugin in the works that will allow to run and debug within intelliJ. Though it is not ready yet. You can find it in jtransc-intellij-plugin folder.

How does it work internally?

  • It locates all the required dependencies (specifying dependencies using gradle, maven, intelliJ or CLI)
  • It includes jtransc-rt-core and jtransc-rt which is a java-6-like (with some Java8 support) RT with some of its methods marked as native
  • Other dependencies than the RT are included without modifications
  • It uses ASM library to load class files, and has code to generate a class-method-statement-expression AST
    • That AST is easily serializable
    • That AST allows feature stripping
    • Your target language don't support gotos? It will generate an AST without gotos. Just plain if/while/switch...
  • It generates your target source code, replacing some classes like String, ArrayList and so on, to make them fast in your target language.
  • It joins or compiles that code into your final runnable program (using available compilers when required)
  • It allows to run directly executing the executable or using an appropiate interpreter (php, node, electron...) depending on the build

Eventually that intermediate AST will be able to be generated or consumed. So others could generate that without JVM and others could generate other targets from that AST directly without all the complexities of stack-based IRs.

Tool dependencies:

Java:

  • Oracle JDK8 (Verified 8u131)
  • Android SDK Tools (Verified 25.2.3)

For the Haxe target:

  • Haxe 3.4.2
  • NekoVM 2.1.0
  • Lime 5.5.0
  • hxcpp 3.4.64

For Node.JS running:

  • NodeJS 7.10.0 with npm 4.2.0

For D target:

  • DMD2 or GDC or LDC (Verified dmd-2.074.0)

For C++ target:

  • Clang++ or g++ (At least gcc 4.8)

For Dart target:

  • Tested with Dart VM version: 1.23.0

Verified on Windows 10.0.15063 and macOS Sierra 10.12.4

Installing JDK

  • Install JDK8
  • Setup $JAVA_HOME This sample, but maybe not working for you, be careful
echo "export JAVA_HOME=$(/usr/libexec/java_home)" >> ~/.bash_profile
source ~/.bash_profile

Installing Haxe

  • Install Haxe from here via installer
  • Set path to haxelib running "haxelib setup" command
  • Install Lime haxelib install lime 5.5.0
  • Install hxcpp haxelib install hxcpp 3.4.64
  • Run haxelib run lime setup

######https://github.com/openfl/lime/issues/831

  • Run lime setup android If try install you gain Out of Memory, choose manual mode.
Download and install the Android SDK? [y/n/a] ? n
Download and install the Android NDK? [y/n/a] ? n
Download and install the Java JDK? [y/n/a] ? n

Path to Android SDK [C:\tools\android-sdk]:
Path to Android NDK []: C:\tools\android-ndk
Path to Java JDK [C:\Program Files\Java\jdk1.8.0_131]:

Setup AppleTV

  • Run lime rebuild hxcpp tvos
  • Remove stable lime haxelib remove lime
  • Install lime from GitHub git clone --recursive https://github.com/openfl/lime
haxelib dev lime lime
haxelib install format
lime rebuild mac
lime rebuild ios
lime rebuild tvos

Installing Node.JS

Installing D

  • Download DMD
  • Install DMD with all extras

Installing C++ suitable compiler

WINDOWS

Workaround for big projects: haxe 3.4.2 can failed with out of memory. You can try replace haxe files from develop, but this dangerous way, and get only stable, see history on github. My current choose: 2017-03-23 05:39:01 >> 4876859 >> haxe_2017-03-23_development_ada466c.tar.gz

WINDOWS 64

  • go to hxcpp/3.4.64 folder in console neko run.n Build.xml -Dwindows -DHXCPP_M64 -Dstatic_link ./project/
  • Remove stable lime haxelib remove lime
  • Install lime from GitHub git clone --recursive https://github.com/openfl/lime -b master
haxelib dev lime lime
haxelib install format

if use MSVC 2013 with not fully supported c99 standard, then replace in lib\openal all inline to __inline, and snprintf to _snprintf

lime rebuild windows -64

MAC

  • Install Xcode 8.3.3
  • This XCode have problem with logs for iPhone with iOS 10.3.2. Please see solution
  • Related to pure C++ target on mac: brew install automake libtool pkg-config
  • Install Mono 5.0.1.1 ??? https://github.com/jtransc/jtransc/issues/167
  • For upload on iPhone/iPad from command line sudo npm install -g ios-deploy --unsafe-perm --allow-root

Installing Dart

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].