Build and Run Mech Programs
The mech command-line tool provides various functionalities for working with Mech programs, including executing scripts, debugging, formatting code, and serving applications over HTTP. Below are the available options and subcommands.
Basic Usage
Usage
mech [OPTIONS] [mech_paths]... [SUBCOMMAND]
Subcommands
Command | Description |
|---|---|
| Build Mech program into bytecode. |
| Format Mech source code into standard format. |
| Print help message. |
| Serve Mech program over an HTTP server. |
Arguments
Source .mec files and directories. You can specify one or more .mec/.mecb files, or directories containing Mech scripts / bytecode.
If you run the Mech command without any files or subcommands, it will start the REPL.
Options
Option | Description |
|---|---|
| Prints debug information. |
| Starts the Mech Read-Eval-Print Loop (REPL). |
| Measures execution time of the program. |
| Prints the parse tree of the Mech program. |
Examples
mech file1.mec file2.mec dir1 mech -d -e file.mec mech -t file.mec mech -r file.mec
Subcommands
build
Compiles Mech source code into bytecode.
mech build [OPTIONS] [FILES]
Options
Option | Value | Description |
|---|---|---|
|
| Specifies the output directory. |
Examples
mech build -o out_dir file1.mec mech build -o out_dir file1.mec file2.mec dir1 dir2
format
Formats Mech source code into a standard format.
mech format [OPTIONS] [FILES]
Options
Option | Value | Description |
|---|---|---|
|
| Specifies the output directory. |
|
| Sets the stylesheet for HTML output. |
| Outputs formatted code as HTML. |
Examples
mech format -o formatted/ my_script.mec
serve
Serves a Mech program over an HTTP server.
mech serve [OPTIONS] [FILES]
Options
Option | Value | Description |
|---|---|---|
|
| Sets the port for the server (default: 8081). |
|
| Sets the server address (default: 127.0.0.1). |
Examples
mech serve -p 3000 -a 0.0.0.0 my_script.mec
Additional Help
For more information on a specific command, you can use the --help option with that command. For example:
mech --help mech serve --help