Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Install g++ (Linux)
- name: Setup g++ (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y g++-14
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-14 100
if command -v g++-14 >/dev/null 2>&1; then
sudo update-alternatives --install /usr/bin/g++ g++ "$(command -v g++-14)" 100
else
sudo apt-get update
sudo apt-get install -y g++-14
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-14 100
fi

- name: Bootstrap
run: make bootstrap
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ build/
deps/
design/
.vscode
ROADMAP.md
COMPILER.md
IR.md
109 changes: 109 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,65 @@ See [Type Casting](#type-casting) for full details on the `as` keyword.
| `random(min, max)` | Random integer in range. |
| `random_float()` | Random float in [0, 1). |

### Crypto

| Module Function | Description |
|----------------|-------------|
| `crypto::sha256(text)` | SHA-256 digest as lowercase hex string. |
| `crypto::md5(text)` | MD5 digest as lowercase hex string. |

### Base64

| Module Function | Description |
|----------------|-------------|
| `base64::encode(text)` | Encode UTF-8 string as Base64. |
| `base64::decode(text)` | Decode Base64 to string. |
| `base64::url_encode(text)` | URL-safe Base64 encoding without padding. |
| `base64::url_decode(text)` | Decode URL-safe Base64 string. |
| `base64::is_valid(text)` | Validate Base64 input. |
| `base64::encode_bytes(buf)` | Encode bytes, returns Base64 text as bytes. |
| `base64::decode_bytes(text)` | Decode Base64 text into `bytes`. |

### Random

Use `import std::rng` for the newer random API. The module is named `rng` rather than `random` to avoid conflicts with C runtime symbols in generated C++.

| Module Function | Description |
|----------------|-------------|
| `rng::seed(seed)` | Seed the pseudo-random generator. |
| `rng::range(min, max)` | Pseudo-random integer in range. |
| `rng::u32()` / `rng::u64()` | Pseudo-random unsigned values exposed as `int`. |
| `rng::next_double()` / `rng::next_float()` | Pseudo-random float in `[0, 1)`. |
| `rng::next_bool()` | Pseudo-random boolean. |
| `rng::chance(p)` | Bernoulli trial with probability `p`. |
| `rng::normal(mean, stddev)` | Normal distribution sample. |
| `rng::exponential(lambda)` | Exponential distribution sample. |
| `rng::next_bytes(len)` | Pseudo-random bytes. |
| `rng::secure_bytes(len)` | OS-backed secure random bytes. |
| `rng::secure_int(min, max)` | Secure random integer in range. |
| `rng::secure_double()` | Secure random float in `[0, 1)`. |
| `rng::uuid_bytes()` / `rng::uuid_string()` | Random UUID v4 as bytes/string. |

### Time

Use `import std::chrono` for the newer time API. The module is named `chrono` rather than `time` to avoid conflicts with the C `time()` symbol in generated C++.

| Module Function | Description |
|----------------|-------------|
| `chrono::now()` / `chrono::now_ms()` / `chrono::now_us()` | Current Unix time in seconds / milliseconds / microseconds. |
| `chrono::uptime_ms()` | Monotonic uptime in milliseconds. |
| `chrono::perf_counter()` / `chrono::perf_frequency()` | High-resolution timer values. |
| `chrono::current(local = true)` | Current local or UTC `DateTime`. |
| `chrono::from_timestamp_ms(ms, local = true)` | Convert timestamp to `DateTime`. |
| `chrono::to_timestamp(dt)` / `chrono::to_timestamp_ms(dt)` | Convert `DateTime` back to Unix time. |
| `chrono::format(dt, fmt)` / `chrono::format_current(fmt)` | Format date/time values. |
| `chrono::to_iso8601(ts, local = true)` | Format Unix seconds as ISO-8601. |
| `chrono::from_iso8601(text)` | Parse ISO-like string in local time. |
| `chrono::sleep_ms(ms)` / `chrono::sleep_us(us)` / `chrono::sleep_seconds(sec)` | Sleep helpers. |
| `chrono::difference(a, b)` | Subtract timestamps. |
| `chrono::timezone_offset()` | Local offset from UTC in seconds. |
| `chrono::is_valid(dt)` | Validate `DateTime` fields. |

### Standard Library Modules

The standard library is organized into importable modules:
Expand All @@ -1262,6 +1321,10 @@ import std::os // os::args(), os::exec(), ...
import std::math // math::PI, math::sqrt(), ...
import std::collections // vector/hashset dot-methods + free functions
import std::bytes // bytes::create(), buf.get(), buf.write_u16_be(), ...
import std::crypto // crypto::sha256(), crypto::md5()
import std::base64 // base64::encode(), decode(), url_encode(), ...
import std::rng // rng::range(), secure_bytes(), uuid_string(), ...
import std::chrono // chrono::now_ms(), format(), DateTime, ...
import std::net // net::tcp_listen(), TcpStream, UdpSocket, ...
import std::thread // thread::spawn(), Mutex, Pool, ...
```
Expand Down Expand Up @@ -1325,6 +1388,52 @@ bytes c = bytes::concat(a, b)
bool e = bytes::equals(a, b)
```

**std::crypto** provides hashing helpers:

```lavina
import std::crypto

string sha = crypto::sha256("lavina")
string digest = crypto::md5("lavina")
```

**std::base64** provides text and binary Base64 helpers:

```lavina
import std::base64
import std::bytes

string encoded = base64::encode("hello")
string decoded = base64::decode(encoded)

bytes raw = bytes::from_string("Lavina")
bytes encoded_bytes = base64::encode_bytes(raw)
bytes decoded_bytes = base64::decode_bytes("TGF2aW5h")
```

**std::rng** provides pseudo-random and secure random generation:

```lavina
import std::rng

rng::seed(12345)
int roll = rng::range(1, 6)
float x = rng::next_double()
bytes token = rng::secure_bytes(32)
string uuid = rng::uuid_string()
```

**std::chrono** provides time, date, and sleep helpers:

```lavina
import std::chrono

int now_ms = chrono::now_ms()
chrono::DateTime dt = chrono::current()
string stamp = chrono::format(dt, "%Y-%m-%d %H:%M:%S.{ms}")
chrono::sleep_ms(50)
```

**std::net** provides TCP/UDP networking and DNS resolution:

```lavina
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ test:
;; \
*) \
/tmp/lavina_next compile $$f 2>/dev/null && \
$$dir/$$name 2>/dev/null; \
$$dir/$$name; \
if [ $$? -eq 0 ]; then \
echo " PASS $$name"; \
passed=$$((passed + 1)); \
Expand Down
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ sudo cp -r lib/* /usr/local/lib/
git clone https://github.com/Raumberg/lavina.git
cd lavina
make bootstrap # compile compiler from saved C++ snapshot
make test # run the test suite (37 tests)
make test # run the test suite
make build # optimized binary → build/
make install # install to /usr/local/ (or: make install PREFIX=~/.local)
```
Expand Down Expand Up @@ -115,6 +115,10 @@ import std::fs
import std::os
import std::math
import std::collections
import std::crypto
import std::base64
import std::rng
import std::chrono

void fn main():
// File I/O
Expand All @@ -128,6 +132,14 @@ void fn main():
print("pi = ${math::PI}")
print("sqrt(2) = ${math::sqrt(2.0)}")

// Crypto + encoding
print(crypto::sha256("lavina"))
print(base64::encode("hello"))

// Random + time
print("roll = ${rng::range(1, 6)}")
print("now = ${chrono::format_current()}")

// Collections — dot-notation via extend
vector[int] nums = [1, 2, 3, 4, 5]
auto doubled = nums.map((int x) => x * 2)
Expand Down Expand Up @@ -157,8 +169,8 @@ void fn main():
src/ compiler source (.lv): scanner, parser, checker, codegen, main
stages/ C++ snapshot for bootstrapping (stage-latest.cpp)
runtime/ C++ runtime header and support libraries
liblavina/ C++ runtime modules (12 headers)
std/ standard library modules (fs, os, math)
liblavina/ C++ runtime modules
std/ standard library modules (fs, os, math, bytes, net, thread, crypto, base64, rng, chrono)
tests/ test suite (.lv files)
examples/ example programs
lvpkg/ package manager (written in Lavina)
Expand Down
4 changes: 4 additions & 0 deletions runtime/lavina.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading