A modern, statically-typed programming language with a bytecode virtual machine, featuring object-oriented programming, generics, lambdas, async/await, and a comprehensive type system inspired by TypeScript and Java.
- Bytecode VM Architecture: Stack-based virtual machine with 130+ optimized opcodes
- Advanced Type System: Full generic support with type constraints and inference
- Modern Features: Async/await, lambdas, closures, and functional programming
- Object-Oriented: Classes, interfaces, inheritance, and polymorphism
- Performance Optimized: SIMD-accelerated operations, string pooling, and AST optimizations
- Full IDE Support: VS Code extension with IntelliSense, debugging, and formatting
- Standard Library: Rich collection framework (List, HashMap, Stack, Queue, etc.)
- Static Typing:
int,float,string,bool,void, andnulltypes - Type Inference: Automatic type deduction for variables and expressions
- Modern Operators: Arithmetic, comparison, logical, ternary, and compound assignment
- Control Flow: if/else, switch/case, for/while/do-while loops, break/continue
- Multi-dimensional Arrays: Jagged and rectangular arrays with SIMD operations
- Exception Handling: try/catch/finally with custom exception hierarchies
- Classes: Full class support with constructors and inheritance
- Interfaces: Multiple interface implementation and inheritance
- Access Modifiers:
public,private,protected - Abstract Classes: Abstract classes and methods
- Final Modifiers: Final classes and methods to prevent overriding
- Static Members: Class-level fields and methods
- Polymorphism: Dynamic dispatch and runtime type checking
- Method Overriding: With covariant return types
- Generics: Generic classes, interfaces, and methods
- Multiple type parameters:
class Pair<K, V> - Type constraints:
class Box<T extends Comparable> - Nested generics:
List<Map<String, Int>>
- Multiple type parameters:
- Type Casting: Safe downcasting with runtime validation
- Nullable Types: Explicit null handling
- Runtime Type Checking:
isClassOfoperator
- Lambda Expressions:
x -> x * 2and(x, y) -> { return x + y; } - Closures: Capture variables from outer scope
- Functional Interfaces:
Function<T,R>,Consumer<T>,Predicate<T>,Supplier<T> - Higher-Order Functions: Functions as parameters and return values
- async/await Syntax: Modern asynchronous code
- Promise Type: Built-in promise support
- Event Loop: Priority-based task scheduling
- Async Lambdas: Asynchronous lambda expressions
- Collections:
List<T>: Dynamic resizable listLinkedList<T>: Doubly-linked listStack<T>: LIFO stackQueue<T>: FIFO queueHashMap<K,V>: Hash-based mapHashSet<T>: Hash-based set
- Primitive Wrappers:
Int,Float,String,Bool - Exception Types:
Exception,RuntimeException,NullPointerException,IndexOutOfBoundsException - Built-in Functions:
print(),typeof(),hashCode(), array operations
mType v0.2.0 features a complete bytecode compilation pipeline:
Source Code (.mt)
↓ Lexer
Tokens
↓ Parser
Abstract Syntax Tree (AST)
↓ Optimizer (optional)
Optimized AST
↓ Bytecode Compiler
Bytecode Program (.mtc)
↓ Virtual Machine
Execution Result
1. Direct Execution (compile and run in memory)
mType script.mt2. Compile to Bytecode (create .mtc file)
# Debug mode (minimal optimizations)
mType --compile script.mt
# Release mode (full optimizations)
mType --compile -release script.mt3. Execute Bytecode (run compiled .mtc file)
mType script.mtc- Stack-Based Architecture: Fast execution with 130+ specialized opcodes
- Call Stack Protection: Configurable stack depth with overflow detection (max: 1000)
- Type-Specialized Instructions: Optimized int/float operations
- Fast Field Access: Cached offset-based field access
- Debugging Support: Breakpoints, line tracking, stack traces
- Event Loop Integration: For async/await execution
AST-Level Optimizations (enabled with -release flag):
-
Constant Folding
- Compile-time evaluation of constant expressions
- Arithmetic, logical, and comparison operations
- String concatenation
- Overflow/underflow detection
-
Dead Code Elimination
- Removes unreachable code after return/break/continue/throw
- Respects
@Scriptand@Throwannotations - O(n) sequential block walking
-
Unused Declaration Elimination
- Two-phase analysis: usage tracking + removal
- Preserves public/exported declarations
- Maintains entry point code
- Automatic Deduplication: Intern strings to save memory
- LRU Cleanup: Automatic cleanup with configurable limits
- Thread-Safe: Concurrent access support
- Statistics Tracking: Monitor pool hits and memory savings
- Configuration: Max 100,000 strings, 1-1024 char length range
- Dimension-Based Reuse: Pool common array sizes (powers of 2, common 2D)
- Hit Rate Tracking: Monitor pool efficiency
- Adaptive Storage: Automatic sparse vs. dense selection
- Memory Limits: Max 1M elements total
Hardware-accelerated array operations (3-8× faster for arrays ≥16 elements):
- Platform Support: SSE2, AVX2 (x86/x64), NEON (ARM)
- Operations: Addition, subtraction, multiplication, scalar operations
- Reductions: Sum, min, max, average
- Runtime Detection: Automatic CPU feature detection
- 95% Memory Reduction: For large object arrays
- Cache-Friendly Layout: Contiguous field storage
- SIMD-Optimized: Field-oriented memory layout
- Sub-Array Views: Zero-copy array slicing
mType now includes a Language Server that works with ANY editor supporting LSP!
Supported Editors:
- ✅ VS Code (via mType extension)
- ✅ Vim/Neovim (via coc.nvim or nvim-lspconfig)
- ✅ Emacs (via lsp-mode)
- ✅ Sublime Text (via LSP package)
- ✅ IntelliJ IDEA, Eclipse, and any LSP-compatible editor
LSP Features:
- Auto-completion (keywords, types, variables, built-ins)
- Hover information (type docs, signatures)
- Real-time diagnostics (errors and warnings)
- Future: Go-to-definition, find references, formatting
Setup: See languageserver/README.md for installation and editor configuration.
Full-featured IDE support with the mType Language Extension:
Two Modes:
- Built-in Mode (default): VS Code-specific providers
- LSP Mode: Universal language server (enable in settings)
- IntelliSense: Context-aware completions (100+ keywords, types, members)
- Signature Help: Real-time parameter hints for functions and methods
- Go-to-Definition (F12): Jump to class, method, field, variable definitions
- Find All References (Shift+F12): Workspace-wide reference search
- Code Lens: Reference counts above classes and methods
- Auto-Formatting (Shift+Alt+F): AST-based code formatting
- Quick Fixes: Auto-import, interface implementation, organize imports
- Import Management: Path resolution and broken import diagnostics
- Semantic Highlighting: Enhanced token-based syntax coloring
- Breakpoints: Set breakpoints in .mt source files
- Step Execution: Step over, step into, step out
- Variable Inspection: View variables in debug sidebar
- Call Stack Navigation: Inspect call hierarchy
- Exception Breakpoints: Break on all/uncaught exceptions
- Syntax Highlighting: Comprehensive TextMate grammar (50+ token categories)
- Color Themes: mType Dark (Atom One Dark-inspired) and Light themes
- Custom Icons: Distinct icons for .mt and .mtc files
- Bracket Matching: Auto-closing and smart indentation
- Tab size, use tabs/spaces
- Format on save
- Organize imports automatically
- Space around operators
- Blank lines between declarations
- C++17 compatible compiler (GCC 7+, Clang 5+, MSVC 2017+)
- Premake5 (for project generation)
git clone https://github.com/matan45/mType.git
cd mType
runPremake.bat
# Open Interpreter.sln in Visual Studio and buildgit clone https://github.com/matan45/mType.git
cd mType
premake5 gmake2
make- Open VS Code
- Go to Extensions (Ctrl+Shift+X)
- Search for "mType" or install from
mtype-vscode-extension/ - Reload VS Code
Create hello.mt:
function main() {
string greeting = "Hello, mType!";
print(greeting);
return 0;
}
Run it:
# Direct execution
mType hello.mt
# Compile to bytecode (optimized)
mType --compile -release hello.mt
# Execute bytecode
mType hello.mtcmType/
├── lib/ # Standard library
│ ├── Object.mt
│ ├── collections/ # List, HashMap, Stack, Queue, etc.
│ └── primitives/ # Int, Float, String, Bool wrappers
├── mType/ # Core interpreter
│ ├── ast/ # Abstract Syntax Tree nodes
│ ├── lexer/ # Lexical analysis
│ ├── parser/ # Syntax analysis
│ ├── optimizer/ # AST optimization passes
│ ├── vm/ # Virtual Machine
│ │ ├── bytecode/ # Bytecode definitions and serialization
│ │ ├── compiler/ # Bytecode compiler
│ │ └── runtime/ # VM execution engine
│ ├── environment/ # Variable scoping and registries
│ ├── types/ # Type system
│ ├── value/ # Value types and memory management
│ ├── services/ # File reading, imports, script execution
│ ├── errors/ # Exception definitions
│ └── tests/ # Comprehensive test suite
│ └── testFiles/ # Test cases by feature
├── mtype-vscode-extension/ # VS Code language support
│ ├── src/ # Extension implementation
│ │ ├── completion/ # IntelliSense
│ │ ├── definition/ # Go-to-definition
│ │ ├── references/ # Find references
│ │ ├── formatter/ # Code formatting
│ │ └── debug/ # Debug adapter
│ ├── syntaxes/ # Syntax highlighting
│ └── themes/ # Color themes
└── bin/ # Compiled executables
class Box<T> {
private T value;
public constructor(T val) {
this.value = val;
}
public function get(): T {
return this.value;
}
public function set(T val): void {
this.value = val;
}
}
function main():void {
Box<int> intBox = new Box<int>(42);
Box<string> strBox = new Box<string>("Hello");
print(intBox.get()); // 42
print(strBox.get()); // Hello
return 0;
}
interface Function<T, R> {
function apply(T arg): R;
}
function map<T, R>(T[] array, Function<T, R> mapper): R[] {
R[] result = new R[array.length];
for (int i = 0; i < array.length; i++) {
result[i] = mapper.apply(array[i]);
}
return result;
}
function main():int {
int[] numbers = [1, 2, 3, 4, 5];
// Lambda expression
Function<int, int> doubler = x -> x * 2;
int[] doubled = map(numbers, doubler);
// Inline lambda
int[] squared = map(numbers, x -> x * x);
print(doubled); // [2, 4, 6, 8, 10]
print(squared); // [1, 4, 9, 16, 25]
return 0;
}
function async fetchData(string url): Promise<string> {
// Simulate async operation
return "Data from " + url;
}
function async processData(): Promise<void> {
string data1 = await fetchData("https://api.example.com/users");
print("Received: " + data1);
string data2 = await fetchData("https://api.example.com/posts");
print("Received: " + data2);
}
function main(): void {
processData();
return 0;
}
interface Drawable {
function draw(): string;
}
interface Resizable {
function resize(float factor): void;
}
class Circle implements Drawable, Resizable {
private float radius;
public constructor(float r) {
this.radius = r;
}
@Override
public function draw(): string {
return "Drawing circle with radius " + parsePrimitive(this.radius);
}
@Override
public function resize(float factor) {
this.radius = this.radius * factor;
}
}
function main(): void {
Circle circle = new Circle(5.0);
print(circle.draw()); // Drawing circle with radius 5.0
circle.resize(2.0);
print(circle.draw()); // Drawing circle with radius 10.0
return 0;
}
class Animal {
protected string name;
public constructor(string n) {
this.name = n;
}
public function speak(): string {
return "Some sound";
}
}
class Dog extends Animal {
public constructor(string n):super(n) {
}
@Override
public function speak(): string {
return "Woof! I'm " + this.name;
}
}
function main(): void {
Animal animal = new Dog("Buddy");
print(animal.speak()); // Woof! I'm Buddy (polymorphism)
return 0;
}
import { List, HashMap } from "lib/collections";
function main(): void {
// List example
List<int> numbers = new List<int>();
numbers.add(10);
numbers.add(20);
numbers.add(30);
print(numbers.size()); // 3
// HashMap example
HashMap<string, int> ages = new HashMap<string, int>();
ages.put("Alice", 30);
ages.put("Bob", 25);
if (ages.containsKey("Alice")) {
print(ages.get("Alice")); // 30
}
return 0;
}
- ✅ Lexical Analysis (Lexer with full token support)
- ✅ Syntax Analysis (Parser with error recovery)
- ✅ Abstract Syntax Tree (50+ node types)
- ✅ Semantic Analysis (Type checking, scope analysis)
- ✅ Generic Type System (Full generic support with constraints)
- ✅ Bytecode Compiler (130+ opcodes, serialization)
- ✅ Virtual Machine (Stack-based execution engine)
- ✅ Optimization System (3 AST optimization passes)
- ✅ Memory Management (String pooling, array pooling, SoA)
- ✅ Standard Library (Collections, primitives, exceptions)
- ✅ Async/Await (Promise support with event loop)
- ✅ Exception Handling (try/catch/finally)
- ✅ Import System (With circular dependency detection)
- ✅ VS Code Extension (Full IDE support)
- ✅ Debugging Support (Debug adapter protocol)
- ✅ SIMD Acceleration (SSE2, AVX2, NEON)
- ✅ Language Server Protocol (LSP) - Universal editor support (Vim, Emacs, Sublime, etc.)
- 🚧 Standard Library Expansion
- 🚧 Performance Benchmarking Suite
- 🚧 Documentation Portal
- 🚧 LSP: Additional Features (go-to-definition, find references, formatting)
- 📋 JIT Compilation
- 📋 Package Manager
- 📋 REPL (Read-Eval-Print Loop)
- 📋 Native Code Generation
- 📋 Cross-Platform Distribution
- Smart Pointers:
std::unique_ptr,std::shared_ptrfor automatic memory management - Move Semantics: Efficient resource transfer
- Lambda Expressions: For callbacks and functional constructs
- RAII: Resource Acquisition Is Initialization
- Variadic Templates: Flexible function signatures
- Range-Based Loops: Modern iteration syntax
- SOLID Principles: Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion
- DRY: Don't Repeat Yourself
- KISS: Keep It Simple, Stupid
- Modular Architecture: Separated concerns with clear interfaces
- Code Quality: 50-line function limit, extensive test coverage
- Bytecode Execution: Faster than tree-walking interpretation
- Optimized Instructions: Type-specialized opcodes
- Memory Efficiency: String interning, array pooling, SoA storage
- SIMD Operations: 3-8× speedup for array operations
- Stack-Based VM: Minimal overhead for function calls
The test suite is built into the interpreter:
# Build and run all tests
mType
# Run specific test suite
mType --test arrays
mType --test class
mType --test generics
# Verbose output
mType --test --verboseComprehensive test suites covering:
- ✅ Arrays (single, multi-dimensional, jagged, SIMD)
- ✅ Classes (inheritance, constructors, polymorphism)
- ✅ Interfaces (single, multiple, inheritance)
- ✅ Generics (classes, methods, constraints)
- ✅ Lambdas (expression, block, closures)
- ✅ Control Flow (if/else, loops, switch, break/continue)
- ✅ Type Checking (casting, validation, inference)
- ✅ Exception Handling (try/catch/finally, custom exceptions)
- ✅ Imports (selective, wildcard, circular detection)
- ✅ Async/Await (promises, event loop)
- ✅ String Pooling (interning, deduplication)
- ✅ Collections (List, HashMap, Stack, Queue)
Contributions are welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Follow C++17 standards and SOLID principles
- Write tests for new features
- Ensure 50-line function limit
- Update documentation
- Commit your changes (
git commit -m 'Add AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Use smart pointers for memory management
- Follow the Result pattern for error handling
- Maintain modular architecture with clear separation of concerns
- Write comprehensive test cases
- Document complex algorithms and design decisions
- Language Specification (Coming Soon)
- Bytecode Reference (Coming Soon)
- Standard Library API (Coming Soon)
- VM Architecture (Coming Soon)
For detailed project structure and implementation details, see CLAUDE.md.
This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by TypeScript, Java, and modern language design principles
- Built with C++17 for performance and reliability
- Special thanks to all contributors and the open-source community
- Project Repository: https://github.com/matan45/mType
- Issues: GitHub Issues
- Discussions: GitHub Discussions
mType v0.2.0 - A modern programming language with bytecode VM, generics, async/await, and comprehensive tooling.
