HypnoScript is a hypnotically-inspired programming language with its own syntax (Focus { ... } Relax).
The complete runtime environment, compiler, and command-line tools were ported from C# to Rust
and are exclusively developed in Rust from version 1.0 onwards.
- ๐ฆ Pure Rust Codebase โ fast builds, no .NET dependencies
- ๐ง Complete Toolchain โ Lexer, Parser, Type Checker, Interpreter, and multiple compiler backends
- ๐ฏ Multiple Targets โ Interpreter, WebAssembly (Text & Binary), Native Code (planned)
- โก Code Optimization โ Constant Folding, Dead Code Elimination, CSE, LICM, Inlining
- ๐งฐ 180+ Builtins โ Math, Strings, Arrays, Hypnosis, Files, Time, System, Statistics, Hashing, Validation, Cryptography
- ๐ Multilingual โ i18n support (EN, DE, FR, ES)
- ๐ Cryptography โ SHA-256, SHA-512, MD5, Base64, UUID
- ๐งฌ Functional Programming โ map, filter, reduce, compose, pipe
- ๐ญ Hypnotic Operators โ 14 synonyms like
youAreFeelingVerySleepy,lookAtTheWatch,underMyControl - ๐ฏ Pattern Matching โ
entrain/when/otherwisewith Destructuring, Guards, and Type Patterns - ๐ Event-Driven โ
triggerfor Callbacks and Event Handlers - ๐ Nullish Operators โ
lucidFallback(??) anddreamReach(?.) for safe null handling - ๐๏ธ OOP Support โ Sessions with
constructor,expose/conceal,dominant(static) - ๐ฅ๏ธ Extended CLI โ
run,lex,parse,check,compile-wasm,compile-native,optimize,builtins,version - โ Comprehensive Tests โ 185+ tests across all compiler modules
- ๐ Documentation โ VitePress + extensive architecture docs + complete Rustdoc
- ๐ Performance โ Zero-cost abstractions, no garbage collector, optimized native code
hyp-runtime/
โโโ Cargo.toml # Workspace configuration
โโโ COMPILER_ARCHITECTURE.md # Detailed compiler documentation
โโโ hypnoscript-core/ # Type system & symbols (100%)
โโโ hypnoscript-lexer-parser/ # Tokens, Lexer, AST, Parser (100%)
โโโ hypnoscript-compiler/ # Compiler backend (100%)
โ โโโ interpreter.rs # โ
Tree-walking interpreter
โ โโโ type_checker.rs # โ
Static type checking
โ โโโ wasm_codegen.rs # โ
WASM Text Format (.wat)
โ โโโ wasm_binary.rs # โ
WASM Binary Format (.wasm)
โ โโโ optimizer.rs # โ
Code optimizations
โ โโโ native_codegen.rs # ๐ง Native compilation (LLVM)
โโโ hypnoscript-runtime/ # 180+ builtin functions (100%)
โโโ hypnoscript-cli/ # Command-line interface (100%)
Documentation is available in hypnoscript-docs/ (Docusaurus).
- Rust 1.76+ (recommended) including
cargo
curl -fsSL https://kink-development-group.github.io/hyp-runtime/install.sh | bashThe script automatically detects Linux/macOS, downloads the appropriate runtime from the current release, and updates existing installations. Important options: --prefix, --version, --check, --include-prerelease, --force, --uninstall.
- Check for updates:
hypnoscript self-update --checkdisplays available versions. - Update:
hypnoscript self-updatepulls the latest release version including sudo handling. - Force reinstallation:
hypnoscript self-update --forceruns the installer again. - Uninstall:
curl -fsSL https://kink-development-group.github.io/hyp-runtime/install.sh | bash -s -- --uninstallremoves binary and metadata.
git clone https://github.com/Kink-Development-Group/hyp-runtime.git
cd hyp-runtime
cargo build --all --releaseThe CLI is created as two binaries: hypnoscript and hyp (short form). Both are identical and can be used interchangeably.
# Both variants work
./target/release/hypnoscript exec program.hyp
./target/release/hyp exec program.hypOr during development:
cargo run -p hypnoscript-cli -- exec test_simple.hypFocus {
entrance {
observe "Welcome to HypnoScript!";
}
induce x: number = 42;
induce message: string = "Hello Trance";
observe message;
observe x;
// Hypnotic operator synonym
if (x yourEyesAreGettingHeavy 40) deepFocus {
observe "X is greater than 40";
}
// Pattern matching with entrain
induce result: string = entrain x {
when 0 => "zero"
when 42 => "answer to everything"
when n if n > 100 => "large number"
otherwise => "other"
};
observe result;
// Nullish operators
induce maybeNull: number? = null;
induce defaulted: number = maybeNull lucidFallback 100;
observe defaulted; // 100
// Trigger (event handler)
trigger onComplete = suggestion() {
observe "Task completed!";
};
onComplete();
} Relax
Note: All commands can be executed with either hypnoscript or hyp.
# Execute program (Interpreter)
hypnoscript exec program.hyp
# or short:
hyp exec program.hyp
# Analysis tools
hypnoscript lex program.hyp # Tokenization
hypnoscript parse program.hyp # Display AST
hypnoscript check program.hyp # Type checking
# Compilation
hypnoscript compile-wasm program.hyp # WASM Text Format (.wat)
hypnoscript compile-wasm -b program.hyp # WASM Binary Format (.wasm)
hypnoscript compile-native program.hyp # Native binary (planned)
hypnoscript compile-native -t linux-x64 \
--opt-level release program.hyp # With target platform
# Code optimization
hypnoscript optimize program.hyp --stats # With statistics
# Package Manager
hypnoscript init # Initialize new project
hypnoscript init --template cli # CLI project template
hypnoscript add package --version "^1.0.0" # Add dependency
hypnoscript add pkg --version "^1.0.0" --dev # Add dev dependency
hypnoscript remove package # Remove dependency
hypnoscript install # Install all dependencies
hypnoscript list # List dependencies
hypnoscript run <script> # Run script from trance.json
hypnoscript validate # Validate trance.json
# Utilities
hypnoscript builtins # Builtin functions
hypnoscript version # Version
hypnoscript self-update # Self-update# Text format (readable, debugging-friendly)
hypnoscript compile-wasm script.hyp -o output.wat
# Binary format (compact, production-ready)
hypnoscript compile-wasm --binary script.hyp -o output.wasm
# Convert to complete WASM binary with wabt-tools
wat2wasm output.wat -o output.wasm# For current platform
hypnoscript compile-native app.hyp
# Cross-compilation
hypnoscript compile-native -t windows-x64 app.hyp
hypnoscript compile-native -t macos-arm64 app.hyp
hypnoscript compile-native -t linux-x64 app.hyp
# With optimization
hypnoscript compile-native --opt-level release app.hypHypnoScript has a built-in package manager, similar to npm for JavaScript or Cargo for Rust. It uses trance.json as its manifest file.
# Initialize new project
hypnoscript init --name my-project --template cli
# Add dependencies
hypnoscript add hypnoscript-runtime --version โ^1.0.0โ
hypnoscript add @hypno/testing-lab --version โ^0.3.0โ --dev
# Install dependencies
hypnoscript install
# List dependencies
hypnoscript list
# Run script
hypnoscript run test
# Validate manifest
hypnoscript validateThe manifest uses hypnotic terminology:
- ritualName: Package name (corresponds to
namein npm) - mantra: Version (corresponds to
versionin npm) - intent: Project type (cli, library)
- anchors: Production dependencies (corresponds to
dependencies) - deepAnchors: Development dependencies (corresponds to
devDependencies) - suggestions: Executable scripts (corresponds to
scripts) - channels: Binary/CLI configuration
- triggers: Lifecycle hooks
Example trance.json:
{
โritualNameโ: โmy-hypno-appโ,
โmantraโ: โ1.0.0โ,
โintentโ: โcliโ,
โsuggestionsโ: {
โfocusโ: โhypnoscript exec src/main.hypโ,
โtestโ: โhypnoscript exec tests/test.hypโ
},
โanchorsโ: {
โhypnoscript-runtimeโ: โ^1.0.0โ
}
}Complete documentation: see PACKAGE_MANAGER.md
Run all tests:
cargo test --allTest Coverage:
- โ Lexer: 15+ tests
- โ Parser: 20+ tests
- โ Type Checker: 10+ tests
- โ Interpreter: 12+ tests
- โ WASM Generator: 4+ tests
- โ Optimizer: 6+ tests
- โ Native Generator: 5+ tests
- โ Runtime Builtins: 30+ tests
- โ Pattern Matching: Full coverage
- โ Triggers: Full coverage
- โ Nullish Operators: Full coverage
# Compiler tests only
cargo test --package hypnoscript-compiler
# With detailed output
cargo test --package hypnoscript-compiler -- --nocapture# Check formatting
cargo fmt --all -- --check
# Linting with Clippy
cargo clippy --all-targets --all-featuresSin, Cos, Tan, Sqrt, Pow, Log, Abs, Floor, Ceil, Round, Min, Max, Factorial, Gcd, Lcm, IsPrime, Fibonacci, Clamp
ToUpper, ToLower, Capitalize, TitleCase, IndexOf, Replace, Reverse, Split, Substring, Trim, Repeat, PadLeft, PadRight, StartsWith, EndsWith, Contains, Length, IsWhitespace
ArrayLength, ArraySum, ArrayAverage, ArrayMin, ArrayMax, ArraySort, ArrayReverse, ArrayDistinct, ArrayFirst, ArrayLast, ArrayTake, ArraySkip, ArraySlice, ArrayJoin, ArrayCount, ArrayIndexOf, ArrayContains, ArrayIsEmpty, ArrayGet
GetCurrentTime, GetCurrentDate, GetCurrentDateTime, FormatDateTime, GetYear, GetMonth, GetDay, GetHour, GetMinute, GetSecond, GetDayOfWeek, GetDayOfYear, IsLeapYear, GetDaysInMonth, CurrentDate, DaysInMonth
IsValidEmail, IsValidUrl, IsValidPhoneNumber, IsAlphanumeric, IsAlphabetic, IsNumeric, IsLowercase, IsUppercase, IsInRange, MatchesPattern
ReadFile, WriteFile, AppendFile, FileExists, IsFile, IsDirectory, DeleteFile, CreateDirectory, ListDirectory, GetFileSize, CopyFile, RenameFile, GetFileExtension, GetFileName
CalculateMean, CalculateMedian, CalculateMode, CalculateStandardDeviation, CalculateVariance, CalculateRange, CalculatePercentile, CalculateCorrelation, LinearRegression, Mean, Variance
HashString, HashNumber, AreAnagrams, IsPalindrome, CountOccurrences, RemoveDuplicates, UniqueCharacters, ReverseWords, TitleCase, SimpleRandom
GetOperatingSystem, GetArchitecture, GetCpuCount, GetHostname, GetCurrentDirectory, GetHomeDirectory, GetTempDirectory, GetEnvVar, SetEnvVar, GetUsername, GetArgs, Exit
Observe, Drift, DeepTrance, HypnoticCountdown, TranceInduction, HypnoticVisualization
ToInt, ToDouble, ToString, ToBoolean
A complete list is available via hypnoscript builtins and in the Docusaurus documentation.
HypnoScript offers 14 hypnotic aliases for standard operators:
| Standard | Hypnotic | Description |
|---|---|---|
== |
youAreFeelingVerySleepy |
Equality |
!= |
youCannotResist |
Inequality |
> |
lookAtTheWatch |
Greater than |
>= |
yourEyesAreGettingHeavy |
Greater or equal |
< |
fallUnderMySpell |
Less than |
<= |
goingDeeper |
Less or equal |
&& |
underMyControl |
Logical AND |
|| |
resistanceIsFutile |
Logical OR |
! |
snapOutOfIt |
Logical NOT |
?? |
lucidFallback |
Nullish coalescing |
?. |
dreamReach |
Optional chaining |
โ ๏ธ String Concatenation: When one of the operands of the+operator is a string, all other values are automatically converted to strings. Examples:null + "text"yields"nulltext",42 + "px"yields"42px". Check the type before concatenating if you want to avoid such implicit conversions.
Example:
induce age: number = 25;
if (age yourEyesAreGettingHeavy 18 underMyControl age fallUnderMySpell 65) {
observe "Adult of working age";
}
๐ Complete Documentation: docs/language-reference/operator-synonyms.md
Powerful pattern matching with:
- Literal Patterns: Direct value comparison
- Type Patterns: Type-based matching with binding
- Array Destructuring: Spread operator, nested patterns
- Record Patterns: Field-based matching
- Guards: Conditional patterns with
if - Identifier Binding: Variable binding in patterns
Example:
induce status: number = 404;
induce message: string = entrain status {
when 200 => "OK"
when 404 => "Not Found"
when 500 => "Server Error"
when s if s yourEyesAreGettingHeavy 400 underMyControl s fallUnderMySpell 500 => "Client Error"
otherwise => "Unknown"
};
// Array destructuring
induce coords: array = [10, 20, 30];
entrain coords {
when [x, y, z] => observe "3D Point: " + x + ", " + y + ", " + z
when [x, y] => observe "2D Point: " + x + ", " + y
otherwise => observe "Invalid coordinates"
}
๐ Complete Documentation: docs/language-reference/pattern-matching.md
Triggers are top-level event handlers that respond to events:
Syntax:
trigger triggerName = suggestion(parameters) {
// Handler code
};
Example:
trigger onStartup = suggestion() {
observe "Application initialized";
};
trigger onError = suggestion(code: number, message: string) {
observe "Error " + code + ": " + message;
};
trigger onCleanup = suggestion() {
observe "Cleaning up resources...";
};
entrance {
onStartup();
if (someCondition) {
onError(404, "Resource not found");
}
onCleanup();
}
Use Cases:
- Event handlers (Click, Load, Error)
- Lifecycle hooks (Setup, Teardown)
- Callbacks for async operations
- Observers for state changes
๐ Complete Documentation: docs/language-reference/triggers.md
Nullish Coalescing (lucidFallback / ??):
Returns the right value only when the left value is null or undefined (not for 0, false, ""):
induce value: number? = null;
induce result: number = value lucidFallback 100; // 100
induce zero: number = 0;
induce result2: number = zero lucidFallback 100; // 0 (not 100!)
Optional Chaining (dreamReach / ?.):
Safe navigation through nested structures:
session User {
expose profile: Profile?;
}
session Profile {
expose name: string;
}
induce user: User? = getUser();
induce name: string = user dreamReach profile dreamReach name lucidFallback "Anonymous";
Benefits:
- โ Avoids null pointer exceptions
- โ
More readable than nested
ifchecks - โ Functional programming patterns
- โ Zero-cost abstraction (compiler-optimized)
๐ Complete Documentation: docs/language-reference/nullish-operators.md
Rust offers several advantages over C#:
- Zero-cost Abstractions: Compile-time optimizations without runtime overhead
- No Garbage Collector: Deterministic memory management
- Memory Safety: Compile-time prevention of common bugs
- Smaller Binaries: 5-10MB vs. 60+MB for C# with runtime
- Better Parallelization: Safe concurrent access via ownership model
- Faster Execution: Native code with LLVM optimizations
- Add function to the appropriate module in
hypnoscript-runtime/src/ - Add tests in the same file
- Update builtins list in CLI
- Export from
lib.rs
Example:
// In math_builtins.rs
pub fn new_function(x: f64) -> f64 {
// Implementation
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_new_function() {
assert_eq!(MathBuiltins::new_function(5.0), expected_result);
}
}- Follow Rust standard style (use
cargo fmt) - Run Clippy for linting:
cargo clippy - Keep functions focused and well-documented
- Write tests for new functionality
- โ Interpreter (100%) โ Tree-walking interpreter with full builtin support
- โ Type Checker (100%) โ Static type checking, OOP validation
- โ WASM Text Generator (100%) โ WebAssembly Text Format (.wat)
- โ WASM Binary Generator (100%) โ Direct binary generation (.wasm)
- โ Code Optimizer (100%) โ Constant Folding, Dead Code Elimination, CSE, LICM, Inlining
- ๐ง Native Code Generator (20%) โ LLVM backend planned
- โ Core type system (100%)
- โ Symbol table (100%)
- โ Lexer (100%)
- โ Parser (100%)
- โ AST (100%)
- โ OOP/Sessions (100%)
- โ
Pattern Matching (
entrain/when/otherwise) (100%) - โ Triggers (Event-Driven Callbacks) (100%)
- โ
Nullish Operators (
lucidFallback,dreamReach) (100%) - โ Hypnotic Operator Synonyms (14 aliases) (100%)
- โ
Runtime Builtins (180+ functions)
- Math, String, Array, Collections
- File I/O, Time/Date, System
- Hashing, Validation, Statistics
- Advanced String Operations
- API/HTTP Helpers
- โ Localization (EN, DE, FR, ES)
- โ CLI Framework (100%)
- โ CI/CD Pipelines (100%)
- Lexer implementation
- Parser implementation
- Type Checker implementation
- Interpreter implementation
- WASM Text Format Generator (.wat)
- WASM Binary Format Generator (.wasm)
- Code optimization framework
- 180+ builtin functions
- Session/OOP features
- Complete program execution
- CLI integration (10 commands)
- CI/CD pipelines
- Comprehensive tests (100+ tests)
- Multilingual documentation
- Native Code Generator โ LLVM backend for platform-specific binaries
- Windows (x86_64, ARM64)
- macOS (x86_64, ARM64/Apple Silicon)
- Linux (x86_64, ARM64, RISC-V)
- Advanced Optimizations โ Complete implementation of all optimization passes
- Source Maps โ Debugging support for compiled code
- JIT compilation
- Incremental compilation
- Profile-Guided Optimization (PGO)
- Link-Time Optimization (LTO)
- Language Server Protocol (LSP) for IDE integration
- Advanced WASM features (Threads, SIMD)
- Additional 40 specialized builtins (Network, ML)
- Session/OOP features
- Advanced error handling
- Performance benchmarking vs. C#
- Optimization passes
- Some advanced C# builtins still pending (Network, ML features - optional)
- Session/OOP features are optional extensions
- โ
C# codebase removed (all former
.csprojprojects deleted) - โ Rust workspace production-ready
- โ Complete port of core functionality
- โ All 48 tests passing
- ๐ Optional extensions (e.g., Network/ML builtins) possible as roadmap items
Migration details: see IMPLEMENTATION_SUMMARY.md.
- ๐ Rust Book
- ๐ฆ Cargo Documentation
- ๐งพ Project Docs:
HypnoScript.Dokumentation/ - ๐ Issues & Discussions: https://github.com/Kink-Development-Group/hyp-runtime
When contributing to the Rust implementation:
- Maintain API compatibility with the C# version where possible
- Follow DRY principles (Don't Repeat Yourself)
- Write comprehensive tests
- Document public APIs
- Run
cargo fmtandcargo clippybefore committing
MIT License (same as the original project)
The Rust runtime is production-ready for HypnoScript core programming! ๐
Enjoy hypnotic programming with Rust!