docs: add missing stdlib modules and update language reference
Stdlib.md: - Add Std::Task (thread spawn/join/sleep) - Add Std::Channel (generic channels + wrappers) - Add Std::Net (TCP sockets) - Add Std::Json (parser/serializer) - Add Std::Crypto (SHA-256, HMAC, Base64, random) - Add Std::Fmt (formatting wrappers) - Add Std::Math (Sqrt, Pow, Abs, Min, Max) - Add String_FromFloat to String docs - Update Future Modules list LanguageRef.md: - Add Concurrency section (threads + channels) - Update Ownership with move semantics and own T BuildAndTest.md: - Add libssl-dev/openssl prerequisite note - Mention -lcrypto auto-linking
This commit is contained in:
+63
-1
@@ -402,7 +402,33 @@ func BadWrite(val: &int) {
|
||||
| Raw pointer | `*T` | C-style pointer, no checks |
|
||||
| Shared ref | `&T` | Borrowed reference (read-only in checked functions) |
|
||||
| Mutable ref | `&mut T` | Exclusive mutable borrow (allows mutation) |
|
||||
| Owned | `own T` | Ownership transfer (syntax parsed, not yet enforced) |
|
||||
| Owned | `own T` | Ownership type — values can be moved |
|
||||
|
||||
### Move Semantics
|
||||
|
||||
`own T` values can be **moved**. After a move, the original variable is uninitialized and cannot be used until reassigned.
|
||||
|
||||
```bux
|
||||
@[Checked]
|
||||
func Process(data: own String) {
|
||||
PrintLine(data);
|
||||
// data is consumed here
|
||||
}
|
||||
|
||||
@[Checked]
|
||||
func Main() {
|
||||
let msg: own String = "hello";
|
||||
Process(msg); // move: msg is now uninitialized
|
||||
// PrintLine(msg); // ERROR: use after move
|
||||
msg = "reassigned"; // OK: reinitialization
|
||||
PrintLine(msg);
|
||||
}
|
||||
```
|
||||
|
||||
Moves happen in three contexts:
|
||||
- **Function call argument**: `Process(msg)` moves `msg` into the parameter
|
||||
- **Assignment**: `b = a` moves `a` into `b`
|
||||
- **Return**: `return x` moves `x` out of the function
|
||||
|
||||
### Rules in @[Checked] functions
|
||||
|
||||
@@ -510,6 +536,42 @@ func PrivateFunc() -> int {
|
||||
|
||||
---
|
||||
|
||||
## Concurrency
|
||||
|
||||
Bux supports both **async/await** (stackful coroutines) and **pthread-based threads** with channels.
|
||||
|
||||
### Threads and Channels
|
||||
|
||||
```bux
|
||||
import Std::Task::{Task_Spawn, Task_Join, TaskHandle};
|
||||
import Std::Channel::{Channel, Channel_New, Channel_SendInt, Channel_RecvInt, Channel_Close};
|
||||
|
||||
func Producer(ch: *Channel<int>) {
|
||||
Channel_SendInt(ch, 42);
|
||||
Channel_Close<int>(ch);
|
||||
}
|
||||
|
||||
func Consumer(ch: *Channel<int>) -> int {
|
||||
let val: int = Channel_RecvInt(ch);
|
||||
return val;
|
||||
}
|
||||
|
||||
func Main() -> int {
|
||||
let ch: Channel<int> = Channel_New<int>(1);
|
||||
let p: *void = spawn Producer(&ch);
|
||||
let c: *void = spawn Consumer(&ch);
|
||||
Task_Join(TaskHandle { handle: p });
|
||||
Task_Join(TaskHandle { handle: c });
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
- `spawn Func()` creates a new pthread running `Func`
|
||||
- `Channel<T>` is a buffered channel with mutex/condvar
|
||||
- `Channel_RecvInt` returns `0` when the channel is closed and empty
|
||||
|
||||
---
|
||||
|
||||
## Async/Await
|
||||
|
||||
Bux supports stackful coroutines via `async`/`await` with a round-robin scheduler.
|
||||
|
||||
Reference in New Issue
Block a user