alexdovzhanyn / ThetaLang

θ A statically typed, functional programming language that compiles to WebAssembly
MIT License
32 stars 9 forks source link

Investigate and Decide on WebAssembly Backend Implementation Options for Theta #3

Closed alexdovzhanyn closed 3 months ago

alexdovzhanyn commented 3 months ago

Investigate options for targeting WebAssembly as the language backend. Decide whether to use WebAssembly Text Format (WAT) or directly compile to WebAssembly binary (WASM). Additionally, explore the possibility of using LLVM as a target Intermediate Representation (IR) for compiling to WebAssembly.

Subtasks:

alexdovzhanyn commented 3 months ago

Research: LLVM vs. WASM

The Case for LLVM

Targeting LLVM as a backend would allow the language to produce native code for all major architectures. LLVM can also compile to WASM, supporting both native and WASM VM options. With built-in code optimization, LLVM makes it easier to generate efficient code.

The Case for WASM

Targeting WASM as the backend simplifies code generation. Since the language is educational, high performance isn't a priority. WASM's built-in garbage collection (GC) and support for control flow structures make it a better fit for a high-level language. Compiling directly to WASM is also faster than using LLVM.


Pros and Cons

LLVM


WASM


Verdict

We will target WASM as the backend for the language. WASM allows the language to be more flexible and high-level, aligning with the project's goals. For native compilation, we can use tools like Wasmer to convert our WASM output to native code, maintaining flexibility and ease of implementation.