Skip to content

Latest commit

 

History

History
118 lines (88 loc) · 3.46 KB

README.md

File metadata and controls

118 lines (88 loc) · 3.46 KB

minijs

go report go doc release ci code coverage

minijs is a JavaScript bytecode virtual machine implemented in Go. It converts JavaScript code into bytecode for execution and, with high compatibility with Go, can be seamlessly embedded into various Go-based applications.

Key Features

  • Bytecode Execution: Optimizes performance by converting JavaScript code into bytecode and executing it in a virtual machine.
  • High Compatibility with Go: Developed in Go, making it easy to integrate into Go-based applications.

Installation

minijs runs in a Go environment. You can clone the repository and build it using the following commands:

git clone https://github.com/siyul-park/minijs.git  
cd minijs  
make build  

Usage

Running the REPL

You can execute JavaScript code interactively in the REPL (Read-Eval-Print Loop).

minijs  
> 'b'+'a'+ +'a'+'a'  
"baNaNa"  

Bytecode Output

To print the corresponding bytecode, use the -print-bytecode flag.

minijs --print-bytecode  
> 'b'+'a'+ +'a'+'a'  
section .text:
        str.load 0x00000000 0x00000001
        str.load 0x00000002 0x00000001
        str.add
        str.load 0x00000002 0x00000001
        str.to_f64
        f64.to_str
        str.add
        str.load 0x00000002 0x00000001
        str.add
        pop

.section .data:
        b
        a

"baNaNa"  

Executing a JavaScript File

When executing a file, minijs applies optimization processes to make the bytecode more efficient. To run a JavaScript file, use the following command:

minijs banana.js  

Printing Bytecode from a File

To print the bytecode while executing a file, use the -print-bytecode flag.

minijs -print-bytecode banana.js  
section .text:
        str.load 0x00000000 0x00000006
        pop

.section .data:
        baNaNa