8000 [WIP] WASIp2 based WasmSystem implementation + updated some WasmComponentModel APIs by tanishiking · Pull Request #48 · scala-wasm/scala-wasm · GitHub
[go: up one dir, main page]

Skip to content

[WIP] WASIp2 based WasmSystem implementation + updated some WasmComponentModel APIs #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from

Conversation

tanishiking
Copy link
@tanishiking tanishiking commented May 21, 2025

@ComponentImport/Export(function-name, module-name)

object WallClock {
  // (import "wasi:clocks/wall-clock@0.2.0" "now" ...)
  @ComponentImport("now", "wasi:clocks/wall-clock@0.2.0")
  def now(): Datetime = cm.native
}

object Foo {
  // (export "component:testing/tests#roundtrip-string" ...)
  @ComponentExport("roundtrip-string", "component:testing/tests")
  def roundtripString(a: String): String = a
}

@ComponentResourceImport

@ComponentResourceImport("output-stream", "wasi:io/streams@0.2.0")
trait OutputStream {
  // (import "wasi:io/streams@0.2.0", "[method]output-stream.blocking-write-and-flush" ...)
  @ComponentResourceMethod("blocking-write-and-flush")
  def blockingWriteAndFlush(contents: Array[UByte]): cm.Result[Unit, StreamError] = cm.native

  // (import "wasi:io/streams@0.2.0", "[resource-drop]output-stream" ...)
  @ComponentResourceDrop
  def close(): Unit = cm.native
}

object OutputStream {
  // (import "wasi:io/streams@0.2.0", "[static]output-stream".static-function" ...)  
  @ComponentResourceStaticMethod("static-function")
  def staticFunction(): ...
   
  // (import "wasi:io/streams@0.2.0", "[constructor]output-stream" ... )
  @ComponentResourceConstructor
  def apply(): OutputStream = cm.native
}

def print(s: String): Unit = {
  cli.Stdout.getStdout().blockingWriteAndFlush(s.getBytes())
}
// ok

def print(s: String): Unit = {
  val stdout = cli.Stdout.getStdout()
  stdout.blockingWriteAndFlush(s.getBytes())
}
// checkClassDef fail
// file:/xxx/javalib/src/main/scala/java/lang/WasmSystem.scala(13:5:VarRef): Cannot find variable stdout in scope
// The IR somehow translated to
// Block(
//  ComponentFunctionApply(..., getStdO
8000
ut, ...) <- should be VarDef(stdout, ..., ComponentFunctionApply(...))
//  ComponentFunctionApply(..., blockingWriteAndFlush

sjrd and others added 5 commits April 30, 2025 17:44
Like in an explicit `toString()` call dispatch, we must handle
hijacked values in string concatenation with something that is an
ancestor of hijacked classes.
Namely: `print`, `nanoTime`, `currentTimeMillis` and `random`.

TODO: This won't work in the component model, as it requires four
dedicated imports. Needs fixing before it can be merged.
@tanishiking tanishiking deleted the refactor-wasm-component-model-api branch May 23, 2025 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0