8 个版本 (4 个重大变更)
0.5.0 | 2022 年 12 月 29 日 |
---|---|
0.4.0 | 2022 年 11 月 2 日 |
0.3.3 | 2022 年 10 月 26 日 |
0.2.0 | 2022 年 4 月 3 日 |
0.1.0 | 2022 年 3 月 5 日 |
#276 in WebAssembly
29KB
560 行
Daku v1.0.0-alpha.2
Daku 是一个类似 WASI 的系统接口 API,但有不同的目标。
由于目前处于 alpha 阶段,一些事情可能会改变,但变化的可能性不大。alpha、beta 和预发布阶段不会持续很长时间(一旦有实现,它将完全稳定)。
目标
- 异步优先
- 立即稳定
- 简单
- 减少系统调用
- 基于通道
- 通过门户实现安全
- 反 POSIX
- 全面的多媒体支持
API
大库 API 导出单个函数 ar()
(import "daku" "ar" (func $event
(param $cmd_size i32) ;; List[Command].size
(param $cmd_data i32) ;; List[Command].reference
(result i32) ;; List[Uint32].size
))
该函数将多个异步任务排队,作为列表传递(前两个参数)。当任何异步任务完成时,它会被推送到就绪列表,函数返回已完成任务的数量。每次调用 ar()
都会清除就绪列表。
命令
#[repr(C, packed)]
struct Command {
/// Ready index for when command completes
ready: u32,
/// Channel id to use
channel: u32,
/// Data buffer size
size: u32,
/// Data buffer reference
data: *const (),
}
通道
通道 0 是特殊的,允许您连接到门户。
#[repr(C, packed)]
struct Connect {
/// The capacity of the ready list
ready_capacity: u32,
/// Reference to uninitialized ready list
ready_data: *mut u32,
/// The number of new portals
portals_size: u32,
/// in: List of new portal IDs - out: List of new portal channel IDs
portals_data: *mut u32,
}
有关门户命令 API,请参阅 门户。
类型
时间戳
#[repr(transparent)]
struct Timestamp {
/// The number of TAI microseconds since Jan 1 00:00:00.000_000, year 0 in
/// [ISO 8601:2004](https://en.wikipedia.org/wiki/ISO_8601)
///
/// This gives about a range of ±292_470 years since year 0.
///
/// This differs from Unix time in 3 ways:
/// - Epoch is 0000-01-01T00:00:00.000_000 TAI instead of
/// 1970-01-01T00:00:00.000_000 UTC
/// - Precision is microseconds instead of seconds
/// - TAI not UTC, meaning that a leap second gets representation, rather
/// than being represented as repeat of previous second as it would be in
/// unix time.
micros: i64,
}
时间
#[repr(C, packed)]
struct Time {
/// Range: 0 ~ 23 (always UTC, localized only for display)
hour: u8,
/// Range: 0 ~ 59
minute: u8,
/// Range: 0 ~ 60_999 (can represent leap seconds)
millis: u16,
}
日期
#[repr(C, packed)]
struct Date {
/// Range: 0 ~ 65_535
year: u16,
/// Range: 1 ~ 12
month: u8,
/// Range: (of week: 1 ~ 7) << 5 | (of month: 1 ~ 31)
day: u8,
}
日期时间
#[repr(C, packed)]
struct DateTime {
date: Date,
time: Time,
}
列表
#[repr(C, packed)]
struct List<T> {
size: u32,
data: *mut T,
}
文本
#[repr(C, packed)]
struct Text {
/// Number of bytes
size: usize,
/// UTF-8 String
data: *mut u8,
}
时区
#[repr(C, u32)]
enum TimeDesignation {
Utc = 0,
}
#[repr(C, packed)]
struct TimeAdjustment {
/// Time to replace
when: DateTime,
/// New time
new: DateTime,
}
#[repr(C, packed)]
struct LeapSecond {
/// Which year
year: i16,
/// Always the last day of the month
month: u8,
/// Direction: Either -1 or +1
delta: i8,
}
#[repr(C, packed)]
struct TimeZone {
/// Name of TimeZone (abbreviated, null terminated unless size 6)
designation: TimeDesignation,
/// List of adjustments made in this timezone
deltas: List<TimeAdjustment>,
/// Replace UTC jan 1 00:00:00:000 year 0 with Local time adjustments
///
/// This must be equivalent to all of the adjustments in `deltas` plus
/// any daylight savings time modifications.
offset: DateTime,
/// List of leap seconds
leap_seconds: List<LeapSecond>,
/// Sum of leap seconds
leap: i16,
/// Is daylight savings time?
is_dst: bool,
/// Reserved for future use
reserved: u8,
}
语言
#[repr(C, u32)]
enum Language {
/// English United States
EnUS = u32::from_ne_bytes(*b"enUS"),
/// English Great Britain
EnGB = u32::from_ne_bytes(*b"enGB"),
/// Esperanto
EoXX = u32::from_ne_bytes(*b"eoXX"),
}
#[repr(C, packed)]
struct Lang {
/// List of languages in order of user preference (0 is most preferred)
list: List<Language>,
}
依赖项
~22KB