M Monster Docs

Example Programs

exam.mnst

The smallest "hello world" style program for quick sanity checks.

mst run exam.mnst

examples/argv.mnst

Shows main(argc, argv) and forwarded CLI arguments.

mst run examples/argv.mnst -- hello

examples/constants.mnst

Uses top-level const declarations for scalar and string values.

mst run examples/constants.mnst

examples/file_io.mnst

Reads a file into memory, defers cleanup with std/mem.mnst, prints its size, and writes a copy back out.

mst run examples/file_io.mnst -- exam.mnst

examples/defer_scope.mnst

Shows scoped defer cleanup on normal block exit, continue, break, and return.

mst run examples/defer_scope.mnst

examples/imports/main.mnst

Demonstrates file imports, module aliases, and loop control.

mst run examples/imports/main.mnst

examples/enum.mnst

Introduces C-like enums and enum comparisons.

mst run examples/enum.mnst

examples/payload_enum.mnst

Shows payload-carrying enums before match enters the picture.

mst run examples/payload_enum.mnst

examples/match.mnst

Exercises enum-only match expressions with payload binding.

mst run examples/match.mnst

examples/string_bytes.mnst

Uses std/str.mnst and std/mem.mnst helpers to copy and compare a C-style string buffer.

mst run examples/string_bytes.mnst

examples/growable_vec_i32.mnst

Shows a growable vector built on the early std/vec_i32.mnst module with malloc, realloc, free, and defer.

mst run examples/growable_vec_i32.mnst

selfhost/main.mnst

Runs the first Monster-written self-hosting slice: a lexer prototype that scans Monster source into a token buffer.

mst run selfhost/main.mnst -- exam.mnst

Raw LLVM Example

The repository also includes a raw IR snapshot at examples/growable_vec_i32.ll, emitted by the current compiler.