forked from AbleOS/ableos
108 lines
2.3 KiB
Plaintext
108 lines
2.3 KiB
Plaintext
.{math: .{Vec2}, buffer, memory} := @use("../../stn/src/lib.hb");
|
|
.{Surface} := @use("../../render/src/lib.hb")
|
|
|
|
$BUFFER_SERVER := "sunset_server\0"
|
|
$BUFFER_CLIENT := "sunset_client\0"
|
|
|
|
Channel := packed struct {
|
|
client: uint,
|
|
server: uint,
|
|
}
|
|
|
|
client := @use("./client.hb")
|
|
server := @use("./server.hb")
|
|
message := @use("./message.hb")
|
|
permissions := @use("./permissions.hb")
|
|
|
|
opaque := fn(i: uint): bool {
|
|
if i == 0 {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
sleep := fn(): void {
|
|
i := 10000000
|
|
loop if opaque(i) break else i -= 1
|
|
}
|
|
|
|
$send_message := fn($Expr: type, kind: uint, msg: Expr, buffer_id: uint): void {
|
|
buffer.write(?Message(Expr), buffer_id, &@as(?Message(Expr), .(.(kind), msg)))
|
|
}
|
|
|
|
$send_header := fn(kind: uint, buffer_id: uint): void {
|
|
buffer.write(?MessageHeader, buffer_id, &@as(?MessageHeader, .(kind)))
|
|
}
|
|
|
|
$recv_message := fn($Expr: type, buffer_id: uint): Message(Expr) {
|
|
response := @as(?Message(Expr), null)
|
|
buffer.recv(?Message(Expr), buffer_id, &response)
|
|
return response
|
|
}
|
|
|
|
$recv_header := fn(buffer_id: uint): ?MessageHeader {
|
|
response := @as(?MessageHeader, null)
|
|
buffer.recv(?MessageHeader, buffer_id, &response)
|
|
return response
|
|
}
|
|
|
|
await_channel := fn(): Channel {
|
|
server_id := 0
|
|
loop if server_id == 0 {
|
|
server_id = buffer.search(BUFFER_SERVER)
|
|
}
|
|
client_id := 0
|
|
loop if client_id == 0 {
|
|
client_id = buffer.search(BUFFER_CLIENT)
|
|
}
|
|
return .{client: client_id, server: server_id}
|
|
}
|
|
|
|
await_message := fn($Expr: type, buffer_id: uint): Message(Expr) {
|
|
response := @as(?Message(Expr), null)
|
|
loop {
|
|
buffer.recv(?Message(Expr), buffer_id, &response)
|
|
if response != null {
|
|
return @as(Message(Expr), response)
|
|
}
|
|
}
|
|
}
|
|
|
|
await_header := fn(buffer_id: uint): MessageHeader {
|
|
response := @as(?MessageHeader, null)
|
|
loop {
|
|
buffer.recv(?MessageHeader, buffer_id, &response)
|
|
if response != null {
|
|
return @as(?MessageHeader, response)
|
|
}
|
|
}
|
|
}
|
|
|
|
MessageHeader := packed struct {
|
|
kind: uint,
|
|
}
|
|
|
|
Message := fn($Expr: type): type {
|
|
return packed struct {
|
|
header: MessageHeader,
|
|
body: Expr,
|
|
}
|
|
}
|
|
|
|
WindowProps := struct {
|
|
position: Vec2(uint),
|
|
dimensions: Vec2(uint),
|
|
// ! replace with owned string type later
|
|
title: ^u8,
|
|
}
|
|
|
|
WindowData := struct {
|
|
props: WindowProps,
|
|
channel: Channel,
|
|
permissions: uint,
|
|
}
|
|
|
|
Window := struct {
|
|
data: WindowData,
|
|
surface: Surface,
|
|
} |