fax-lang 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.md +31 -0
  2. package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  3. package/.github/PULL_REQUEST_TEMPLATE.md +22 -0
  4. package/.github/workflows/ci.yml +33 -0
  5. package/.github/workflows/docs.yml +49 -0
  6. package/.nojekyll +0 -0
  7. package/CNAME +1 -0
  8. package/LICENSE +21 -0
  9. package/Makefile +37 -0
  10. package/README.md +97 -0
  11. package/assets/logo.svg +51 -0
  12. package/book/.nojekyll +0 -0
  13. package/book/book.toml +14 -0
  14. package/book/src/README.md +20 -0
  15. package/book/src/SUMMARY.md +26 -0
  16. package/book/src/concepts/internals.md +15 -0
  17. package/book/src/concepts/life_force.md +41 -0
  18. package/book/src/concepts/shadow_mirroring.md +33 -0
  19. package/book/src/concepts/state_machines.md +49 -0
  20. package/book/src/concepts/the_four_rules.md +18 -0
  21. package/book/src/concepts/unified_memory.md +19 -0
  22. package/book/src/guide/control_flow.md +44 -0
  23. package/book/src/guide/functions.md +23 -0
  24. package/book/src/guide/getting_started.md +28 -0
  25. package/book/src/guide/installation.md +50 -0
  26. package/book/src/guide/types.md +1 -0
  27. package/book/src/guide/variables.md +40 -0
  28. package/book/src/logo.svg +51 -0
  29. package/book/src/syntax.md +3023 -0
  30. package/dist/index.js +88 -0
  31. package/dist/modules/analysis/checker.js +142 -0
  32. package/dist/modules/analysis/memory-manager.js +76 -0
  33. package/dist/modules/analysis/scopes/scope-manager.js +26 -0
  34. package/dist/modules/backend/native/arm64.js +28 -0
  35. package/dist/modules/backend/native/codegen.js +65 -0
  36. package/dist/modules/backend/native/elf.js +57 -0
  37. package/dist/modules/codegen/index.js +244 -0
  38. package/dist/modules/lexer/constants/keywords.js +36 -0
  39. package/dist/modules/lexer/index.js +300 -0
  40. package/dist/modules/lexer/types.js +80 -0
  41. package/dist/modules/llvm/builder.js +73 -0
  42. package/dist/modules/llvm/module.js +39 -0
  43. package/dist/modules/llvm/types.js +22 -0
  44. package/dist/modules/parser/ast/nodes.js +16 -0
  45. package/dist/modules/parser/index.js +413 -0
  46. package/dist/shared/errors/compiler-error.js +16 -0
  47. package/dist/shared/logger/error-reporter.js +41 -0
  48. package/dist/shared/logger/index.js +45 -0
  49. package/examples/advanced.fx +14 -0
  50. package/examples/complex_sm.fx +7 -0
  51. package/examples/conn.fx +7 -0
  52. package/examples/fail_sm.fx +7 -0
  53. package/examples/hello_fn.fx +8 -0
  54. package/examples/logic.fx +4 -0
  55. package/examples/logic_if.fx +8 -0
  56. package/examples/loop_test +0 -0
  57. package/examples/mvp.fx +3 -0
  58. package/examples/shadow_exhaustion.fx +17 -0
  59. package/examples/tests/any_test.fx +22 -0
  60. package/examples/tests/exhaustion_error.fx +6 -0
  61. package/examples/tests/exhaustion_test.fx +14 -0
  62. package/examples/tests/loop_test.fx +13 -0
  63. package/examples/tests/mut_error.fx +4 -0
  64. package/examples/tests/mut_test.fx +3 -0
  65. package/examples/tests/rules_test.fx +15 -0
  66. package/examples/tests/shadow_mut_error.fx +5 -0
  67. package/examples/tests/shadow_test.fx +12 -0
  68. package/examples/tests/vulnerability_test.fx +3 -0
  69. package/index.html +176 -0
  70. package/install.sh +120 -0
  71. package/package.json +45 -0
  72. package/site/.nojekyll +0 -0
  73. package/site/logo.svg +51 -0
  74. package/src/index.ts +102 -0
  75. package/src/modules/analysis/checker.ts +211 -0
  76. package/src/modules/analysis/memory-manager.ts +216 -0
  77. package/src/modules/analysis/scopes/scope-manager.ts +28 -0
  78. package/src/modules/backend/native/arm64.ts +51 -0
  79. package/src/modules/backend/native/codegen.ts +92 -0
  80. package/src/modules/backend/native/elf.ts +87 -0
  81. package/src/modules/codegen/index.ts +264 -0
  82. package/src/modules/lexer/constants/keywords.ts +37 -0
  83. package/src/modules/lexer/index.ts +297 -0
  84. package/src/modules/lexer/types.ts +98 -0
  85. package/src/modules/llvm/builder.ts +100 -0
  86. package/src/modules/llvm/module.ts +60 -0
  87. package/src/modules/llvm/types.ts +56 -0
  88. package/src/modules/parser/ast/nodes.ts +30 -0
  89. package/src/modules/parser/index.ts +407 -0
  90. package/src/shared/errors/compiler-error.ts +24 -0
  91. package/src/shared/logger/error-reporter.ts +50 -0
  92. package/src/shared/logger/index.ts +56 -0
  93. package/src/types.d.ts +0 -0
  94. package/tests/lexer.test.ts +104 -0
  95. package/tests/test-runner.ts +75 -0
  96. package/tsconfig.json +35 -0
@@ -0,0 +1,31 @@
1
+ ---
2
+ name: Bug Report
3
+ about: Create a report to help us improve
4
+ title: '[BUG] '
5
+ labels: bug
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Describe the bug**
11
+ A clear and concise description of what the bug is.
12
+
13
+ **To Reproduce**
14
+ Steps to reproduce the behavior:
15
+ 1. Create a file with code '...'
16
+ 2. Run 'fax build file.fx'
17
+ 3. See error
18
+
19
+ **Expected behavior**
20
+ A clear and concise description of what you expected to happen.
21
+
22
+ **Screenshots/Logs**
23
+ If applicable, add screenshots or compiler logs to help explain your problem.
24
+
25
+ **Environment:**
26
+ - OS: [e.g. Linux, macOS]
27
+ - Node version: [e.g. 20.x]
28
+ - LLVM version: [e.g. 18]
29
+
30
+ **Additional context**
31
+ Add any other context about the problem here.
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: Feature Request
3
+ about: Suggest an idea for Fax-lang
4
+ title: '[FEAT] '
5
+ labels: enhancement
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Is your feature request related to a problem? Please describe.**
11
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12
+
13
+ **Describe the solution you'd like**
14
+ A clear and concise description of what you want to happen.
15
+
16
+ **Describe alternatives you've considered**
17
+ A clear and concise description of any alternative solutions or features you've considered.
18
+
19
+ **Additional context**
20
+ Add any other context or screenshots about the feature request here.
@@ -0,0 +1,22 @@
1
+ ## Description
2
+ Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context.
3
+
4
+ Fixes # (issue)
5
+
6
+ ## Type of change
7
+ - [ ] Bug fix (non-breaking change which fixes an issue)
8
+ - [ ] New feature (non-breaking change which adds functionality)
9
+ - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
10
+ - [ ] Documentation update
11
+
12
+ ## How Has This Been Tested?
13
+ Please describe the tests that you ran to verify your changes.
14
+
15
+ ## Checklist:
16
+ - [ ] My code follows the style guidelines of this project
17
+ - [ ] I have performed a self-review of my own code
18
+ - [ ] I have commented my code, particularly in hard-to-understand areas
19
+ - [ ] I have made corresponding changes to the documentation
20
+ - [ ] My changes generate no new warnings
21
+ - [ ] I have added tests that prove my fix is effective or that my feature works
22
+ - [ ] New and existing unit tests pass locally with my changes
@@ -0,0 +1,33 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+
15
+ - name: Setup Node.js
16
+ uses: actions/setup-node@v4
17
+ with:
18
+ node-version: '20'
19
+ cache: 'npm'
20
+
21
+ - name: Install LLVM
22
+ run: |
23
+ sudo apt-get update
24
+ sudo apt-get install -y llvm clang lld
25
+
26
+ - name: Install Dependencies
27
+ run: npm install
28
+
29
+ - name: Lint
30
+ run: npm run lint
31
+
32
+ - name: Run Tests
33
+ run: npm test
@@ -0,0 +1,49 @@
1
+ name: Deploy Docs
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ paths:
7
+ - 'book/**'
8
+ - '.github/workflows/docs.yml'
9
+
10
+ permissions:
11
+ contents: read
12
+ pages: write
13
+ id-token: write
14
+
15
+ jobs:
16
+ deploy-docs:
17
+ environment:
18
+ name: github-pages
19
+ url: ${{ steps.deployment.outputs.page_url }}
20
+ runs-on: ubuntu-latest
21
+ steps:
22
+ - uses: actions/checkout@v4
23
+
24
+ - name: Setup Rust
25
+ uses: dtolnay/rust-toolchain@stable
26
+
27
+ - name: Install mdBook
28
+ run: |
29
+ mkdir bin
30
+ curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.37/mdbook-v0.4.37-x86_64-unknown-linux-gnu.tar.gz | tar -xz -C bin
31
+ echo "$(pwd)/bin" >> $GITHUB_PATH
32
+
33
+ - name: Build Documentation
34
+ run: |
35
+ mdbook build book
36
+ # Copy the root landing page and assets into the site folder for deployment
37
+ cp index.html site/
38
+ cp -r assets site/
39
+ # Ensure .nojekyll exists
40
+ touch site/.nojekyll
41
+
42
+ - name: Upload artifact
43
+ uses: actions/upload-pages-artifact@v3
44
+ with:
45
+ path: site
46
+
47
+ - name: Deploy to GitHub Pages
48
+ id: deployment
49
+ uses: actions/deploy-pages@v4
package/.nojekyll ADDED
File without changes
package/CNAME ADDED
@@ -0,0 +1 @@
1
+ fax-lang.js.org
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Luvion1
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/Makefile ADDED
@@ -0,0 +1,37 @@
1
+ # Fax-lang Makefile
2
+
3
+ PREFIX ?= /usr/local
4
+ BINDIR = $(PREFIX)/bin
5
+
6
+ .PHONY: all build test clean install uninstall docs
7
+
8
+ all: build
9
+
10
+ build:
11
+ npm run build
12
+
13
+ test:
14
+ npm test
15
+
16
+ clean:
17
+ rm -rf dist/
18
+ find . -name "*.tmp.ll" -delete
19
+ find . -name "*.tmp.o" -delete
20
+ rm -f examples/mvp examples/logic examples/logic_if
21
+
22
+ docs-serve:
23
+ cd book && mdbook serve --open
24
+
25
+ docs-build:
26
+ cp assets/logo.svg book/src/logo.svg
27
+ cd book && mdbook build
28
+
29
+ install: build
30
+ mkdir -p $(BINDIR)
31
+ cp dist/index.js $(BINDIR)/fax
32
+ chmod +x $(BINDIR)/fax
33
+ @echo "Fax-lang installed to $(BINDIR)/fax"
34
+
35
+ uninstall:
36
+ rm -f $(BINDIR)/fax
37
+ @echo "Fax-lang removed."
package/README.md ADDED
@@ -0,0 +1,97 @@
1
+ <p align="center">
2
+ <img src="assets/logo.svg" width="180" height="180" />
3
+ </p>
4
+
5
+ <h1 align="center">Fax-lang</h1>
6
+
7
+ <p align="center">
8
+ <strong>A Modern Systems Programming Language with Life-Force Memory Management</strong>
9
+ </p>
10
+
11
+ <p align="center">
12
+ <a href="https://github.com/Luvion1/Fax-lang/actions"><img src="https://github.com/Luvion1/Fax-lang/workflows/CI/badge.svg" alt="CI Status"></a>
13
+ <a href="https://github.com/Luvion1/Fax-lang/actions"><img src="https://github.com/Luvion1/Fax-lang/workflows/Deploy%20Docs/badge.svg" alt="Docs Status"></a>
14
+ <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License"></a>
15
+ </p>
16
+
17
+ ---
18
+
19
+ ## 🦊 What is Fax-lang?
20
+
21
+ Fax-lang is a high-performance systems programming language built on top of LLVM. It introduces a revolutionary approach to memory safety called **Life-Force Tracking**, allowing for deterministic memory management without the overhead of a Garbage Collector or the complexity of a traditional Borrow Checker.
22
+
23
+ ## ✨ Core Pillars
24
+
25
+ ### 1. Life-Force Memory System (Rule 2)
26
+ Every variable is born with "energy" that decays through usage.
27
+ - **Read**: -0.02 | **Write**: -0.08
28
+ - When life-force reaches zero, the variable is automatically reclaimed. This ensures memory safety through a deterministic, usage-based lifecycle.
29
+
30
+ ### 2. Contractual State Machines (Rule 4)
31
+ State machines are first-class citizens. Transitions are verified at compile-time to prevent illegal states.
32
+ ```fax
33
+ state_machine Connection {
34
+ state Closed {
35
+ fn connect() -> Connecting { ... }
36
+ }
37
+ }
38
+ ```
39
+
40
+ ### 3. Shadow & Mirroring (Rule 1)
41
+ Manage data access via **Shadows** (read-only views) that lazily create **Mirrors** only for modified segments, optimizing cache locality and performance.
42
+
43
+ ### 4. Unified Memory Space (Rule 3)
44
+ The compiler automatically analyzes access patterns to decide whether data should reside on the **Stack**, **Heap**, or a **Hybrid** of both.
45
+
46
+ ---
47
+
48
+ ## 🛠 Getting Started
49
+
50
+ ### Prerequisites
51
+ - **Node.js** (v18 or newer)
52
+ - **LLVM** (llc & clang v14/18)
53
+
54
+ ### Installation
55
+ ```bash
56
+ git clone https://github.com/Luvion1/Fax-lang.git
57
+ cd Fax-lang
58
+ npm install
59
+ ```
60
+
61
+ ---
62
+
63
+ ## 🚀 Usage
64
+
65
+ ### Compiling Programs
66
+ ```bash
67
+ # Build a binary from a .fx file
68
+ npm run dev build examples/mvp.fx
69
+
70
+ # Execute the output
71
+ ./examples/mvp
72
+ ```
73
+
74
+ ### AST Visualization
75
+ ```bash
76
+ npm run dev ast examples/mvp.fx
77
+ ```
78
+
79
+ ---
80
+
81
+ ## 📖 Documentation
82
+ The official documentation is built with **mdBook** and is available in the `book/` directory.
83
+
84
+ To serve documentation locally:
85
+ ```bash
86
+ cd book
87
+ mdbook serve --open
88
+ ```
89
+
90
+ ## 🤝 Contributing
91
+ Contributions are welcome! Please feel free to submit a Pull Request or open an Issue to discuss potential changes.
92
+
93
+ ---
94
+
95
+ <p align="center">
96
+ Built with ❤️ by <a href="https://github.com/Luvion1">Luvion1</a>
97
+ </p>
@@ -0,0 +1,51 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
2
+ <defs>
3
+ <linearGradient id="kawaiiGrad" x1="0%" y1="0%" x2="0%" y2="100%">
4
+ <stop offset="0%" style="stop-color:#FFB347;stop-opacity:1" />
5
+ <stop offset="100%" style="stop-color:#FF8C00;stop-opacity:1" />
6
+ </linearGradient>
7
+ </defs>
8
+
9
+ <!-- Soft Shadow for Kawaii Sticker Look -->
10
+ <circle cx="256" cy="270" r="230" fill="#000" opacity="0.05"/>
11
+
12
+ <!-- Fluffy Big Tail -->
13
+ <path d="M360 300c60-20 120 20 120 90s-50 100-110 100-90-40-90-80c0-50 40-90 80-110z" fill="#FF8C00" />
14
+ <path d="M480 390c0 40-30 70-70 80 20-10 40-30 40-50s-10-40-40-50c40 10 70 20 70 20z" fill="#FFFFFF" />
15
+
16
+ <!-- Round Chibi Body -->
17
+ <circle cx="256" cy="380" r="100" fill="url(#kawaiiGrad)" />
18
+ <path d="M256 460c-40 0-70-20-70-50s30-20 70-20 70 10 70 20-30 50-70 50z" fill="#FFFFFF" opacity="0.8"/>
19
+
20
+ <!-- Oversized Kawaii Head -->
21
+ <circle cx="256" cy="220" r="160" fill="url(#kawaiiGrad)" />
22
+
23
+ <!-- Big Rounded Ears -->
24
+ <path d="M140 100l-50-60c-10-15 15-20 25-10l65 50" fill="#FF8C00" stroke="#E67E22" stroke-width="8" stroke-linejoin="round"/>
25
+ <path d="M372 100l50-60c10-15-15-20-25-10l-65 50" fill="#FF8C00" stroke="#E67E22" stroke-width="8" stroke-linejoin="round"/>
26
+ <path d="M150 90l-20-25c-3-4 5-8 8-4l30 20" fill="#FFD1DC"/>
27
+ <path d="M362 90l20-25c3-4-5-8-8-4l-30 20" fill="#FFD1DC"/>
28
+
29
+ <!-- Fluffy White Cheeks -->
30
+ <path d="M110 240c0 50 60 80 146 80s146-30 146-80-60-60-146-60-146 10-146 60z" fill="#FFFFFF"/>
31
+
32
+ <!-- Large Sparkling Kawaii Eyes -->
33
+ <g>
34
+ <circle cx="180" cy="230" r="40" fill="#2C3E50"/>
35
+ <circle cx="165" cy="215" r="15" fill="#FFFFFF"/>
36
+ <circle cx="195" cy="245" r="7" fill="#FFFFFF" opacity="0.6"/>
37
+ </g>
38
+ <g>
39
+ <circle cx="332" cy="230" r="40" fill="#2C3E50"/>
40
+ <circle cx="317" cy="215" r="15" fill="#FFFFFF"/>
41
+ <circle cx="347" cy="245" r="7" fill="#FFFFFF" opacity="0.6"/>
42
+ </g>
43
+
44
+ <!-- Blush (Pink Ovals) -->
45
+ <ellipse cx="120" cy="280" rx="30" ry="18" fill="#FFB6C1" opacity="0.7"/>
46
+ <ellipse cx="392" cy="280" rx="30" ry="18" fill="#FFB6C1" opacity="0.7"/>
47
+
48
+ <!-- Tiny Nose and 'w' Mouth -->
49
+ <path d="M256 250l-6 8h12z" fill="#1a1a1b"/>
50
+ <path d="M230 275c10 10 20 10 26 0s16 10 26 0" fill="none" stroke="#1a1a1b" stroke-width="4" stroke-linecap="round"/>
51
+ </svg>
package/book/.nojekyll ADDED
File without changes
package/book/book.toml ADDED
@@ -0,0 +1,14 @@
1
+ [book]
2
+ authors = ["Luvion1"]
3
+ language = "en"
4
+ src = "src"
5
+ title = "The Fax-lang Book"
6
+
7
+ [build]
8
+ build-dir = "../site/book"
9
+
10
+ [output.html]
11
+ git-repository-url = "https://github.com/Luvion1/Fax-lang"
12
+ edit-url-template = "https://github.com/Luvion1/Fax-lang/edit/main/book/{path}"
13
+
14
+ [preprocessor.links]
@@ -0,0 +1,20 @@
1
+ # Introduction to Fax-lang
2
+
3
+ <img src="logo.svg" alt="Fax Logo" width="100">
4
+
5
+ Welcome to the **Fax Programming Language** documentation.
6
+
7
+ Fax is a systems programming language designed for **extreme memory safety** and **deterministic state transitions** without a garbage collector or traditional borrow checker.
8
+
9
+ ## Core Philosophy
10
+
11
+ Fax-lang is built on four fundamental pillars:
12
+
13
+ 1. **Contractual State Machines**: State transitions are first-class citizens and are verified at compile-time.
14
+ 2. **Life-Force Tracking**: Every variable has an "energy" level that decays with usage, preventing over-use and ensuring deterministic cleanup.
15
+ 3. **Shadow & Mirroring**: Data access is managed through read-only views (shadows) that lazily create mirrors for modifications.
16
+ 4. **Unified Memory Space**: The compiler automatically decides whether data lives on the stack, heap, or a hybrid of both based on access patterns.
17
+
18
+ ## Why Fax?
19
+
20
+ Traditional languages either use garbage collection (which introduces latency) or manual memory management/borrow checking (which can be complex). Fax-lang introduces a **probabilistic yet deterministic** approach to memory safety through the concept of **Life-Force**.
@@ -0,0 +1,26 @@
1
+ # Summary
2
+
3
+ [Introduction](README.md)
4
+
5
+ - [Getting Started](guide/getting_started.md)
6
+ - [Installation](guide/installation.md)
7
+
8
+ # Language Basics
9
+
10
+ - [Variables & Mutability](guide/variables.md)
11
+ - [Data Types](guide/types.md)
12
+ - [Functions](guide/functions.md)
13
+ - [Control Flow](guide/control_flow.md)
14
+
15
+ # Advanced Concepts
16
+
17
+ - [The Four Rules](concepts/the_four_rules.md)
18
+ - [State Machines (Contractual States)](concepts/state_machines.md)
19
+ - [Memory Management: Life-Force](concepts/life_force.md)
20
+ - [Shadow & Mirroring](concepts/shadow_mirroring.md)
21
+ - [Unified Memory Space](concepts/unified_memory.md)
22
+
23
+ ---
24
+
25
+ - [Compiler Internals](concepts/internals.md)
26
+ - [Syntax Reference](syntax.md)
@@ -0,0 +1,15 @@
1
+ # Compiler Internals
2
+
3
+ The Fax-lang compiler is built with a modular architecture using TypeScript and LLVM.
4
+
5
+ ## Compilation Pipeline
6
+
7
+ 1. **Lexer**: Tokenizes the source code.
8
+ 2. **Parser**: Generates an Abstract Syntax Tree (AST).
9
+ 3. **Semantic Checker**: Validates memory rules (Life-Force, State Transitions).
10
+ 4. **Code Generator**: Produces LLVM IR (`.ll` files).
11
+ 5. **LLVM Backend**: `llc` converts IR to object files, and `clang` links them to a native binary.
12
+
13
+ ## Unique Checks
14
+
15
+ The **Semantic Checker** is the heart of Fax-lang. It maintains a metadata map of every variable to track its energy level and current state machine status at compile-time.
@@ -0,0 +1,41 @@
1
+ # Memory Management: Life-Force
2
+
3
+ The most unique feature of Fax-lang is its **Life-Force** system (Rule 2).
4
+
5
+ ## What is Life-Force?
6
+
7
+ Every variable in Fax-lang is born with a life-force of `1.0`. As you use the variable, its life-force decays.
8
+
9
+ - **Read Access**: Decays by `0.02`.
10
+ - **Write Access**: Decays by `0.08`.
11
+ - **Heavy Operations**: Decays by `0.15`.
12
+
13
+ When a variable's life-force reaches `0.0`, the variable is considered **exhausted** and can no longer be accessed.
14
+
15
+ ## Why this system?
16
+
17
+ This system prevents "hot-spot" memory access from becoming bottlenecks and encourages efficient code. It also provides a unique way to handle cleanup: when life-force is depleted, the compiler can deterministically schedule memory reclamation.
18
+
19
+ ## Boosting Life-Force
20
+
21
+ You can "boost" a variable's life-force through certain operations, representing the "feeding" of data back into the hot path of the application.
22
+
23
+ ```fax
24
+ let x = 10;
25
+ // After many reads, x is low on energy.
26
+ // The compiler tracks this semantically.
27
+ ```
28
+
29
+ ## Compilation Errors
30
+
31
+ If you attempt to access a variable that the compiler determines *could* be exhausted, it will throw an `E002` error:
32
+
33
+ ```text
34
+ error[E002]: variable `x` has been exhausted
35
+ --> main.fx:10:5
36
+ |
37
+ 10 | let y = x;
38
+ | ^~
39
+ |
40
+ = help: Energy depleted. Reading from this variable costs 0.02 Life-Force.
41
+ ```
@@ -0,0 +1,33 @@
1
+ # Shadow & Mirroring
2
+
3
+ Fax-lang implements **Rule 1: Shadow & Mirroring with Page-based Copy**. This is a high-performance alternative to traditional Copy-on-Write (CoW).
4
+
5
+ ## Shadows
6
+
7
+ A `shadow` is a read-only view of a variable. It shares the same **Life-Force** as the original variable.
8
+
9
+ ```fax
10
+ let mut x = BigData::new();
11
+ shadow y = x; // y is a read-only view of x
12
+ ```
13
+
14
+ - Shadows are **read-only**.
15
+ - Shadows share the energy consumption of the source.
16
+ - Shadows do not move or copy data upon creation.
17
+
18
+ ## Mirroring (Differential Copy)
19
+
20
+ When data is modified through a shadow (in more complex data structures like structs), Fax-lang uses **Differential Mirroring**.
21
+
22
+ Unlike traditional CoW which might copy an entire object or large buffer, Fax-lang's mirroring works on a **page-level** (typically 4KB).
23
+
24
+ 1. **Access Tracking**: The compiler tracks which segments of the data are accessed through the shadow.
25
+ 2. **Lazy Mirroring**: Only when a segment is actually modified does the compiler create a "Mirror" of that specific page.
26
+ 3. **Reconciliation**: When the shadow is merged back or the original data is updated, only the mirrored pages are synchronized.
27
+
28
+ This optimization ensures that even with massive data structures, small updates remain constant-time and cache-friendly.
29
+
30
+ ## Why not just use References?
31
+
32
+ References in other languages often require complex lifetime tracking (like Rust) or garbage collection (like Java). Shadows provide a middle ground: they are safe, read-only views that are semantically tied to the original data's life-cycle, without the overhead of tracking every pointer's validity.
33
+
@@ -0,0 +1,49 @@
1
+ # State Machines (Contractual States)
2
+
3
+ Fax-lang treats state machines as first-class citizens (Rule 4).
4
+
5
+ ## Definition
6
+
7
+ A state machine is defined using the `state_machine` keyword. Unlike simple enums, Fax-lang state machines enforce **valid transitions** at compile-time.
8
+
9
+ ```fax
10
+ state_machine Connection {
11
+ state Closed {
12
+ fn connect() -> Connecting {
13
+ // transition logic
14
+ }
15
+ }
16
+
17
+ state Connecting {
18
+ fn established() -> Connected { ... }
19
+ fn timeout() -> Closed { ... }
20
+ }
21
+
22
+ state Connected {
23
+ fn disconnect() -> Closed { ... }
24
+ }
25
+ }
26
+ ```
27
+
28
+ ## The `any` Block
29
+
30
+ The `any` block allows you to define transitions that are valid from **any** state. This is useful for error handling or global resets.
31
+
32
+ ```fax
33
+ any {
34
+ fn emergency_shutdown() -> Closed {
35
+ // cleanup
36
+ }
37
+ }
38
+ ```
39
+
40
+ ## Compile-time Safety
41
+
42
+ The Fax-lang compiler ensures that you cannot call a transition function if the machine is not in the correct state.
43
+
44
+ ```fax
45
+ let conn = Connection::Closed::new();
46
+ conn.established(); // ERROR: 'established' is only valid in 'Connecting' state.
47
+ ```
48
+
49
+ This prevents a whole class of bugs related to illegal state transitions in systems programming.
@@ -0,0 +1,18 @@
1
+ # The Four Rules of Fax-lang
2
+
3
+ Fax-lang is built upon four fundamental rules that govern memory, state, and execution. These rules ensure performance and safety without a traditional garbage collector or complex borrow checker.
4
+
5
+ ## Rule 1: Shadow & Mirroring (Differential Copy)
6
+ Data access is managed through read-only **Shadows**. When a modification is requested, instead of copying the entire data structure, the compiler creates a **Mirror** of only the modified segments (pages).
7
+
8
+ ## Rule 2: Life-Force (Adaptive Decay)
9
+ Every variable has an energy level called **Life-Force**.
10
+ - Accessing data consumes Life-Force.
11
+ - When Life-Force reaches zero, the variable is exhausted.
12
+ - This enforces efficient access patterns and enables deterministic cleanup.
13
+
14
+ ## Rule 3: Unified Memory Space (Context-Agnostic Allocation)
15
+ The compiler, not the developer, decides where data lives (Stack, Heap, or Hybrid). This decision is based on the data's size, lifetime, and access frequency, optimizing for cache locality automatically.
16
+
17
+ ## Rule 4: Contractual States (State Machines)
18
+ State machines are first-class citizens. Transitions are checked at compile-time, ensuring that a resource can only be used when it is in a valid state. This replaces many runtime checks and complex error handling logic.
@@ -0,0 +1,19 @@
1
+ # Unified Memory Space
2
+
3
+ Fax-lang employs **Rule 3: Context-Agnostic Allocation**.
4
+
5
+ ## The Concept
6
+
7
+ In traditional systems languages, the developer must explicitly choose between the Stack and the Heap. Fax-lang removes this cognitive load by analyzing data usage patterns at compile-time.
8
+
9
+ ## How it Works
10
+
11
+ The compiler builds an **Access Graph** for every variable:
12
+
13
+ 1. **Stack Placement**: Small data (≤ 64 bytes) with short lifetimes and high-frequency access.
14
+ 2. **Heap Placement**: Large data structures or variables that must persist beyond the current scope.
15
+ 3. **Hybrid Placement**: A unique Fax-lang feature where "hot" parts of a structure stay on the stack for speed, while "cold" or large parts are transparently moved to the heap.
16
+
17
+ ## Topology Optimization
18
+
19
+ The Unified Allocator also considers cache locality. If two variables are frequently accessed together, the compiler will attempt to place them in adjacent memory locations to minimize cache misses.
@@ -0,0 +1,44 @@
1
+ # Control Flow
2
+
3
+ Fax-lang provides standard control flow structures, but many of them function as **expressions**.
4
+
5
+ ## If Expressions
6
+
7
+ In Fax-lang, `if` is an expression, meaning it returns a value.
8
+
9
+ ```fax
10
+ let x = 10;
11
+ let y = 20;
12
+
13
+ let result = if x > y {
14
+ x
15
+ } else {
16
+ y
17
+ };
18
+ ```
19
+
20
+ ## Loops
21
+
22
+ ### While Loop
23
+ The `while` loop continues as long as a condition is met. Note that every operation inside the loop consumes **Life-Force** from the involved variables.
24
+
25
+ ```fax
26
+ let mut i = 0;
27
+ while i < 10 {
28
+ i = i + 1;
29
+ }
30
+ ```
31
+
32
+ ## Match Expressions (Experimental)
33
+
34
+ > **Note:** `match` expressions are currently in the experimental phase and may not be fully supported by all backends.
35
+
36
+ `match` provides powerful pattern matching, especially useful when working with **State Machines** or Enums.
37
+
38
+ ```fax
39
+ match connection_state {
40
+ Closed => println("Retry?"),
41
+ Connected => println("Online"),
42
+ _ => println("Unknown")
43
+ }
44
+ ```