ItScript is a dynamic, interpreted general-purpose programming language developed in C++. It integrates the syntactic simplicity of scripting languages with advanced concurrency models found in Go and modern functional programming features.
The interpreter is built with a focus on modularity, robust concurrency support, and a comprehensive standard library.
The language is designed to bridge the gap between simple scripting and complex application development by offering:
- Strong Dynamic Typing: Runtime type checking with support for complex data structures like named tuples and hash tables.
- First-Class Concurrency: Native support for threads, synchronization primitives, and asynchronous programming models.
- Metaprogramming Capabilities: Built-in support for decorators, reflection, and dynamic module loading.
- Modern Syntax: Features include pattern matching, list/table comprehensions, and variadic templates.
- Data Types: Numbers (double precision), Strings, Booleans, Lists (Arrays), Tables (Dictionaries/Maps), and
nil. - Scoping: Lexical scoping with support for closures and global/local variable shadowing.
- Control Flow:
if-else,while,for-inloops, andmatchexpressions.
ItScript implements a hybrid concurrency model:
- Threading: System-level threads via
std::thread. - Synchronization: A full suite of primitives in
std::sync, including Mutexes, Semaphores, Condition Variables, and Barriers. - Message Passing: Go-style channels (
chan) for safe communication between threads. - Async/Await: Promise-based asynchronous execution handling via
std::async.
- Functions: First-class citizens that can be passed as arguments, returned, and assigned to variables.
- Decorators: Rust-style
#[decorator]syntax for modifying function behavior. - Comprehensions: Concise syntax for generating Lists, Sets, and Tables based on existing iterables.
The project requires a C++20.
- C++ Compiler (GCC 10+, Clang 11+, or MSVC 19.28+)
- CMake 3.14 or higher
- Google Test (GTest) library
mkdir build
cd build
cmake ..
makeTo run the test suite:
./ItScript_testsimport std::math
// Function definition
fib = function(n)
if n <= 1 then
return n
end if
return fib(n-1) + fib(n-2)
end function
// Pattern matching
result = match fib(10)
case 55: "Correct"
case x if x > 100: "Too high"
default: "Unknown"
end match
print(result)Demonstrating Go-style communication between threads.
import std::sync
import std::thread
// Create a synchronous (unbuffered) channel
ch = sync.create_channel(0)
// Spawn a worker thread
thread.create_worker("
import std::sync
// Simulate work
std::thread.sleep(100)
sync.channel_send(ch, 42)
")
// Main thread waits for data
print("Waiting for worker...")
value = sync.channel_receive(ch)
print("Received: " + std::string::to_string(value))Using promises for non-blocking operations.
import std::async
task = function()
return "Async Result"
end function
// Create a promise and execute asynchronously
promise = async.async_task(task)
if not async.promise_is_resolved(promise) then
print("Task is running...")
end if
result = async.promise_wait(promise)
print(result)Implementing aspect-oriented patterns.
// Define a timing decorator
timing_decorator = function(func)
return function(...args)
print("Start execution...")
res = func(...args)
print("End execution.")
return res
end function
end function
#[timing_decorator]
process_data = function(data)
return "Processed " + data
end function
process_data("Input")The interpreter includes a robust standard library:
| Module | Description |
|---|---|
std::io |
File system operations, binary streams, JSON/CSV parsing, and logging configurations. |
std::math |
Trigonometry, statistics, random number generation, and linear algebra helpers. |
std::string |
Manipulation functions including split, join, replace, and casing utilities. |
std::collections |
algorithms for sorting, filtering, and manipulating complex data structures. |
std::sync |
Thread synchronization primitives (Mutex, Semaphore, Barrier, Channel). |
std::async |
Asynchronous task management, Promises, and Timers. |
This project is licensed under the MIT License.