Search code examples
transpiler

Abstract (programming) language built to transpile


Introduction

Oftentimes I encounter a situation in which a library has been written in a particular programming language. That's great, if I want to use the library in the same language, but if I want to use a different language, that's going to be a problem (that doesn't mean that there might be a more or less hacky way).
For some libraries I have the feeling that they have been written in that particular programming language, simply because any language will do (and because of personal preference of the author) meaning that no language-specific high-level external 3rdparty-libraries are being used. For these situations I thought that it would be neat, if there was some sort of abstract (programming) language in which the library author can specify the algorithms, but which can then be transpiled into a lot of other programming languages. Thus if I want to use that library, I can simply use the transpiler to get that library in my language of choice.


Actual question

So what I am looking for is a language, that is specifically meant to be transpiled into most popular languages (e.g. Java, C/C++, Python). I'm interested in whether someone has gone through the effort of creating such a "universal" transpiler language before.

Note that I'm not looking for a particular transpiler from one language to another. I want to know whether there exists a (programming) language that has been designed for being transpilable into source code of a lot of different actual programming languages. Thus the language I'm looking for would probably not even run by itself (only the transpiled code would be an actual program).
Although I would be interested to hear general pros/cons for the existence of such a language, this is also not what this question is about due to the rules here on SO. Therefore I'd ask you, to not write opinion-based answers in this kind of style.

The answer to this question might very well be that there is no such language, but as my recherche hasn't brought anything up, I thought that maybe someone here knows of such a language, that I might have missed due to it not being widely used.


Solution

  • One language that was designed with the intention of being transpiled to various other languages is Haxe
    At the time of writing it supports generating source code for:

    • JavaScript
    • ActionScript 3
    • PHP (including PHP7)
    • C++
    • Java
    • C#
    • Python
    • Lua

    (reference: https://haxe.org/documentation/introduction/compiler-targets.html)

    It also supports compiling directly to byte code for specific VMs