-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
32 additions
and
1 deletion.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
31 changes: 31 additions & 0 deletions
31
canard/src/wasmWasiMain/kotlin/org/kodein/log/timestamp.wasmWasi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.kodein.log | ||
|
||
import kotlin.wasm.WasmImport | ||
import kotlin.wasm.unsafe.Pointer | ||
import kotlin.wasm.unsafe.UnsafeWasmMemoryApi | ||
import kotlin.wasm.unsafe.withScopedMemoryAllocator | ||
|
||
|
||
@WasmImport("wasi_snapshot_preview1", "clock_time_get") | ||
private external fun wasiRawClockTimeGet(clockId: Int, precision: Long, resultPtr: Int): Int | ||
|
||
@OptIn(UnsafeWasmMemoryApi::class) | ||
private fun wasiGetTime(clockId: Int): Long = withScopedMemoryAllocator { allocator -> | ||
val rp0 = allocator.allocate(8) | ||
val ret = wasiRawClockTimeGet( | ||
clockId = clockId, | ||
precision = 1, | ||
resultPtr = rp0.address.toInt() | ||
) | ||
check(ret == 0) { | ||
"Invalid WASI return code $ret" | ||
} | ||
(Pointer(rp0.address.toInt().toUInt())).loadLong() | ||
} | ||
|
||
public actual fun now(): Timestamp = Timestamp(wasiGetTime(0).toULong()) | ||
|
||
@Suppress("LocalVariableName") | ||
public actual fun Timestamp.toLocalString(): String = | ||
TODO("$msecSinceEpoch") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters