Flowa Architecture
Understanding Flowa's internal architecture helps you write better code and debug issues.
Compiler Pipeline
1. Lexer (lexer.cpp)
Tokenizes source code into tokens:
- Keywords (
let,func,if) - Identifiers (variable names)
- Literals (strings, numbers)
- Operators (
+,-,==)
2. Parser (parser.cpp)
Builds Abstract Syntax Tree (AST) using recursive descent parsing:
- Expressions
- Statements
- Blocks
3. AST (ast.cpp)
Represents program structure as tree nodes.
4. Constant Folder (constant_folder.cpp)
Optimizes constant expressions at compile time:
let x = 2 + 3; // Compiled as: let x = 5;5. Bytecode Compiler (compiler.cpp)
Converts AST to bytecode instructions.
6. Bytecode (bytecode.cpp)
Low-level instructions for the runtime:
OP_LOAD_CONSTOP_CALLOP_RETURN
Runtime Execution
Memory Manager (memory_manager.cpp)
- Heap allocation
- Reference counting
- Garbage collection
Object System (object.h)
Object types:
- Strings
- Numbers
- Arrays
- Hashes
- funcs
Environment (environment.h)
Stores variable bindings for scope management.
JIT Compiler (jit/compiler.cpp)
Translates hot bytecode paths to native x64/arm64 machine code:
- Hot Path Detection: Identifies frequently executed code
- Code Generation: Produces native instructions
- Register Allocation: Optimizes register usage
- Execution: Runs compiled native code
JIT Executor (jit/executor.cpp)
Executes compiled native code with register allocation.
JIT Assembler (jit/assembler.cpp)
Generates native machine instructions (x64/arm64).
Event Loop (event_loop.cpp)
Manages:
- Asynchronous operations
- HTTP server requests
- Concurrent tasks
Scheduler (scheduler.cpp)
Schedules and executes tasks with priority queues:
- Cron jobs
- Periodic tasks
- Event handlers
Module System
All modules are implemented as C++ builtins:
- Registration:
builtins.cppregisters module funcs - Implementation: Each module in dedicated source files
- Global Access: Modules accessible globally (
fs.readFile()) - Dynamic Loading: Module loader for runtime loading
Built-in Modules
builtins_file.cpp- File system operationsbuiltins_json.cpp- JSON parsing/stringifyingbuiltins_auth.cpp- Bcrypt hashingbuiltins_jwt.cpp- JWT tokensbuiltins_mail.cpp- SMTP emailbuiltins_sqlite.cpp- SQLite databasebuiltins_http.cpp- HTTP server/clientbuiltins_cron.cpp- Job schedulingbuiltins_log.cpp- Structured loggingbuiltins_os.cpp- OS interaction
Concurrency Model
Actor Model
Message-passing between actors for safe parallelism.
Event Loop
Non-blocking I/O with event queue.
Task System (task.cpp)
Schedulable units of work.
Execution Flow
Source Code
↓
[Lexer] → Tokens
↓
[Parser] → AST
↓
[Compiler] → Bytecode
↓
[Runtime] → Execution
↓
[JIT] → Native Code (hot paths)Performance Optimizations
- JIT Compilation: Hot code → native machine code
- Constant Folding: Compile-time evaluation
- Register Allocation: Efficient CPU usage
- Reference Counting: Fast memory management
- Object Pooling: Reuse common objects
Development
Building from Source
git clone https://github.com/senapati484/flowa.git
cd flowa
./build.shProject Structure
flowa/
├── src/ # Source code
│ ├── lexer.cpp
│ ├── parser.cpp
│ ├── compiler.cpp
│ ├── jit/ # JIT compiler
│ └── builtins/ # Standard library
├── include/ # Headers
├── examples/ # Example programs
├── tests/ # Test suite
└── docs/ # DocumentationContributing
See the Contributing Guide (opens in a new tab).
Version Information
- Current Version: 0.1.6 (December 2025)
- Language: Flowa 0.1
- Runtime: C++17 bytecode interpreter with JIT
- Platforms: Linux, macOS (including Apple Silicon), Windows
Next Steps
- Performance - Optimization techniques
- Concurrency - Actor model patterns
- GitHub Repository (opens in a new tab) - Source code