Sign inSign up

100hellos/wat

By 100hellos

•Updated 5 months ago

"Hello World!" Written in wat

Image
0

4.1K

100hellos/wat repository overview

⁠Hello World! From wat.

Language page⁠ — context, influences, and learning notes on the 100hellos site.

Source on GitHub⁠ (100hellos/wat)

⁠Trying it

docker run --rm --platform="linux/amd64" 100hellos/wat:latest

⁠Modifying it

Read the repo README⁠, or fork the project⁠ and customize it.

For an interactive shell:

docker run --rm --platform="linux/amd64" --entrypoint="" -it 100hellos/wat:latest zsh

⁠WAT (WebAssembly Text Format)

WAT (WebAssembly Text Format) is the human-readable text representation of WebAssembly bytecode. While WebAssembly is typically generated by compiling high-level languages like C, C++, or Rust, WAT allows developers to write WebAssembly modules directly in a text-based S-expression format.

⁠Language Features

WAT provides direct access to WebAssembly's low-level capabilities:

  • Stack-based virtual machine: Operations work on an implicit stack
  • Linear memory model: Manages memory as a contiguous array of bytes
  • Type safety: Strict typing prevents many runtime errors
  • Sandboxed execution: WebAssembly runs in a secure, isolated environment
  • WASI support: WebAssembly System Interface enables interaction with the host system

⁠Hello World Explanation

The WAT implementation uses WASI (WebAssembly System Interface) to interact with the host system:

(module
  ;; Import WASI functions for system interaction
  (import "wasi_snapshot_preview1" "fd_write" ...)

  ;; Define linear memory for string storage
  (memory 1)

  ;; Store "Hello World!" string at memory address 0
  (data (i32.const 0) "Hello World!")

  ;; Main function sets up I/O vector and calls fd_write
  (func $main (export "_start") ...)
)

⁠Interesting Facts

  • S-expression syntax: WAT uses Lisp-like parenthesized expressions
  • Compilation target: WAT compiles to binary WebAssembly (.wasm) format
  • Cross-platform: Runs on any system with a WebAssembly runtime
  • Performance: Near-native execution speed in modern browsers and runtimes
  • Security: Capability-based security model with explicit imports

⁠Runtime

This implementation uses Wasmtime⁠, a standalone WebAssembly runtime that supports WASI for system interactions.

⁠Further Exploration

  • Try modifying the string or adding more WASI functions
  • Explore WebAssembly's instruction set architecture
  • Learn about WebAssembly's role in modern web development
  • Investigate other WebAssembly runtimes like Wasmer or Node.js

Tag summary

Content type

Image

Digest

sha256:5618e37e7…

Size

43.2 MB

Last updated

5 months ago

docker pull 100hellos/wat