This repository contains a compiler developed in Java that translates high-level source code into WebAssembly (Wasm). The system includes an integrated testing environment via a local web server to verify the execution of the compiled code.
- Java Runtime Environment (JRE) / Java Development Kit (JDK) 17 or higher.
- Using a modern JDK distribution (such as Adoptium Temurin) is recommended to ensure compatibility and avoid errors when passing environment arguments. A basic JRE meeting the version requirement is also sufficient.
- Open a terminal or command prompt.
- Navigate to the directory containing the
Compilador.jarexecutable and the test files. - Run the compiler by providing the path to the source code file as a parameter:
java -jar Compilador.jar <source_code_path>Usage Example:
java -jar Compilador.jar PRUEBA_DE_FUEGO.txtUpon a successful compilation, the system automates the deployment and testing process:
- Intermediate Code Generation: The compiler generates an
out.wat(WebAssembly Text Format) file in the root directory. The contents of this file are also printed to the console for inspection. - Assembly: The
.watcode is processed internally usingwat2wasmto generate the final executable binary.- Note: The
wat2wasmexecutable is included in the directory in case manual assembly is required (by runningwat2wasm out.wat). If an external source code generates invalid instructions, the console will display the nativewat2wasmerrors before aborting the process.
- Note: The
- Local Server: A lightweight HTTP server is initialized, and the default web browser is automatically opened to load the WebAssembly execution environment.
- Standard Output (Prints): Print instructions defined in the source code will be displayed in the browser via notifications or pop-ups using the following format:
Valor/cadena recibida --> {Valor}. - Termination: Once testing in the browser is complete, press the
Enterkey in the terminal. This will shut down the local server and perform an automatic cleanup of the generated temporary files.
The repository includes multiple use cases to validate the compiler's behavior:
- Complex Tests (
PRUEBA_DE_FUEGO): Files that evaluate the performance and correctness of the compiler in advanced scenarios. C++ equivalents of these algorithms are provided so the outputs can be independently verified (e.g., using OnlineGDB). - Classic Algorithms: Test implementations for standard computational problems, including iterative Fibonacci and Factorial calculations.
- Error Validation: Files with names containing the words
errororincorrectopossess deliberate lexical, syntactic, or semantic flaws. Their purpose is to verify that the compiler correctly intercepts issues and reports the expected failures without generating final code. All other test cases are expected to compile successfully.