Skip to content

StellarWitch7/moth-lang

Repository files navigation

Moth

Home Page

About Build Test

Moth's official compiler, written in C#. It takes Moth code and converts it to LLVM IR, which is then passed to the Clang C compiler. Currently only compatible with the Clang compiler. Read the wiki for Moth's documentation. Please report any bugs to the issue tracker, as it helps to improve Moth's compiler.

Dependencies

  1. .NET 7
  2. Clang 16
  3. Git
  4. Git Extras

Arguments

luna

Usage:
luna build [-v] [-n] [-c] [--no-advanced-ir-opt] [-p <path>] => Builds the project at the path provided or in the current directory if no project file is passed. 
luna run [-v] [-n] [-c] [--no-advanced-ir-opt] [-p <path>] [--run-args <args>] [--run-dir <path>] => Builds and runs the project at the path provided or in the current directory if no project file is passed. 
luna init [--lib] [--name <project-name>] => Initialises a new project in the current directory. 

-v, --verbose => Logs extra info to console. 
-n, --no-meta => Strips metadata from the output file. WARNING: disables reflection! 
-c, --clear-cache => Whether to clear dependency cache prior to build. 
--no-advanced-ir-opt => Whether to skip IR optimization passes. 
-p, --project => The project file to use. 
--name => When initializing a new project, pass this option with the name to use. 
--lib => When initializing a new project, pass this option to create a static library instead of an executable project. 
--run-args => When running a project, pass this option with the arguments to use. 
--run-dir => When running a project, pass this option with the working directory to use. 

mothc

Usage:
mothc [-v] [-n] [--no-advanced-ir-opt] [--moth-libs <paths>] [--c-libs <paths>] -t exe|lib -o <output-name> -i <paths>
-v, --verbose => Logs extra info to console. 
-n, --no-meta => Strips metadata from the output file. WARNING: disables reflection! 
--no-advanced-ir-opt => Whether to skip IR optimization passes. 
-t, --output-type => The type of file to output. Options are "exe" and "lib". 
-o, --output => The name of the output file. Please forego the extension.
-i, --input => The files to compile.
--moth-libs => External Moth library files to include in the compiled program. 
--c-libs => External C library files to include in the compiled program. 

Hello World

The following is a minimal example that prints "Hello World!" to the terminal.

// HelloWorld.moth
namespace hello; // all files must belong to a namespace

with core; // we are using the core namespace in this file, so we declare our usage here

// the main function is the entrypoint of an executable program
// it must return a value of type i32
func main() #i32 {
    WriteLine("Hello World!"); // we use the core namespace here
    return 0; // we end the program by returning from the main function with an exit code of zero
}

To learn how to run this code, continue reading.

Tools

Currently the only aid for coding in Moth is the official VS Code extension. It serves only to provide syntax highlighting.

!!WARNING!!

Moth is currently unfinished. Many things are unlikely to function well.