package runtime
This package contains all the classes and types related to running WebAssembly modules.
The entry point for almost all users will be Engine. A typical use of the engine is:
import swam._ import text._ import runtime._ import exports._ import cats.implicits._ import cats.effect._ import java.nio.file.Paths val tcompiler = Compiler[IO] val engine = Engine[IO] for { tcompiler <- tcompiler engine <- engine mod <- engine.compile(/* source of the module */) inst <- mod.newInstance() f <- inst.exports.function1[Int, Int]("f") res <- f(43) } yield res println(res.unsafeRunSync())
- Source
- package.scala
- Alphabetic
- By Inheritance
- runtime
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Package Members
Type Members
- type CanFail[+T] = Either[String, T]
- final class CompileException extends SwamException
Raised when module compilation is not possible.
- case class CompiledData[F[_]](offset: Array[AsmInst[F]], init: ByteBuffer) extends Product with Serializable
- case class CompiledElem[F[_]](offset: Array[AsmInst[F]], init: Vector[Int]) extends Product with Serializable
- final class ConversionException extends RuntimeException
Raised when trying to type interface elements with invalid types.
- case class Custom(name: String, payload: BitVector) extends Product with Serializable
- class Engine[F[_]] extends ModuleLoader[F]
This is the engine used to compile, instantiate and run modules.
This is the engine used to compile, instantiate and run modules. It exposes all the needed interface to interact with modules.
You typically want to reuse the same instance for all your executions over the same effectful type
F
. - sealed trait Export extends AnyRef
- abstract class Function[F[_]] extends Interface[F, FuncType]
Functions must implement this interface to be used by Swam.
- abstract class Global[F[_]] extends Interface[F, GlobalType]
Globals must implement this interface to be used by Swam.
- sealed trait Import extends AnyRef
- class Instance[F[_]] extends AnyRef
A module instance that has already been initialized.
- sealed trait Interface[F[_], +T <: Type] extends AnyRef
All elements that are part of the interface of an instance must implement this interface.
All elements that are part of the interface of an instance must implement this interface.
Each specialization defines a specific WebAssembly type that can be imported or exported.
- final class LinkException extends SwamException
Raised when a problem occurs at module instantiation or when required exports are missing.
- abstract class Memory[F[_]] extends Interface[F, MemType]
Memories must implement this interface to be used by Swam.
Memories must implement this interface to be used by Swam.
This interface is unsafe, meaning that no exception is expected when calling any method on it. The Swam engine ensures that this does not occur by running only validated WebAssembly code, where size constraints are checked before execution. Implementations must respect the contract of each method.
This interface is not thread-safe, concurrent access to the same instance may lead to undefined behaviors.
- class Module[F[_]] extends AnyRef
The runtime representation of a validated and compiled module.
- sealed class RuntimeException extends SwamException
Raised when something goes wrong during module execution.
- trait StackFrame extends AnyRef
Interface of a stack frame, making it possible to create a call stack on trap for reporting purpose.
- final class StackOverflowException extends RuntimeException
Raised when call stack overflows.
- trait Table[F[_]] extends Interface[F, TableType]
Tables must implement this interface to be used by Swam.
Tables must implement this interface to be used by Swam. This interface is unsafe, meaning that no exception is expected when calling any method on it.
This interface is not thread-safe, concurrent modifications may lead to undefined behaviors.
- final class TrapException extends RuntimeException
Raised when a trap is raised in a module.
- sealed abstract class Value extends AnyRef