# marflo-lang/m-language architecture

> Architecture diagram of the GitHub repository marflo-lang/m-language, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/marflo-lang/m-language
- Repository: https://github.com/marflo-lang/m-language

## Overview

This repository implements the M language interpreter: a command-line user supplies a script, which is tokenized, parsed into syntax, compiled to IR and bytecode, then executed by the VM, with results displayed by the CLI. The runtime also includes value and collection objects, stack operations, VM utilities, and error handling. The CLI excerpt shows its frontend/compiler orchestration and result formatting; some later execution calls and internal runtime interactions are not shown, so those links are omitted or marked unverified.

Main entry points: [`src/cli/cli.c`](https://github.com/marflo-lang/m-language/blob/master/src/cli/cli.c) (CLI commands), [`src/vm/vm.c`](https://github.com/marflo-lang/m-language/blob/master/src/vm/vm.c) (Bytecode VM), [`src/utils/err.c`](https://github.com/marflo-lang/m-language/blob/master/src/utils/err.c) (Diagnostics), [`src/vm/mobjects.c`](https://github.com/marflo-lang/m-language/blob/master/src/vm/mobjects.c) (Values and objects)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["Command line"]
  node_cli["CLI commands<br/>[cli.c]"]
end

subgraph group_frontend["Language frontend"]
  node_lexer["Lexer<br/>[lexer.c]"]
  node_parser["Parser<br/>[parser.c]"]
  node_ast["AST types<br/>[ast.h]"]
end

subgraph group_backend["Compilation backend"]
  node_compiler["IR compiler<br/>[compiler.c]"]
  node_codegen["Bytecode generator<br/>[codegen.c]"]
end

subgraph group_runtime["Virtual machine"]
  node_vm["Bytecode VM<br/>[vm.c]"]
  node_objects["Values and objects<br/>[mobjects.c]"]
  node_stack["VM stack API<br/>[mstack.c]"]
  node_vmutils["Value operations<br/>[mvmutils.c]"]
  node_runtime_errors["Runtime errors<br/>[merror.c]"]
end

subgraph group_support["Runtime support"]
  node_allocator["Arena allocator<br/>[allocator.c]"]
  node_errors["Diagnostics<br/>[err.c]"]
  node_printing["Value printing<br/>[print.h]"]
  node_common["Common definitions<br/>[common.h]"]
  node_language_defs["Language definitions<br/>[m.h]"]
  node_runtime_config["Runtime configuration<br/>[mconfig.h]"]
  node_debug["Debug assertions<br/>[mdebug.h]"]
end

node_user(("Script user"))

node_user -->|"provides script"| node_cli
node_cli -->|"tokenizes source"| node_lexer
node_cli -->|"parses tokens"| node_parser
node_cli -->|"compiles syntax"| node_compiler
node_cli -->|"generates bytecode"| node_codegen
node_cli -->|"formats result"| node_stack
node_parser -->|"builds syntax"| node_ast
node_compiler -->|"provides IR"| node_codegen
node_codegen -->|"creates VM chunk"| node_vm
node_vm -->|"operates on values"| node_objects
node_vm -->|"uses stack"| node_stack
node_vm -->|"reports runtime faults"| node_runtime_errors
node_vm -->|"reports diagnostics"| node_errors
node_objects -->|"uses assertions"| node_debug
node_stack -->|"manipulates values"| node_objects
node_vm -->|"uses value helpers"| node_vmutils
node_allocator -->|"reports allocation failures"| node_errors
node_lexer -->|"reports lexical errors"| node_errors
node_parser -->|"reports syntax errors"| node_errors
node_compiler -->|"reports compile errors"| node_errors
node_cli -->|"prints output"| node_printing
node_debug -->|"uses definitions"| node_common
node_objects -->|"uses limits"| node_runtime_config
node_language_defs -.->|"sets runtime types"| node_runtime_config

click node_cli "https://github.com/marflo-lang/m-language/blob/master/src/cli/cli.c"
click node_lexer "https://github.com/marflo-lang/m-language/blob/master/src/frontend/lexer.c"
click node_parser "https://github.com/marflo-lang/m-language/blob/master/src/frontend/parser.c"
click node_ast "https://github.com/marflo-lang/m-language/blob/master/src/frontend/ast.h"
click node_compiler "https://github.com/marflo-lang/m-language/blob/master/src/backend/compiler.c"
click node_codegen "https://github.com/marflo-lang/m-language/blob/master/src/backend/codegen.c"
click node_vm "https://github.com/marflo-lang/m-language/blob/master/src/vm/vm.c"
click node_objects "https://github.com/marflo-lang/m-language/blob/master/src/vm/mobjects.c"
click node_stack "https://github.com/marflo-lang/m-language/blob/master/src/vm/mstack.c"
click node_vmutils "https://github.com/marflo-lang/m-language/blob/master/src/vm/mvmutils.c"
click node_runtime_errors "https://github.com/marflo-lang/m-language/blob/master/src/vm/merror.c"
click node_allocator "https://github.com/marflo-lang/m-language/blob/master/src/utils/allocator.c"
click node_errors "https://github.com/marflo-lang/m-language/blob/master/src/utils/err.c"
click node_printing "https://github.com/marflo-lang/m-language/blob/master/src/utils/print.h"
click node_common "https://github.com/marflo-lang/m-language/blob/master/include/common.h"
click node_language_defs "https://github.com/marflo-lang/m-language/blob/master/include/m.h"
click node_runtime_config "https://github.com/marflo-lang/m-language/blob/master/include/mconfig.h"
click node_debug "https://github.com/marflo-lang/m-language/blob/master/include/mdebug.h"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_user toneBlue
class node_lexer,node_parser,node_ast toneAmber
class node_compiler,node_codegen toneMint
class node_vm,node_objects,node_stack,node_vmutils,node_runtime_errors toneRose
class node_allocator,node_errors,node_printing,node_common,node_language_defs,node_runtime_config,node_debug toneIndigo
```

## Components

### Command line

- [CLI commands](https://github.com/marflo-lang/m-language/blob/master/src/cli/cli.c): `src/cli/cli.c`

### Language frontend

- [Lexer](https://github.com/marflo-lang/m-language/blob/master/src/frontend/lexer.c): `src/frontend/lexer.c`
- [Parser](https://github.com/marflo-lang/m-language/blob/master/src/frontend/parser.c): `src/frontend/parser.c`
- [AST types](https://github.com/marflo-lang/m-language/blob/master/src/frontend/ast.h): `src/frontend/ast.h`

### Compilation backend

- [IR compiler](https://github.com/marflo-lang/m-language/blob/master/src/backend/compiler.c): `src/backend/compiler.c`
- [Bytecode generator](https://github.com/marflo-lang/m-language/blob/master/src/backend/codegen.c): `src/backend/codegen.c`

### Virtual machine

- [Bytecode VM](https://github.com/marflo-lang/m-language/blob/master/src/vm/vm.c): `src/vm/vm.c`
- [Values and objects](https://github.com/marflo-lang/m-language/blob/master/src/vm/mobjects.c): `src/vm/mobjects.c`
- [VM stack API](https://github.com/marflo-lang/m-language/blob/master/src/vm/mstack.c): `src/vm/mstack.c`
- [Value operations](https://github.com/marflo-lang/m-language/blob/master/src/vm/mvmutils.c): `src/vm/mvmutils.c`
- [Runtime errors](https://github.com/marflo-lang/m-language/blob/master/src/vm/merror.c): `src/vm/merror.c`

### Runtime support

- [Arena allocator](https://github.com/marflo-lang/m-language/blob/master/src/utils/allocator.c): `src/utils/allocator.c`
- [Diagnostics](https://github.com/marflo-lang/m-language/blob/master/src/utils/err.c): `src/utils/err.c`
- [Value printing](https://github.com/marflo-lang/m-language/blob/master/src/utils/print.h): `src/utils/print.h`
- [Common definitions](https://github.com/marflo-lang/m-language/blob/master/include/common.h): `include/common.h`
- [Language definitions](https://github.com/marflo-lang/m-language/blob/master/include/m.h): `include/m.h`
- [Runtime configuration](https://github.com/marflo-lang/m-language/blob/master/include/mconfig.h): `include/mconfig.h`
- [Debug assertions](https://github.com/marflo-lang/m-language/blob/master/include/mdebug.h): `include/mdebug.h`

### Other components

- **Script user**

## Connections

- Script user → CLI commands: provides script (evidence: `src/cli/cli.c`)
- CLI commands → Lexer: tokenizes source (evidence: `src/cli/cli.c`)
- CLI commands → Parser: parses tokens (evidence: `src/cli/cli.c`)
- CLI commands → IR compiler: compiles syntax (evidence: `src/cli/cli.c`)
- CLI commands → Bytecode generator: generates bytecode (evidence: `src/cli/cli.c`)
- CLI commands → VM stack API: formats result (evidence: `src/cli/cli.c`)
- Parser → AST types: builds syntax
- IR compiler → Bytecode generator: provides IR
- Bytecode generator → Bytecode VM: creates VM chunk
- Bytecode VM → Values and objects: operates on values (evidence: `src/vm/vm.c`)
- Bytecode VM → VM stack API: uses stack (evidence: `src/vm/vm.c`)
- Bytecode VM → Runtime errors: reports runtime faults (evidence: `src/vm/merror.c`)
- Bytecode VM → Diagnostics: reports diagnostics (evidence: `src/utils/err.c`)
- Values and objects → Debug assertions: uses assertions (evidence: `src/vm/mobjects.c`)
- VM stack API → Values and objects: manipulates values (evidence: `src/vm/mstack.c`)
- Bytecode VM → Value operations: uses value helpers
- Arena allocator → Diagnostics: reports allocation failures (evidence: `src/utils/allocator.c`)
- Lexer → Diagnostics: reports lexical errors (evidence: `src/frontend/lexer.c`)
- Parser → Diagnostics: reports syntax errors (evidence: `src/frontend/parser.c`)
- IR compiler → Diagnostics: reports compile errors (evidence: `src/backend/compiler.c`)
- CLI commands → Value printing: prints output (evidence: `src/cli/cli.c`)
- Debug assertions → Common definitions: uses definitions (evidence: `include/mdebug.h`)
- Values and objects → Runtime configuration: uses limits
- Language definitions → Runtime configuration: sets runtime types
