Skip to content

Tiny v0.3.1 - WebAssembly, Global Hotkeys, Base64, MessagePack Plugins, and VM Optimizations

Latest

Choose a tag to compare

@confh confh released this 09 Jul 16:02

This release adds support for WebAssembly module execution, global keyboard hotkeys, Base64 encoding/decoding, MessagePack serialization for native plugins, TCP client connections, and key VM/JIT performance optimizations.

Standard Library Changes

  • WebAssembly Module (wasm): Added the wasm standard library module for running WebAssembly binaries inside Tiny via the wazero runtime. Instantiated modules support function calling and memory reads/writes.
    import std "wasm"
    import std "fs"
    import std "io"
    
    const wasmBytes = fs.readBytes("app.wasm")
    const module = wasm.instantiate(wasmBytes, {
        env: {
            host_func: fn(x: number): number {
                return x * 2.0
            }
        }
    })
    
    const result = module.call("add", [10.5, 20.25])
    io.println(result)
  • Global Hotkeys: Added global desktop hotkey registration in the desktop module. Register shortcuts with modifier keys and callbacks.
    import std "desktop"
    import std "io"
    
    const hotkeyId = desktop.registerHotKey([desktop.Modifiers.Ctrl, desktop.Modifiers.Alt], "s", fn() {
        io.println("Ctrl+Alt+S pressed!")
    })
    
    desktop.unregisterHotKey(hotkeyId)
  • Base64 Support in buffer: Added buffer.fromBase64 to decode base64 strings and buffer.toBase64 on buffer instances to encode them.
    import std "buffer"
    import std "io"
    
    const buf = buffer.fromBase64("SGVsbG8gVGlueQ==")
    io.println(buf.stringify()) // "Hello Tiny"
    
    const encoded = buf.toBase64() // "SGVsbG8gVGlueQ=="
  • TCP Client: Added net.tcpClient to connect to remote TCP hosts.
    import std "net"
    
    const conn = net.tcpClient("127.0.0.1", 8080)
    conn.writeString("Hello server\n")

Runtime / VM Changes

  • Instruction Memory Optimization: Separated DebugInfo from Instruction structs in the VM. Instructions no longer store file, line, and column info directly, reducing bytecode execution memory footprint.
  • Method Call Cache: Added MethodCallCache to cache standard module method resolution, bypassing slow-path lookups on repeated calls.
  • Fast Return Path: Skip defer checking, return type overrides, and frame release overhead for functions that contain no defers or return type hints.
  • Stack Popping Speedup: The stack execution loop (popFast) no longer writes nil to popped slots, reducing CPU overhead during stack manipulation.
  • JIT Compiler Improvements: Support for compiling functions returning any. Added linear memory heap safety limits (jitMaxLinearHeapTop) and improved safeness checking for direct calls and string joins.

Plugin Changes

  • MessagePack Plugin Protocol: Native plugins can now export TinyPluginCallMsgPack and TinyPluginFreeMsgPack to utilize binary MessagePack serialization instead of legacy JSON strings, improving VM-to-plugin interop performance.
    //export TinyPluginCallMsgPack
    func TinyPluginCallMsgPack(dataPtr *C.char, size C.int) *C.char {
        data := C.GoBytes(unsafe.Pointer(dataPtr), size)
        resBytes := tinyplugin.HandleCallMsgPack(data)
        return (*C.char)(unsafe.Pointer(&resBytes[0]))
    }

LSP Changes

  • Structural Type Matching: The Language Server now compares classes and interfaces structurally when validating type compatibility across different modules or files.
  • Lambda Return Inference: Resolves return type inference in lambdas containing multiple return statements.

Installation and Downloads

To install Tiny, download the compiler binary for your specific operating system:

  • Windows: Download tiny_windows_amd64.exe
  • Linux: Download tiny_linux_amd64 for amd64 or tiny_linux_arm64 for arm64
  • macOS (Apple Silicon): Download tiny_darwin_arm64

Note: The tiny_runtime_* assets listed in the releases page are managed automatically by the compiler during the pack and dist commands. You do not need to download them manually.