Panel modules in the wasm compositor: the host runs them (moonplasma:host/plasmoids)
CI / test (push) Failing after 46s
CI / test (push) Failing after 46s
A component can't embed a second wasm runtime, so the compositor drives panel modules through a host import and the wasmtime host instantiates them: load, render, popup, on-event, plus the data they read (apps, windows, layouts, modules, system) and the requests they make (launch, focus window, set layout, load/unload, browse), with a zenity file chooser for 'Add widget'. - wit/worlds.wit: world plasmoid-host, every capability a module can import + the plasmoid export. The host instantiates any module against it; a module imports the subset it uses. - wit/host/plasmoids.wit + generated MoonBit bindings; compositor/wasm gets a wasm backend (wasm_host.mbt) with the same public API as the native wasmer one. - host-wasm/src/plasmoid.rs: typed component bindings, one Store per module, shared host data. Tests load the built launcher/layout modules and drive them (typed filter, Enter, launch request). - scripts/gen-native-stubs.py keeps a package's imports when it rewrites moon.pkg. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5c3bebc7fd
commit
e769566d8f
23 files changed
+2001
-302
No files matched your search
@@ -6,11 +6,6 @@ fn wasmImportLoad(p0 : Int, p1 : Int, p2 : Int) -> Int = "moonplasma:host/font@0
|
||||
///|
|
||||
fn wasmImportRasterise(p0 : Int, p1 : Int, p2 : Int, p3 : Int) = "moonplasma:host/font@0.1.0" "rasterise"
|
||||
|
||||
///|
|
||||
#owned(str)
|
||||
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] =
|
||||
#|(func (param i32) (param i32) (result i32)
|
||||
@@ -19,8 +14,8 @@ extern "wasm" fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] =
|
||||
#| local.get 0)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0 i32.load)
|
||||
extern "wasm" fn mbt_ffi_free(position : Int) =
|
||||
#|(func (param i32) local.get 0 call $moonbit.decref)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
|
||||
@@ -30,6 +25,11 @@ extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
|
||||
#| local.get 1)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_free(position : Int) =
|
||||
#|(func (param i32) local.get 0 call $moonbit.decref)
|
||||
#owned(str)
|
||||
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0 i32.load)
|
||||
|
||||
@@ -10,18 +10,13 @@ fn wasmImportRasterise(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Unit {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_str2ptr(str : String) -> Int {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_load32(offset : Int) -> Int {
|
||||
fn mbt_ffi_free(position : Int) -> Unit {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
@@ -31,6 +26,11 @@ fn mbt_ffi_malloc(size : Int) -> Int {
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_free(position : Int) -> Unit {
|
||||
fn mbt_ffi_str2ptr(str : String) -> Int {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_load32(offset : Int) -> Int {
|
||||
abort("wasm-only")
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||
|
||||
///|
|
||||
fn wasmImportLoad(p0 : Int, p1 : Int, p2 : Int) = "moonplasma:host/plasmoids@0.1.0" "load"
|
||||
|
||||
///|
|
||||
fn wasmImportUnload(p0 : Int) = "moonplasma:host/plasmoids@0.1.0" "unload"
|
||||
|
||||
///|
|
||||
fn wasmImportSetTokens(p0 : Int) = "moonplasma:host/plasmoids@0.1.0" "set-tokens"
|
||||
|
||||
///|
|
||||
fn wasmImportRender(p0 : Int, p1 : Int, p2 : Int, p3 : Int) = "moonplasma:host/plasmoids@0.1.0" "render"
|
||||
|
||||
///|
|
||||
fn wasmImportPopup(p0 : Int, p1 : Int) = "moonplasma:host/plasmoids@0.1.0" "popup"
|
||||
|
||||
///|
|
||||
fn wasmImportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int) -> Int = "moonplasma:host/plasmoids@0.1.0" "on-event"
|
||||
|
||||
///|
|
||||
fn wasmImportPublishTable(p0 : Int, p1 : Int, p2 : Int) = "moonplasma:host/plasmoids@0.1.0" "publish-table"
|
||||
|
||||
///|
|
||||
fn wasmImportPublishState(p0 : Int, p1 : Int) = "moonplasma:host/plasmoids@0.1.0" "publish-state"
|
||||
|
||||
///|
|
||||
fn wasmImportPublishSystem(p0 : Int, p1 : Int64, p2 : Int64, p3 : Int, p4 : Int, p5 : Int64, p6 : Int64, p7 : Int64, p8 : Int) = "moonplasma:host/plasmoids@0.1.0" "publish-system"
|
||||
|
||||
///|
|
||||
fn wasmImportPublishWindows(p0 : Int, p1 : Int) = "moonplasma:host/plasmoids@0.1.0" "publish-windows"
|
||||
|
||||
///|
|
||||
fn wasmImportNextRequest(p0 : Int) = "moonplasma:host/plasmoids@0.1.0" "next-request"
|
||||
|
||||
///|
|
||||
fn wasmImportTakeFocusRequest(p0 : Int) = "moonplasma:host/plasmoids@0.1.0" "take-focus-request"
|
||||
|
||||
///|
|
||||
fn wasmImportListWasmFiles(p0 : Int, p1 : Int, p2 : Int) = "moonplasma:host/plasmoids@0.1.0" "list-wasm-files"
|
||||
|
||||
///|
|
||||
fn wasmImportPickerStart() -> Int = "moonplasma:host/plasmoids@0.1.0" "picker-start"
|
||||
|
||||
///|
|
||||
fn wasmImportPickerPoll(p0 : Int) = "moonplasma:host/plasmoids@0.1.0" "picker-poll"
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_store8(offset : Int, value : Int) =
|
||||
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store8)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
|
||||
#|(func (param i32) (result i32) (local i32)
|
||||
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
|
||||
#| local.tee 1 i32.const 0 call $moonbit.init_array8
|
||||
#| local.get 1)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_free(position : Int) =
|
||||
#|(func (param i32) local.get 0 call $moonbit.decref)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String =
|
||||
#|(func (param i32) (param i32) (result i32)
|
||||
#| local.get 0
|
||||
#| local.get 1 call $moonbit.init_array16
|
||||
#| local.get 0)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0 i32.load)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_store32(offset : Int, value : Int) =
|
||||
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store)
|
||||
|
||||
///|
|
||||
#owned(str)
|
||||
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0)
|
||||
|
||||
///|
|
||||
#owned(bytes)
|
||||
extern "wasm" fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_store64(offset : Int, value : Int64) =
|
||||
#|(func (param i32) (param i64) local.get 0 local.get 1 i64.store)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_load64(offset : Int) -> Int64 =
|
||||
#|(func (param i32) (result i64) local.get 0 i64.load)
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import {
|
||||
"moonplasma/desktop/interface/moonplasma/desktop/theme" @theme,
|
||||
"moonplasma/desktop/interface/moonplasma/desktop/types" @types,
|
||||
}
|
||||
|
||||
warnings = "-44"
|
||||
|
||||
// ffi.mbt is generated and wasm-only; native builds use native_stub.mbt (scripts/gen-native-stubs.py).
|
||||
options(
|
||||
targets: {
|
||||
"ffi.mbt": ["wasm", "wasm-gc"],
|
||||
"native_stub.mbt": ["native"],
|
||||
},
|
||||
)
|
||||
@@ -0,0 +1,131 @@
|
||||
// Generated by scripts/gen-native-stubs.py. Native stand-ins for the wasm-only ffi.mbt.
|
||||
|
||||
///|
|
||||
fn wasmImportLoad(p0 : Int, p1 : Int, p2 : Int) -> Unit {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportUnload(p0 : Int) -> Unit {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportSetTokens(p0 : Int) -> Unit {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportRender(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Unit {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportPopup(p0 : Int, p1 : Int) -> Unit {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int) -> Int {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportPublishTable(p0 : Int, p1 : Int, p2 : Int) -> Unit {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportPublishState(p0 : Int, p1 : Int) -> Unit {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportPublishSystem(p0 : Int, p1 : Int64, p2 : Int64, p3 : Int, p4 : Int, p5 : Int64, p6 : Int64, p7 : Int64, p8 : Int) -> Unit {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportPublishWindows(p0 : Int, p1 : Int) -> Unit {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportNextRequest(p0 : Int) -> Unit {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportTakeFocusRequest(p0 : Int) -> Unit {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportListWasmFiles(p0 : Int, p1 : Int, p2 : Int) -> Unit {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportPickerStart() -> Int {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportPickerPoll(p0 : Int) -> Unit {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_store8(offset : Int, value : Int) -> Unit {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_load8_u(offset : Int) -> Int {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_malloc(size : Int) -> Int {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_free(position : Int) -> Unit {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_load32(offset : Int) -> Int {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_store32(offset : Int, value : Int) -> Unit {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_str2ptr(str : String) -> Int {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_store64(offset : Int, value : Int64) -> Unit {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_load64(offset : Int) -> Int64 {
|
||||
abort("wasm-only")
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
// Generated using `moon info`, DON'T EDIT IT
|
||||
package "moonplasma/desktop/interface/moonplasma/host/plasmoids"
|
||||
|
||||
import {
|
||||
"moonplasma/desktop/interface/moonplasma/desktop/theme",
|
||||
"moonplasma/desktop/interface/moonplasma/desktop/types",
|
||||
}
|
||||
|
||||
// Values
|
||||
pub fn list_wasm_files(String) -> Array[String]
|
||||
|
||||
pub fn load(String) -> Result[Loaded, String]
|
||||
|
||||
pub fn next_request() -> Request?
|
||||
|
||||
pub fn on_event(UInt32, Bool, @types.InputEvent) -> Bool
|
||||
|
||||
pub fn picker_poll() -> PickerState
|
||||
|
||||
pub fn picker_start() -> Bool
|
||||
|
||||
pub fn popup(UInt32) -> PopupSurface?
|
||||
|
||||
pub fn publish_state(Int32, Bool) -> Unit
|
||||
|
||||
pub fn publish_system(SystemSnapshot) -> Unit
|
||||
|
||||
pub fn publish_table(UInt32, FixedArray[Byte]) -> Unit
|
||||
|
||||
pub fn publish_windows(Array[WindowEntry]) -> Unit
|
||||
|
||||
pub fn render(UInt32, @types.Size) -> Array[@types.DrawOp]
|
||||
|
||||
pub fn set_tokens(@theme.Tokens) -> Unit
|
||||
|
||||
pub fn take_focus_request() -> UInt64?
|
||||
|
||||
pub fn unload(UInt32) -> Unit
|
||||
|
||||
// Errors
|
||||
|
||||
// Types and methods
|
||||
pub(all) struct Loaded {
|
||||
handle : UInt32
|
||||
id : String
|
||||
name : String
|
||||
preferred : @types.Size
|
||||
min_width : UInt32
|
||||
stretch : Bool
|
||||
imports : Array[String]
|
||||
}
|
||||
|
||||
pub(all) enum PickerState {
|
||||
Open
|
||||
Cancelled
|
||||
Chosen(String)
|
||||
}
|
||||
|
||||
pub(all) struct PopupSurface {
|
||||
box : @types.Size
|
||||
ops : Array[@types.DrawOp]
|
||||
}
|
||||
|
||||
pub(all) enum Request {
|
||||
Launch(String)
|
||||
FocusWindow(Int32)
|
||||
SetLayout(Int32)
|
||||
SetInspector(Bool)
|
||||
LoadModule(String)
|
||||
UnloadInstance(String)
|
||||
Browse
|
||||
}
|
||||
|
||||
pub(all) struct SystemSnapshot {
|
||||
cpu_permille : UInt32
|
||||
mem_used_kib : UInt64
|
||||
mem_total_kib : UInt64
|
||||
battery_percent : Int32
|
||||
charging : Bool
|
||||
uptime_secs : UInt64
|
||||
net_rx_bytes_per_sec : UInt64
|
||||
net_tx_bytes_per_sec : UInt64
|
||||
load_centi : UInt32
|
||||
}
|
||||
|
||||
pub(all) struct WindowEntry {
|
||||
id : UInt64
|
||||
title : String
|
||||
app_id : String
|
||||
focused : Bool
|
||||
}
|
||||
|
||||
// Type aliases
|
||||
|
||||
// Traits
|
||||
@@ -0,0 +1,489 @@
|
||||
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||
///|
|
||||
/// A loaded module. `imports` is its capability grant: the host interfaces its binary imports
|
||||
/// (besides theme), e.g. ["clock"] or ["windows", "system"].
|
||||
pub(all) struct Loaded {
|
||||
handle : UInt; id : String; name : String; preferred : @types.Size; min_width : UInt; stretch : Bool; imports : Array[String]
|
||||
}
|
||||
///|
|
||||
pub(all) struct PopupSurface {
|
||||
box : @types.Size; ops : Array[@types.DrawOp]
|
||||
}
|
||||
///|
|
||||
pub(all) struct SystemSnapshot {
|
||||
cpu_permille : UInt; mem_used_kib : UInt64; mem_total_kib : UInt64; battery_percent : Int; charging : Bool; uptime_secs : UInt64; net_rx_bytes_per_sec : UInt64; net_tx_bytes_per_sec : UInt64; load_centi : UInt
|
||||
}
|
||||
///|
|
||||
pub(all) struct WindowEntry {
|
||||
id : UInt64; title : String; app_id : String; focused : Bool
|
||||
}
|
||||
///|
|
||||
/// ---- what modules asked of the host ----
|
||||
pub(all) enum Request {
|
||||
Launch(String)
|
||||
FocusWindow(Int)
|
||||
SetLayout(Int)
|
||||
SetInspector(Bool)
|
||||
LoadModule(String)
|
||||
UnloadInstance(String)
|
||||
Browse
|
||||
}
|
||||
///|
|
||||
/// A native file-chooser dialog (zenity on the host session) for "Add widget".
|
||||
pub(all) enum PickerState {
|
||||
Open
|
||||
Cancelled
|
||||
Chosen(String)
|
||||
}
|
||||
///|
|
||||
/// Load the plasmoid component at `path`. The error is a short reason.
|
||||
pub fn load(path : String) -> Result[Loaded, String] {
|
||||
|
||||
let ptr = mbt_ffi_str2ptr(path)
|
||||
let return_area = mbt_ffi_malloc(48)
|
||||
wasmImportLoad(ptr, path.length(), return_area);
|
||||
|
||||
let lifted = match (mbt_ffi_load8_u((return_area) + 0)) {
|
||||
0 => {
|
||||
|
||||
let result = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 8), mbt_ffi_load32((return_area) + 12))
|
||||
|
||||
let result0 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 16), mbt_ffi_load32((return_area) + 20))
|
||||
|
||||
let array : Array[String] = [];
|
||||
for index = 0; index < (mbt_ffi_load32((return_area) + 44)); index = index + 1 {
|
||||
let iter_base = (mbt_ffi_load32((return_area) + 40)) + (index * 8)
|
||||
|
||||
let result1 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4))
|
||||
|
||||
array.push(result1)
|
||||
}
|
||||
mbt_ffi_free(mbt_ffi_load32((return_area) + 40))
|
||||
|
||||
Result::Ok(Loaded::{handle : (mbt_ffi_load32((return_area) + 4)).reinterpret_as_uint(), id : result, name : result0, preferred : @types.Size::{w : (mbt_ffi_load32((return_area) + 24)).reinterpret_as_uint(), h : (mbt_ffi_load32((return_area) + 28)).reinterpret_as_uint()}, min_width : (mbt_ffi_load32((return_area) + 32)).reinterpret_as_uint(), stretch : (mbt_ffi_load8_u((return_area) + 36) != 0), imports : array})
|
||||
}
|
||||
1 => {
|
||||
|
||||
let result2 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 4), mbt_ffi_load32((return_area) + 8))
|
||||
|
||||
Result::Err(result2)
|
||||
}
|
||||
_ => panic()
|
||||
}
|
||||
let ret = lifted
|
||||
mbt_ffi_free(ptr)
|
||||
mbt_ffi_free(return_area)
|
||||
return ret
|
||||
|
||||
}
|
||||
///|
|
||||
pub fn unload(handle : UInt) -> Unit {
|
||||
|
||||
wasmImportUnload((handle).reinterpret_as_int());
|
||||
|
||||
}
|
||||
///|
|
||||
/// The theme the modules see through `theme.get-tokens` (set before drawing so a swap shows at once).
|
||||
pub fn set_tokens(t : @theme.Tokens) -> Unit {
|
||||
|
||||
let return_area = mbt_ffi_malloc(64)
|
||||
|
||||
let ptr = mbt_ffi_str2ptr((t).name)
|
||||
mbt_ffi_store32((return_area) + 4, (t).name.length())
|
||||
mbt_ffi_store32((return_area) + 0, ptr)
|
||||
mbt_ffi_store8((return_area) + 8, ((((t).palette).desktop_top).r).to_int())
|
||||
mbt_ffi_store8((return_area) + 9, ((((t).palette).desktop_top).g).to_int())
|
||||
mbt_ffi_store8((return_area) + 10, ((((t).palette).desktop_top).b).to_int())
|
||||
mbt_ffi_store8((return_area) + 11, ((((t).palette).desktop_top).a).to_int())
|
||||
mbt_ffi_store8((return_area) + 12, ((((t).palette).desktop_bottom).r).to_int())
|
||||
mbt_ffi_store8((return_area) + 13, ((((t).palette).desktop_bottom).g).to_int())
|
||||
mbt_ffi_store8((return_area) + 14, ((((t).palette).desktop_bottom).b).to_int())
|
||||
mbt_ffi_store8((return_area) + 15, ((((t).palette).desktop_bottom).a).to_int())
|
||||
mbt_ffi_store8((return_area) + 16, ((((t).palette).surface).r).to_int())
|
||||
mbt_ffi_store8((return_area) + 17, ((((t).palette).surface).g).to_int())
|
||||
mbt_ffi_store8((return_area) + 18, ((((t).palette).surface).b).to_int())
|
||||
mbt_ffi_store8((return_area) + 19, ((((t).palette).surface).a).to_int())
|
||||
mbt_ffi_store8((return_area) + 20, ((((t).palette).surface_hover).r).to_int())
|
||||
mbt_ffi_store8((return_area) + 21, ((((t).palette).surface_hover).g).to_int())
|
||||
mbt_ffi_store8((return_area) + 22, ((((t).palette).surface_hover).b).to_int())
|
||||
mbt_ffi_store8((return_area) + 23, ((((t).palette).surface_hover).a).to_int())
|
||||
mbt_ffi_store8((return_area) + 24, ((((t).palette).surface_popup).r).to_int())
|
||||
mbt_ffi_store8((return_area) + 25, ((((t).palette).surface_popup).g).to_int())
|
||||
mbt_ffi_store8((return_area) + 26, ((((t).palette).surface_popup).b).to_int())
|
||||
mbt_ffi_store8((return_area) + 27, ((((t).palette).surface_popup).a).to_int())
|
||||
mbt_ffi_store8((return_area) + 28, ((((t).palette).foreground).r).to_int())
|
||||
mbt_ffi_store8((return_area) + 29, ((((t).palette).foreground).g).to_int())
|
||||
mbt_ffi_store8((return_area) + 30, ((((t).palette).foreground).b).to_int())
|
||||
mbt_ffi_store8((return_area) + 31, ((((t).palette).foreground).a).to_int())
|
||||
mbt_ffi_store8((return_area) + 32, ((((t).palette).foreground_muted).r).to_int())
|
||||
mbt_ffi_store8((return_area) + 33, ((((t).palette).foreground_muted).g).to_int())
|
||||
mbt_ffi_store8((return_area) + 34, ((((t).palette).foreground_muted).b).to_int())
|
||||
mbt_ffi_store8((return_area) + 35, ((((t).palette).foreground_muted).a).to_int())
|
||||
mbt_ffi_store8((return_area) + 36, ((((t).palette).accent).r).to_int())
|
||||
mbt_ffi_store8((return_area) + 37, ((((t).palette).accent).g).to_int())
|
||||
mbt_ffi_store8((return_area) + 38, ((((t).palette).accent).b).to_int())
|
||||
mbt_ffi_store8((return_area) + 39, ((((t).palette).accent).a).to_int())
|
||||
mbt_ffi_store8((return_area) + 40, ((((t).palette).accent_foreground).r).to_int())
|
||||
mbt_ffi_store8((return_area) + 41, ((((t).palette).accent_foreground).g).to_int())
|
||||
mbt_ffi_store8((return_area) + 42, ((((t).palette).accent_foreground).b).to_int())
|
||||
mbt_ffi_store8((return_area) + 43, ((((t).palette).accent_foreground).a).to_int())
|
||||
mbt_ffi_store8((return_area) + 44, ((((t).palette).border).r).to_int())
|
||||
mbt_ffi_store8((return_area) + 45, ((((t).palette).border).g).to_int())
|
||||
mbt_ffi_store8((return_area) + 46, ((((t).palette).border).b).to_int())
|
||||
mbt_ffi_store8((return_area) + 47, ((((t).palette).border).a).to_int())
|
||||
mbt_ffi_store32((return_area) + 48, ((t).font_size).reinterpret_as_int())
|
||||
mbt_ffi_store32((return_area) + 52, ((t).radius).reinterpret_as_int())
|
||||
mbt_ffi_store32((return_area) + 56, ((t).spacing).reinterpret_as_int())
|
||||
mbt_ffi_store32((return_area) + 60, ((t).panel_height).reinterpret_as_int())
|
||||
wasmImportSetTokens(return_area);
|
||||
mbt_ffi_free(return_area)
|
||||
mbt_ffi_free(ptr)
|
||||
|
||||
}
|
||||
///|
|
||||
pub fn render(handle : UInt, box : @types.Size) -> Array[@types.DrawOp] {
|
||||
|
||||
let return_area = mbt_ffi_malloc(8)
|
||||
wasmImportRender((handle).reinterpret_as_int(), ((box).w).reinterpret_as_int(), ((box).h).reinterpret_as_int(), return_area);
|
||||
|
||||
let array : Array[@types.DrawOp] = [];
|
||||
for index = 0; index < (mbt_ffi_load32((return_area) + 4)); index = index + 1 {
|
||||
let iter_base = (mbt_ffi_load32((return_area) + 0)) + (index * 32)
|
||||
|
||||
let lifted = match (mbt_ffi_load8_u((iter_base) + 0)) {
|
||||
0 => {
|
||||
|
||||
@types.DrawOp::FillRect(@types.FillRectOp::{rect : @types.Rect::{x : mbt_ffi_load32((iter_base) + 4), y : mbt_ffi_load32((iter_base) + 8), w : (mbt_ffi_load32((iter_base) + 12)).reinterpret_as_uint(), h : (mbt_ffi_load32((iter_base) + 16)).reinterpret_as_uint()}, color : @types.Color::{r : (mbt_ffi_load8_u((iter_base) + 20)).to_byte(), g : (mbt_ffi_load8_u((iter_base) + 21)).to_byte(), b : (mbt_ffi_load8_u((iter_base) + 22)).to_byte(), a : (mbt_ffi_load8_u((iter_base) + 23)).to_byte()}, radius : (mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint()})
|
||||
}
|
||||
1 => {
|
||||
|
||||
@types.DrawOp::StrokeRect(@types.StrokeRectOp::{rect : @types.Rect::{x : mbt_ffi_load32((iter_base) + 4), y : mbt_ffi_load32((iter_base) + 8), w : (mbt_ffi_load32((iter_base) + 12)).reinterpret_as_uint(), h : (mbt_ffi_load32((iter_base) + 16)).reinterpret_as_uint()}, color : @types.Color::{r : (mbt_ffi_load8_u((iter_base) + 20)).to_byte(), g : (mbt_ffi_load8_u((iter_base) + 21)).to_byte(), b : (mbt_ffi_load8_u((iter_base) + 22)).to_byte(), a : (mbt_ffi_load8_u((iter_base) + 23)).to_byte()}, width : (mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint(), radius : (mbt_ffi_load32((iter_base) + 28)).reinterpret_as_uint()})
|
||||
}
|
||||
2 => {
|
||||
|
||||
@types.DrawOp::Line(@types.LineOp::{start : @types.Point::{x : mbt_ffi_load32((iter_base) + 4), y : mbt_ffi_load32((iter_base) + 8)}, end : @types.Point::{x : mbt_ffi_load32((iter_base) + 12), y : mbt_ffi_load32((iter_base) + 16)}, color : @types.Color::{r : (mbt_ffi_load8_u((iter_base) + 20)).to_byte(), g : (mbt_ffi_load8_u((iter_base) + 21)).to_byte(), b : (mbt_ffi_load8_u((iter_base) + 22)).to_byte(), a : (mbt_ffi_load8_u((iter_base) + 23)).to_byte()}, width : (mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint()})
|
||||
}
|
||||
3 => {
|
||||
|
||||
@types.DrawOp::Circle(@types.CircleOp::{center : @types.Point::{x : mbt_ffi_load32((iter_base) + 4), y : mbt_ffi_load32((iter_base) + 8)}, radius : (mbt_ffi_load32((iter_base) + 12)).reinterpret_as_uint(), color : @types.Color::{r : (mbt_ffi_load8_u((iter_base) + 16)).to_byte(), g : (mbt_ffi_load8_u((iter_base) + 17)).to_byte(), b : (mbt_ffi_load8_u((iter_base) + 18)).to_byte(), a : (mbt_ffi_load8_u((iter_base) + 19)).to_byte()}, filled : (mbt_ffi_load8_u((iter_base) + 20) != 0)})
|
||||
}
|
||||
4 => {
|
||||
|
||||
let result = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 12), mbt_ffi_load32((iter_base) + 16))
|
||||
|
||||
@types.DrawOp::Text(@types.TextOp::{origin : @types.Point::{x : mbt_ffi_load32((iter_base) + 4), y : mbt_ffi_load32((iter_base) + 8)}, text : result, style : @types.TextStyle::{size : (mbt_ffi_load32((iter_base) + 20)).reinterpret_as_uint(), color : @types.Color::{r : (mbt_ffi_load8_u((iter_base) + 24)).to_byte(), g : (mbt_ffi_load8_u((iter_base) + 25)).to_byte(), b : (mbt_ffi_load8_u((iter_base) + 26)).to_byte(), a : (mbt_ffi_load8_u((iter_base) + 27)).to_byte()}, align : @types.TextAlign::from(mbt_ffi_load8_u((iter_base) + 28)), bold : (mbt_ffi_load8_u((iter_base) + 29) != 0)}})
|
||||
}
|
||||
5 => {
|
||||
|
||||
@types.DrawOp::PushClip(@types.Rect::{x : mbt_ffi_load32((iter_base) + 4), y : mbt_ffi_load32((iter_base) + 8), w : (mbt_ffi_load32((iter_base) + 12)).reinterpret_as_uint(), h : (mbt_ffi_load32((iter_base) + 16)).reinterpret_as_uint()})
|
||||
}
|
||||
6 => {
|
||||
|
||||
@types.DrawOp::PopClip
|
||||
}
|
||||
_ => panic()
|
||||
}
|
||||
|
||||
array.push(lifted)
|
||||
}
|
||||
mbt_ffi_free(mbt_ffi_load32((return_area) + 0))
|
||||
let ret = array
|
||||
mbt_ffi_free(return_area)
|
||||
return ret
|
||||
|
||||
}
|
||||
///|
|
||||
pub fn popup(handle : UInt) -> PopupSurface? {
|
||||
|
||||
let return_area = mbt_ffi_malloc(20)
|
||||
wasmImportPopup((handle).reinterpret_as_int(), return_area);
|
||||
|
||||
let lifted0 : PopupSurface? = match mbt_ffi_load8_u((return_area) + 0) {
|
||||
0 => Option::None
|
||||
1 => {
|
||||
|
||||
let array : Array[@types.DrawOp] = [];
|
||||
for index = 0; index < (mbt_ffi_load32((return_area) + 16)); index = index + 1 {
|
||||
let iter_base = (mbt_ffi_load32((return_area) + 12)) + (index * 32)
|
||||
|
||||
let lifted = match (mbt_ffi_load8_u((iter_base) + 0)) {
|
||||
0 => {
|
||||
|
||||
@types.DrawOp::FillRect(@types.FillRectOp::{rect : @types.Rect::{x : mbt_ffi_load32((iter_base) + 4), y : mbt_ffi_load32((iter_base) + 8), w : (mbt_ffi_load32((iter_base) + 12)).reinterpret_as_uint(), h : (mbt_ffi_load32((iter_base) + 16)).reinterpret_as_uint()}, color : @types.Color::{r : (mbt_ffi_load8_u((iter_base) + 20)).to_byte(), g : (mbt_ffi_load8_u((iter_base) + 21)).to_byte(), b : (mbt_ffi_load8_u((iter_base) + 22)).to_byte(), a : (mbt_ffi_load8_u((iter_base) + 23)).to_byte()}, radius : (mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint()})
|
||||
}
|
||||
1 => {
|
||||
|
||||
@types.DrawOp::StrokeRect(@types.StrokeRectOp::{rect : @types.Rect::{x : mbt_ffi_load32((iter_base) + 4), y : mbt_ffi_load32((iter_base) + 8), w : (mbt_ffi_load32((iter_base) + 12)).reinterpret_as_uint(), h : (mbt_ffi_load32((iter_base) + 16)).reinterpret_as_uint()}, color : @types.Color::{r : (mbt_ffi_load8_u((iter_base) + 20)).to_byte(), g : (mbt_ffi_load8_u((iter_base) + 21)).to_byte(), b : (mbt_ffi_load8_u((iter_base) + 22)).to_byte(), a : (mbt_ffi_load8_u((iter_base) + 23)).to_byte()}, width : (mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint(), radius : (mbt_ffi_load32((iter_base) + 28)).reinterpret_as_uint()})
|
||||
}
|
||||
2 => {
|
||||
|
||||
@types.DrawOp::Line(@types.LineOp::{start : @types.Point::{x : mbt_ffi_load32((iter_base) + 4), y : mbt_ffi_load32((iter_base) + 8)}, end : @types.Point::{x : mbt_ffi_load32((iter_base) + 12), y : mbt_ffi_load32((iter_base) + 16)}, color : @types.Color::{r : (mbt_ffi_load8_u((iter_base) + 20)).to_byte(), g : (mbt_ffi_load8_u((iter_base) + 21)).to_byte(), b : (mbt_ffi_load8_u((iter_base) + 22)).to_byte(), a : (mbt_ffi_load8_u((iter_base) + 23)).to_byte()}, width : (mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint()})
|
||||
}
|
||||
3 => {
|
||||
|
||||
@types.DrawOp::Circle(@types.CircleOp::{center : @types.Point::{x : mbt_ffi_load32((iter_base) + 4), y : mbt_ffi_load32((iter_base) + 8)}, radius : (mbt_ffi_load32((iter_base) + 12)).reinterpret_as_uint(), color : @types.Color::{r : (mbt_ffi_load8_u((iter_base) + 16)).to_byte(), g : (mbt_ffi_load8_u((iter_base) + 17)).to_byte(), b : (mbt_ffi_load8_u((iter_base) + 18)).to_byte(), a : (mbt_ffi_load8_u((iter_base) + 19)).to_byte()}, filled : (mbt_ffi_load8_u((iter_base) + 20) != 0)})
|
||||
}
|
||||
4 => {
|
||||
|
||||
let result = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 12), mbt_ffi_load32((iter_base) + 16))
|
||||
|
||||
@types.DrawOp::Text(@types.TextOp::{origin : @types.Point::{x : mbt_ffi_load32((iter_base) + 4), y : mbt_ffi_load32((iter_base) + 8)}, text : result, style : @types.TextStyle::{size : (mbt_ffi_load32((iter_base) + 20)).reinterpret_as_uint(), color : @types.Color::{r : (mbt_ffi_load8_u((iter_base) + 24)).to_byte(), g : (mbt_ffi_load8_u((iter_base) + 25)).to_byte(), b : (mbt_ffi_load8_u((iter_base) + 26)).to_byte(), a : (mbt_ffi_load8_u((iter_base) + 27)).to_byte()}, align : @types.TextAlign::from(mbt_ffi_load8_u((iter_base) + 28)), bold : (mbt_ffi_load8_u((iter_base) + 29) != 0)}})
|
||||
}
|
||||
5 => {
|
||||
|
||||
@types.DrawOp::PushClip(@types.Rect::{x : mbt_ffi_load32((iter_base) + 4), y : mbt_ffi_load32((iter_base) + 8), w : (mbt_ffi_load32((iter_base) + 12)).reinterpret_as_uint(), h : (mbt_ffi_load32((iter_base) + 16)).reinterpret_as_uint()})
|
||||
}
|
||||
6 => {
|
||||
|
||||
@types.DrawOp::PopClip
|
||||
}
|
||||
_ => panic()
|
||||
}
|
||||
|
||||
array.push(lifted)
|
||||
}
|
||||
mbt_ffi_free(mbt_ffi_load32((return_area) + 12))
|
||||
|
||||
Option::Some(PopupSurface::{box : @types.Size::{w : (mbt_ffi_load32((return_area) + 4)).reinterpret_as_uint(), h : (mbt_ffi_load32((return_area) + 8)).reinterpret_as_uint()}, ops : array})
|
||||
}
|
||||
_ => panic()
|
||||
}
|
||||
let ret = lifted0
|
||||
mbt_ffi_free(return_area)
|
||||
return ret
|
||||
|
||||
}
|
||||
///|
|
||||
/// Deliver an event to the module (`on-popup`: to its popup surface). True when it wants a redraw.
|
||||
pub fn on_event(handle : UInt, on_popup : Bool, event : @types.InputEvent) -> Bool {
|
||||
let cleanup_list : Array[Int] = []
|
||||
|
||||
let (lowered,lowered5,lowered6) = match event {
|
||||
PointerMove(payload) => {
|
||||
|
||||
((0), (payload).x, (payload).y)
|
||||
}
|
||||
PointerDown(payload0) => {
|
||||
|
||||
((1), (payload0).x, (payload0).y)
|
||||
}
|
||||
PointerUp(payload1) => {
|
||||
|
||||
((2), (payload1).x, (payload1).y)
|
||||
}
|
||||
PointerLeave => {
|
||||
|
||||
((3), 0, 0)
|
||||
}
|
||||
FocusLost => {
|
||||
|
||||
((4), 0, 0)
|
||||
}
|
||||
KeyDown(payload4) => {
|
||||
|
||||
let ptr = mbt_ffi_str2ptr(payload4)
|
||||
cleanup_list.push(ptr)
|
||||
|
||||
((5), ptr, payload4.length())
|
||||
}
|
||||
}
|
||||
let result : Int = wasmImportOnEvent((handle).reinterpret_as_int(), (if on_popup { 1 } else { 0 }), lowered, lowered5, lowered6);
|
||||
let ret = (result != 0)
|
||||
|
||||
cleanup_list.each(mbt_ffi_free)
|
||||
return ret
|
||||
|
||||
}
|
||||
///|
|
||||
/// ---- host data modules read through their capabilities ----
|
||||
/// Row tables, as built by compositor/wasm: a LE u32 row count, then per row each field as a LE
|
||||
/// i32 ('i') or a LE u32 byte length + UTF-8 ('s'). `which`: 0 apps (sssss: id name comment
|
||||
/// category glyph), 1 windows (isii: id title focused minimized), 2 layouts (s), 3 modules
|
||||
/// (sssi: id name path loaded), 4 instances (sss: slot module name).
|
||||
pub fn publish_table(which : UInt, rows : FixedArray[Byte]) -> Unit {
|
||||
|
||||
let ptr = mbt_ffi_bytes2ptr(rows)
|
||||
|
||||
wasmImportPublishTable((which).reinterpret_as_int(), ptr, rows.length());
|
||||
mbt_ffi_free(ptr)
|
||||
|
||||
}
|
||||
///|
|
||||
/// Layout mode (0 tiling, 1 monocle, 2 floating) and whether the Interface Explorer is on.
|
||||
pub fn publish_state(layout_mode : Int, inspector_on : Bool) -> Unit {
|
||||
|
||||
wasmImportPublishState(layout_mode, (if inspector_on { 1 } else { 0 }));
|
||||
|
||||
}
|
||||
///|
|
||||
pub fn publish_system(s : SystemSnapshot) -> Unit {
|
||||
|
||||
wasmImportPublishSystem(((s).cpu_permille).reinterpret_as_int(), ((s).mem_used_kib).reinterpret_as_int64(), ((s).mem_total_kib).reinterpret_as_int64(), (s).battery_percent, (if (s).charging { 1 } else { 0 }), ((s).uptime_secs).reinterpret_as_int64(), ((s).net_rx_bytes_per_sec).reinterpret_as_int64(), ((s).net_tx_bytes_per_sec).reinterpret_as_int64(), ((s).load_centi).reinterpret_as_int());
|
||||
|
||||
}
|
||||
///|
|
||||
pub fn publish_windows(wins : Array[WindowEntry]) -> Unit {
|
||||
let cleanup_list : Array[Int] = []
|
||||
|
||||
let address = mbt_ffi_malloc((wins).length() * 32);
|
||||
for index = 0; index < (wins).length(); index = index + 1 {
|
||||
let iter_elem : WindowEntry = (wins)[(index)]
|
||||
let iter_base = address + (index * 32);
|
||||
mbt_ffi_store64((iter_base) + 0, ((iter_elem).id).reinterpret_as_int64())
|
||||
|
||||
let ptr = mbt_ffi_str2ptr((iter_elem).title)
|
||||
mbt_ffi_store32((iter_base) + 12, (iter_elem).title.length())
|
||||
mbt_ffi_store32((iter_base) + 8, ptr)
|
||||
|
||||
let ptr0 = mbt_ffi_str2ptr((iter_elem).app_id)
|
||||
mbt_ffi_store32((iter_base) + 20, (iter_elem).app_id.length())
|
||||
mbt_ffi_store32((iter_base) + 16, ptr0)
|
||||
mbt_ffi_store8((iter_base) + 24, (if (iter_elem).focused { 1 } else { 0 }))
|
||||
cleanup_list.push(ptr)
|
||||
cleanup_list.push(ptr0)
|
||||
|
||||
}
|
||||
wasmImportPublishWindows(address, (wins).length());
|
||||
mbt_ffi_free(address)
|
||||
|
||||
cleanup_list.each(mbt_ffi_free)
|
||||
|
||||
}
|
||||
///|
|
||||
/// The next pending request, oldest first.
|
||||
pub fn next_request() -> Request? {
|
||||
|
||||
let return_area = mbt_ffi_malloc(16)
|
||||
wasmImportNextRequest(return_area);
|
||||
|
||||
let lifted2 : Request? = match mbt_ffi_load8_u((return_area) + 0) {
|
||||
0 => Option::None
|
||||
1 => {
|
||||
|
||||
let lifted = match (mbt_ffi_load8_u((return_area) + 4)) {
|
||||
0 => {
|
||||
|
||||
let result = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 8), mbt_ffi_load32((return_area) + 12))
|
||||
|
||||
Request::Launch(result)
|
||||
}
|
||||
1 => {
|
||||
|
||||
Request::FocusWindow(mbt_ffi_load32((return_area) + 8))
|
||||
}
|
||||
2 => {
|
||||
|
||||
Request::SetLayout(mbt_ffi_load32((return_area) + 8))
|
||||
}
|
||||
3 => {
|
||||
|
||||
Request::SetInspector((mbt_ffi_load8_u((return_area) + 8) != 0))
|
||||
}
|
||||
4 => {
|
||||
|
||||
let result0 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 8), mbt_ffi_load32((return_area) + 12))
|
||||
|
||||
Request::LoadModule(result0)
|
||||
}
|
||||
5 => {
|
||||
|
||||
let result1 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 8), mbt_ffi_load32((return_area) + 12))
|
||||
|
||||
Request::UnloadInstance(result1)
|
||||
}
|
||||
6 => {
|
||||
|
||||
Request::Browse
|
||||
}
|
||||
_ => panic()
|
||||
}
|
||||
|
||||
Option::Some(lifted)
|
||||
}
|
||||
_ => panic()
|
||||
}
|
||||
let ret = lifted2
|
||||
mbt_ffi_free(return_area)
|
||||
return ret
|
||||
|
||||
}
|
||||
///|
|
||||
/// A window a module asked to focus through `windows.focus` (64-bit id), since the last call.
|
||||
pub fn take_focus_request() -> UInt64? {
|
||||
|
||||
let return_area = mbt_ffi_malloc(16)
|
||||
wasmImportTakeFocusRequest(return_area);
|
||||
|
||||
let lifted : UInt64? = match mbt_ffi_load8_u((return_area) + 0) {
|
||||
0 => Option::None
|
||||
1 => {
|
||||
|
||||
Option::Some((mbt_ffi_load64((return_area) + 8)).reinterpret_as_uint64())
|
||||
}
|
||||
_ => panic()
|
||||
}
|
||||
let ret = lifted
|
||||
mbt_ffi_free(return_area)
|
||||
return ret
|
||||
|
||||
}
|
||||
///|
|
||||
/// Names of the `*.wasm` files directly in `dir`, sorted.
|
||||
pub fn list_wasm_files(dir : String) -> Array[String] {
|
||||
|
||||
let ptr = mbt_ffi_str2ptr(dir)
|
||||
let return_area = mbt_ffi_malloc(8)
|
||||
wasmImportListWasmFiles(ptr, dir.length(), return_area);
|
||||
|
||||
let array : Array[String] = [];
|
||||
for index = 0; index < (mbt_ffi_load32((return_area) + 4)); index = index + 1 {
|
||||
let iter_base = (mbt_ffi_load32((return_area) + 0)) + (index * 8)
|
||||
|
||||
let result = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4))
|
||||
|
||||
array.push(result)
|
||||
}
|
||||
mbt_ffi_free(mbt_ffi_load32((return_area) + 0))
|
||||
let ret = array
|
||||
mbt_ffi_free(ptr)
|
||||
mbt_ffi_free(return_area)
|
||||
return ret
|
||||
|
||||
}
|
||||
///|
|
||||
pub fn picker_start() -> Bool {
|
||||
|
||||
let result : Int = wasmImportPickerStart();
|
||||
let ret = (result != 0)
|
||||
return ret
|
||||
|
||||
}
|
||||
///|
|
||||
pub fn picker_poll() -> PickerState {
|
||||
|
||||
let return_area = mbt_ffi_malloc(12)
|
||||
wasmImportPickerPoll(return_area);
|
||||
|
||||
let lifted = match (mbt_ffi_load8_u((return_area) + 0)) {
|
||||
0 => {
|
||||
|
||||
PickerState::Open
|
||||
}
|
||||
1 => {
|
||||
|
||||
PickerState::Cancelled
|
||||
}
|
||||
2 => {
|
||||
|
||||
let result = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 4), mbt_ffi_load32((return_area) + 8))
|
||||
|
||||
PickerState::Chosen(result)
|
||||
}
|
||||
_ => panic()
|
||||
}
|
||||
let ret = lifted
|
||||
mbt_ffi_free(return_area)
|
||||
return ret
|
||||
|
||||
}
|
||||
|
||||
@@ -73,8 +73,12 @@ fn wasmImportHasExe(p0 : Int, p1 : Int) -> Int = "moonplasma:host/sys@0.1.0" "ha
|
||||
fn wasmImportSpawn(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int = "moonplasma:host/sys@0.1.0" "spawn"
|
||||
|
||||
///|
|
||||
#owned(bytes)
|
||||
extern "wasm" fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int =
|
||||
extern "wasm" fn mbt_ffi_free(position : Int) =
|
||||
#|(func (param i32) local.get 0 call $moonbit.decref)
|
||||
|
||||
///|
|
||||
#owned(str)
|
||||
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0)
|
||||
|
||||
///|
|
||||
@@ -85,10 +89,21 @@ extern "wasm" fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String =
|
||||
#| local.get 0)
|
||||
|
||||
///|
|
||||
#owned(str)
|
||||
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
|
||||
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
|
||||
#|(func (param i32) (result i32) (local i32)
|
||||
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
|
||||
#| local.tee 1 i32.const 0 call $moonbit.init_array8
|
||||
#| local.get 1)
|
||||
|
||||
///|
|
||||
#owned(bytes)
|
||||
extern "wasm" fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0 i32.load)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] =
|
||||
#|(func (param i32) (param i32) (result i32)
|
||||
@@ -96,18 +111,3 @@ extern "wasm" fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] =
|
||||
#| local.get 1 call $moonbit.init_array8
|
||||
#| local.get 0)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0 i32.load)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
|
||||
#|(func (param i32) (result i32) (local i32)
|
||||
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
|
||||
#| local.tee 1 i32.const 0 call $moonbit.init_array8
|
||||
#| local.get 1)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_free(position : Int) =
|
||||
#|(func (param i32) local.get 0 call $moonbit.decref)
|
||||
|
||||
@@ -121,12 +121,7 @@ fn wasmImportSpawn(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String {
|
||||
fn mbt_ffi_free(position : Int) -> Unit {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
@@ -136,12 +131,7 @@ fn mbt_ffi_str2ptr(str : String) -> Int {
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_load32(offset : Int) -> Int {
|
||||
fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
@@ -151,6 +141,16 @@ fn mbt_ffi_malloc(size : Int) -> Int {
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_free(position : Int) -> Unit {
|
||||
fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_load32(offset : Int) -> Int {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] {
|
||||
abort("wasm-only")
|
||||
}
|
||||
Reference in new issue
Block a user