Skip to content

Commit

Permalink
chore(WASI): wip
Browse files Browse the repository at this point in the history
  • Loading branch information
romainbsl committed Jan 12, 2024
1 parent e2ddcea commit 737d676
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 1 deletion.
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")

2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
maven(url = "https://raw.githubusercontent.com/kosi-libs/kodein-internal-gradle-plugin/mvn-repo")
}
dependencies {
classpath("org.kodein.internal.gradle:kodein-internal-gradle-settings:8.5.1")
classpath("org.kodein.internal.gradle:kodein-internal-gradle-settings:8.5.2")
}
}

Expand Down

0 comments on commit 737d676

Please sign in to comment.