Introducing wax, an innovative programming language that effortlessly transpiles into C, C++, Java, TypeScript, Python, C#, Swift, Lua, and WebAssembly. By focusing on simplicity and readability, wax allows programmers to produce clean, integral output across multiple languages without the complexities of each language's unique features. Welcome to seamless coding.
wax is an innovative and compact programming language that is engineered for seamless transpilation into various popular languages including C, C++, Java, TypeScript, Python, C#, Swift, Lua, and WebAssembly. 🚀
Overview
Designed as a "common subset" of major imperative programming languages, wax eliminates the complexities of unique language features, allowing for a straightforward user experience. The goals of wax include:
- Readable: The transpiled output is surprisingly similar to the original source code, making it easier for programmers to follow and understand.
- Editable: Even without access to the original wax source, programmers can effectively work with and modify the output code.
- Integrable: The generated code can be easily imported as libraries into other projects, ensuring versatile usability.
Though using a language with less flair can be seen as a limitation, wax ensures that crucial programming functions are intact, thus promoting productivity. The syntax is inspired by the WebAssembly Text Format (wat) and employs S-expressions akin to the Lisp family, yet remains heavily imperative and analogous to C in its structure. This design philosophy draws inspiration from Haxe’s language transpilation capabilities.
Hello World Example
Here's a simple example of a Hello World program written in wax:
(func main (result int)
(print "hello world!")
(return 0)
)
Newlines and indentations in wax are cosmetic, allowing flexibility in code representation with various bracket styles.
Compiler Features
The reference implementation of wax, known as waxc, is crafted from scratch in C99 and supports rapid compilation across its target languages. Some highlights include:
- Fast compiling speed: E.g., a 700 line wax file compiles in approximately 0.015 seconds on a MacBook Pro.
- Detailed output: Emit a low-level syntax tree in JSON format alongside the transpiled code.
- Tokenization and abstraction: Print tokenization and abstract syntax trees to the terminal for improved troubleshooting.
Sample Compilation Command
To illustrate the ease of use, here’s a command to transpile a sample program and print its abstract syntax tree:
./waxc examples/fib.wax --c fib.c --ast
For additional features like compiling to WebAssembly, check out the specific instructions provided in the README.
Community Contributions
As wax is currently in an experimental stage, contributions through pull requests and issue reporting are welcomed to help enhance its functionality.
Explore More
Take a look at the extensive examples or visit the online playground to interact with wax firsthand. To kickstart your journey with wax, navigate to the QUICKSTART guide.
Extend Your Experience
Don't forget to check out the VSCode Extension for syntax highlighting, transpilation, compilation, and more!