Packages

  • package root
    Definition Classes
    root
  • package swam
    Definition Classes
    root
  • package runtime

    This package contains all the classes and types related to running WebAssembly modules.

    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())
    Definition Classes
    swam
  • package internals
    Definition Classes
    runtime
  • package compiler
    Definition Classes
    internals
  • Compiler
  • Context
  • Func
  • FunctionContext
  • Glob
  • LabelStack
  • Mem
  • Tab
  • package interpreter
    Definition Classes
    internals

package compiler

Source
package.scala
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. compiler
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Type Members

  1. class Compiler[F[_]] extends AnyRef

    Compiles a valid module to the low level assembly language.

    Compiles a valid module to the low level assembly language. This is a one-pass assembler which generates typed breaks.

    This compiler executes the static part of the specification semantics, i.e. the one dealing with labels and breaks. The static restrictions on the WebAssembly bytecodes make it possible to statically compute the local stack size at any point in a function body. Of course, it assumes that the module is valid otherwise it will break or generate undefined assembly code.

  2. case class Context[F[_]](types: Vector[FuncType] = Vector.empty, funcs: Vector[Int] = Vector.empty, code: Vector[Func[F]] = Vector.empty, tables: Vector[Tab] = Vector.empty, mems: Vector[Mem] = Vector.empty, globals: Vector[Glob[F]] = Vector.empty, elems: Vector[CompiledElem[F]] = Vector.empty, data: Vector[CompiledData[F]] = Vector.empty, start: Option[Int] = None, exports: Vector[Export] = Vector.empty, imports: Vector[Import] = Vector.empty, customs: Vector[Custom] = Vector.empty) extends Product with Serializable
  3. sealed trait Func[+F[_]] extends AnyRef
  4. case class FunctionContext(labels: LabelStack, errata: List[(Target, (Int) => Unit)], offsets: Map[Target, Int], offset: Int, nxt: Int) extends Product with Serializable

    Compilation context used when compiling instructions for a function.

    Compilation context used when compiling instructions for a function. The label stack represents the static trace of the program so far in terms of stack modifications, the errata registers the label to fix later, and the jump label offsets. This allows to compile code in one pass even with forward jumps.

    The errata lists how to set correct offset for target labels.

    The offsets maps label names to their offset.

    Once all code has been generated, the placeholders pointed by the errata map are replaced with real offsets from the offsets map.

  5. sealed trait Glob[+F[_]] extends AnyRef
  6. case class LabelStack(parent: LabelStack, target: Target, arity: Int, pushed: Int) extends Product with Serializable

    A stack of labels, each one tracking following information:

    A stack of labels, each one tracking following information:

    • the parent label
    • its target on break
    • its arity (i.e. the number of return value to pop and return on break)
    • the number of pushed value so far for the current label At top-level, the parent is null and target is 0. No checks need to be performed because the compiler is only called if the program is correct, in which case all breaks target an existing label. The top-level label is a special synthesized one, representing the top-level block of the function body.
  7. sealed trait Mem extends AnyRef
  8. sealed trait Tab extends AnyRef
  9. type Target = Int

    A target label for a break

Value Members

  1. object Func
  2. object FunctionContext extends Serializable
  3. object Glob
  4. object Mem
  5. object Tab

Inherited from AnyRef

Inherited from Any

Ungrouped