2024-03-20 09:31:14 +00:00
|
|
|
# Dust
|
|
|
|
|
2024-08-02 19:10:29 +00:00
|
|
|
High-level programming language with effortless concurrency, automatic memory management and type
|
|
|
|
safety.
|
|
|
|
|
2024-08-14 02:25:33 +00:00
|
|
|
Dust is a work in progress. Because it aims to deliver a high level of safety, extensive testing
|
|
|
|
is required. The language is still in the design phase, and the syntax is subject to change.
|
2024-08-02 19:10:29 +00:00
|
|
|
|
2024-08-14 02:25:33 +00:00
|
|
|
## Usage
|
2024-08-02 19:10:29 +00:00
|
|
|
|
2024-08-14 02:25:33 +00:00
|
|
|
The Dust command line tool can be used to run Dust programs. It is not yet available outside of
|
|
|
|
this repository.
|
|
|
|
|
|
|
|
```sh
|
|
|
|
cargo run --package dust-shell -- examples/hello_world.ds
|
|
|
|
```
|
|
|
|
|
|
|
|
```sh
|
2024-09-02 08:21:29 +00:00
|
|
|
cargo run --package dust-shell -- -c '"Hello my name is " + read_line() + "!"'
|
2024-08-14 02:25:33 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Dust is easily embedded in another program. You can run a dust program of any size or complexity
|
|
|
|
with a single function.
|
|
|
|
|
|
|
|
```rust
|
|
|
|
use dust_lang::{run, Value};
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let code = "
|
2024-09-02 08:21:29 +00:00
|
|
|
let x = 'Dust'
|
|
|
|
let y = ' is awesome!'
|
2024-08-02 19:10:29 +00:00
|
|
|
|
2024-08-14 02:25:33 +00:00
|
|
|
write_line(x + y)
|
|
|
|
|
|
|
|
42
|
|
|
|
";
|
|
|
|
|
2024-09-02 08:21:29 +00:00
|
|
|
let result = run(code);
|
2024-08-14 02:25:33 +00:00
|
|
|
|
|
|
|
assert_eq!(result, Ok(Some(Value::integer(42))));
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## Concepts
|
|
|
|
|
|
|
|
### Effortless Concurrency
|
2024-03-20 09:31:14 +00:00
|
|
|
|
2024-09-02 08:21:29 +00:00
|
|
|
Dust makes concurrency as effortless as possible. Dust is organized into **statements**, and any
|
|
|
|
sequence of statements can be run concurrently by simply adding the `async` keyword before the block
|
|
|
|
of statements.
|
2024-08-02 19:10:29 +00:00
|
|
|
|
2024-08-14 02:25:33 +00:00
|
|
|
```rust
|
|
|
|
// Counts from 0 to 9, sleeping for an increasing amount of time between each.
|
2024-09-02 08:21:29 +00:00
|
|
|
let count_slowly = fn (multiplier: int) {
|
2024-08-14 02:25:33 +00:00
|
|
|
i = 0
|
2024-08-02 19:10:29 +00:00
|
|
|
|
2024-08-14 02:25:33 +00:00
|
|
|
while i < 10 {
|
|
|
|
sleep(i * multiplier)
|
|
|
|
write_line(i.to_string())
|
2024-08-02 19:10:29 +00:00
|
|
|
|
2024-08-14 02:25:33 +00:00
|
|
|
i += 1
|
|
|
|
}
|
2024-08-02 19:10:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async {
|
2024-08-14 02:25:33 +00:00
|
|
|
count_slowly(200) // Finishes last
|
|
|
|
count_slowly(100) // Finishes second
|
|
|
|
count_slowly(50) // Finishes first
|
2024-05-18 15:59:39 +00:00
|
|
|
}
|
|
|
|
```
|
2024-08-02 19:10:29 +00:00
|
|
|
|
|
|
|
### Automatic Memory Management
|
|
|
|
|
2024-09-02 08:21:29 +00:00
|
|
|
Dust uses a garbage collector to automatically manage memory.
|
2024-08-02 19:10:29 +00:00
|
|
|
|
2024-08-14 02:25:33 +00:00
|
|
|
```rust
|
2024-09-02 08:21:29 +00:00
|
|
|
let x = 0 // x is assigned but never used
|
|
|
|
// x is removed from memory
|
2024-08-02 19:10:29 +00:00
|
|
|
|
2024-09-02 08:21:29 +00:00
|
|
|
let y = 41 // y is assigned
|
|
|
|
let z = y + 1 // y is kept alive for this statement
|
|
|
|
// y is removed from memory
|
|
|
|
|
|
|
|
write_line(z) // z is kept alive for this statement
|
|
|
|
// z is removed from memory
|
2024-08-02 19:10:29 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
### Type Safety
|
|
|
|
|
|
|
|
Dust is statically typed and null-free, but the type of a value can usually be inferred from its
|
|
|
|
usage. Dust will refuse to run programs with type errors, but will usually not require type
|
|
|
|
annotations.
|
|
|
|
|
2024-08-14 02:25:33 +00:00
|
|
|
```rust
|
|
|
|
// These two statements are identical to Dust
|
2024-09-02 08:21:29 +00:00
|
|
|
let x = 1
|
|
|
|
let x: int = 1
|
2024-08-02 19:10:29 +00:00
|
|
|
|
2024-08-14 02:25:33 +00:00
|
|
|
// Numbers with decimals are floats
|
2024-09-02 08:21:29 +00:00
|
|
|
let y = 10.0
|
|
|
|
let y: float = 10.0
|
2024-08-02 19:10:29 +00:00
|
|
|
|
2024-09-02 08:21:29 +00:00
|
|
|
// Strings are enclosed in double quotes and are guaranteed to be valid UTF-8
|
|
|
|
let z = "Hello, world!"
|
|
|
|
let z: str = "Hello, world!"
|
2024-08-02 19:10:29 +00:00
|
|
|
```
|
|
|
|
|
2024-09-02 08:21:29 +00:00
|
|
|
Aside from the ubiqutous `bool`, `int`, `float`, and `str` types, Dust also has lists, maps,
|
2024-08-14 02:25:33 +00:00
|
|
|
ranges, structures, enums and functions.
|