⚡ The Fresh Programming Language
A modern, statically-typed compiled language featuring a Pratt parser, optimizing bytecode compiler, stack-based Virtual Machine with mark-and-sweep GC, native C transpilation, closures, pattern matching, and developer tooling.
📑 Table of Contents
- 🚀 Quickstart in 30 Seconds
- 🌟 Key Highlights & Language Design
- 🏗 Architecture & Compiler Pipeline
- 💻 Command-Line Interface (CLI)
- 🛠 VS Code Integration & 1-Click Execution
- 🧩 Feature Showcase & Code Examples
- 📂 Project Directory Structure
- 📚 Documentation Index
- 🧪 Running the Test Suite
- 📄 License
🚀 Quickstart in 30 Seconds
1. Installation
Clone the repository and install dependencies:
git clone https://github.com/CodeClosed/fresh-lang.git
cd fresh-lang
python -m pip install -e .
2. Write Your First Fresh Program
Create a file named hello.fresh:
// hello.fresh
fn greet(name: string) -> string {
return "Hello, " + name + "! Welcome to Fresh ⚡";
}
let message = greet("Developer");
println(message);
3. Run It!
You can run your program using any of these simple methods:
# Option A: Direct command (if installed via pip / venv / PATH)
fresh run hello.fresh
# Option B: Windows local repo wrapper (works immediately with zero setup)
.\fresh run hello.fresh
# Option C: Universal Python module (works on any machine/shell)
python -m fresh run hello.fresh
Windows Tip: If
freshis not recognized globally in your PowerShell, run this once:[Environment]::SetEnvironmentVariable("Path", [Environment]::GetEnvironmentVariable("Path", "User") + ";$env:APPDATA\Python\Python314\Scripts", "User")Or simply use
.\fresh run hello.fresh!
Output:
Hello, Developer! Welcome to Fresh ⚡
🌟 Key Highlights & Language Design
Fresh merges the expressive readability of modern languages with the predictable performance of a bytecode VM and C native code generator:
- Static Typing with Local Inference: Strict compile-time type verification with automatic type inference on
letbindings. - Top-Down Operator Precedence (Pratt Parser): Clean, robust expression parsing with exact precedence levels and recursion bounds.
- Visual Rust-Style Diagnostics: Clear underline markers and error codes (
[E1001]to[E4001]) for syntax and type errors. - First-Class Closures & Upvalues: Functions capture variables across scopes with state persistence.
- Pattern Matching with Guards: Powerful
matchexpressions supporting values, wildcards (_), and conditionalifguard clauses. - User-Defined Records & Structs: Strongly typed struct records with in-place mutable fields.
- Dynamic Arrays & Matrices: Native
[T]arrays withpush,pop,len, and multi-dimensional indexing. - Mark-and-Sweep Garbage Collection: Automatic memory management tracing stacks, upvalues, and globals with
FRESH_GC_STRESS=1allocation mode. - Native C Transpiler: Compiles Fresh code directly to readable C99 with 1:1 behavioral equivalence for native binary builds (
gcc,clang,msvc). - Complete Developer Tooling: Built-in formatter (
fresh fmt), package manager (fresh init/fresh build), type checker (fresh check), and REPL (fresh repl).
🏗 Architecture & Compiler Pipeline
Fresh uses a unified multi-stage pipeline:
graph TD
A["Source Code (.fresh)"] --> B["Scanner / Lexer"]
B -->|"Token Stream"| C["Pratt Parser"]
C -->|"Abstract Syntax Tree (AST)"| D["Module Loader & Cycle Checker"]
D -->|"Expanded AST"| E["Resolver & Scope Checker"]
E -->|"Scoped AST"| F["Type Checker & Inferrer"]
F -->|"Typed AST"| G["Bytecode Compiler"]
G -->|"Bytecode Chunk"| H["Peephole Optimizer"]
H -->|"Optimized Bytecode"| I["Virtual Machine (VM + GC)"]
I -->|"Runtime Output"| J["Program Result"]
F -.->|"Typed AST"| K["C99 Transpiler"]
K -.->|"Native C Source"| L["C Compiler (GCC / Clang)"]
L -.->|"Native Binary"| M["Standalone Executable"]
💻 Command-Line Interface (CLI)
The fresh CLI provides an all-in-one developer toolkit:
| Command | Usage | Description |
|---|---|---|
fresh run <file> |
fresh run main.fresh |
Compiles and executes a Fresh script on the Bytecode VM. |
fresh check <file> |
fresh check main.fresh |
Static analysis: checks types and resolves names without running. |
fresh fmt <file> |
fresh fmt main.fresh [--check] |
Formats source files idempotently according to standard Fresh style. |
fresh init <name> |
fresh init my_app |
Scaffolds a new project with directory structure and fresh.toml. |
fresh build [dir] |
fresh build . |
Builds the project entrypoint into a standalone native executable. |
fresh test [dir] |
fresh test tests/ |
Runs the automated pytest test suite. |
fresh repl |
fresh repl |
Starts an interactive Read-Eval-Print-Loop session. |
Compiler Inspection Flags
Inspect intermediate representations at any phase of compilation:
# Print token stream produced by lexical analysis
fresh run main.fresh --dump-tokens
# Print formatted Abstract Syntax Tree
fresh run main.fresh --dump-ast
# Print disassembled bytecode instructions & constant pool
fresh run main.fresh --disassemble
# Transpile Fresh AST directly into standalone C99 source code
fresh run main.fresh --emit-c
🛠 VS Code Integration & 1-Click Execution
The workspace includes ready-to-use VS Code configurations:
- Press
F5: Runs the currently active.freshfile in the integrated terminal. - Press
Ctrl + Shift + B: Executes the default build task (Fresh: Run Active File). - Command Palette (
Ctrl + Shift + P->Tasks: Run Task):Fresh: Run Active FileFresh: Type Check Active FileFresh: Format Active FileFresh: Run Test Suite
- Syntax Highlighting & File Icons: Included in
vscode-extension/.
🧩 Feature Showcase & Code Examples
Explore ready-to-run examples in the examples/ directory:
| Example File | Key Concept Demonstrated |
|---|---|
all_features.fresh |
Complete Tour: Primitives, closures, matrices, structs, pattern matching, stdlib, file I/O |
01_fibonacci.fresh |
Recursive function calls, conditional returns, arithmetic |
02_matrix_multiply.fresh |
2D dynamic arrays, nested loops, matrix multiplication |
03_quicksort.fresh |
In-place array mutation, indexing, partition algorithm |
04_closure_counter.fresh |
Lexical closures, upvalue mutation across multiple function calls |
05_calculator.fresh |
First-class functions, higher-order function dispatch |
06_inventory.fresh |
User-defined structs, field mutations, inventory calculations |
07_stress_suite.fresh |
End-to-end stress test across all core language features |
08_aggressive_suite.fresh |
Deep recursion (Ackermann), map/filter higher-order lambdas, pattern guards |
📂 Project Directory Structure
NEW_LANG/
├── all_features.fresh # Complete feature showcase script
├── LANGUAGE_GUIDE.md # Comprehensive language tutorial and handbook
├── README.md # Main project documentation (this file)
├── pyproject.toml # Python build metadata & tool configuration
├── docs/ # In-depth architectural documentation
│ ├── FRESH_SPECIFICATION.md # Formal EBNF grammar & normative specification
│ ├── project_guide.md # Architecture & contributor implementation guide
│ ├── COMPARISON.md # Academic comparison vs Rust, Go, Python, Lua, C
│ ├── PROS.md # Language design rationale and benefits
│ ├── COMPATIBILITY_AND_VERSIONING.md # Versioning & SemVer policy
│ └── production_release_guide.md # Packaging and release workflow
├── examples/ # Official runnable example programs
├── src/fresh/ # Fresh compiler & runtime core package
│ ├── analyzer/ # Semantic analysis (Resolver, Type Checker)
│ ├── codegen/ # Bytecode compiler, optimizer, and C transpiler
│ ├── common/ # Shared AST tokens, type definitions, error types
│ ├── lexer/ # Scanner and token definitions
│ ├── parser/ # Pratt expression parser and statement AST
│ ├── stdlib/ # Built-in functions and math library
│ ├── vm/ # Virtual machine, CallFrame, and Mark-and-Sweep GC
│ ├── cli.py # Command-line interface driver
│ ├── formatter.py # Canonical source code formatter
│ ├── modules.py # Multi-file module loader and cycle detector
│ ├── package.py # Package manager (init & build)
│ └── pipeline.py # Unified end-to-end execution pipeline
├── tests/ # 93 automated tests across all subsystems
└── vscode-extension/ # Official VS Code syntax highlighter & icons
📚 Documentation Index
For in-depth guides, check the dedicated documents:
- 📘 Language Guide (
LANGUAGE_GUIDE.md): Complete language tutorial from variables to closures and pattern matching. - 📐 Formal Specification (
docs/FRESH_SPECIFICATION.md): EBNF grammar, typing rules, and operational semantics. - 🏛 Architecture & Contributor Guide (
docs/project_guide.md): Deep-dive into compiler internals, AST structures, and VM bytecode engine. - ⚖️ Comparative Analysis (
docs/COMPARISON.md): Architectural comparison against Rust, Go, Python, Lua, and C. - 💡 Project Advantages & Design Rationale (
docs/PROS.md): Why Fresh was built and key architectural strengths. - 🚀 Production & Release Guide (
docs/production_release_guide.md): Wheel packaging, release checklist, and distribution.
🧪 Running the Test Suite
Run the full automated test suite containing unit, integration, differential, safety, and GC stress tests:
# Run all tests
pytest -v
# Run with test coverage report
pytest --cov=fresh --cov-report=term-missing
📄 License
Fresh is open-source software distributed under the terms of the MIT License.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fresh_lang-0.1.0.tar.gz.
File metadata
- Download URL: fresh_lang-0.1.0.tar.gz
- Upload date:
- Size: 603.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d3697e7123cb0bf780e97cd61d18421397cb77092843b16fccf43ec3dccf0b7
|
|
| MD5 |
93c6aa1ae9b7a2beb4d95d1c8e97c793
|
|
| BLAKE2b-256 |
2c1549b0b2d38e4549b522d572d88504ec5116d63a28ab5cdd197f5710f1103c
|
File details
Details for the file fresh_lang-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fresh_lang-0.1.0-py3-none-any.whl
- Upload date:
- Size: 72.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04fedea5bb06362eded92c59439b27e384660bb1bcb7dc9b7084fe0333b3a930
|
|
| MD5 |
a58999e2ac6b33f71092824d0d564183
|
|
| BLAKE2b-256 |
b7f1b34a48e52762741685028c351aaad8d8edabc7899d4d7d3f313b792160ea
|