Hello Encantis

Hello Encantis

More Magical WebAssembly

Encantis is a new programming language aimed at being wasm native, but much easier to work with than something like wat syntax. It does this in 2 main ways:

  • Add a robust type system on top of the primitive types in Wasm native. This allows for vectors, null-terminated arrays, structs, etc.

  • Use more traditional syntax over s-expressions including infix syntax for most expressions.

Also while being wasm native, it will ship an optional bytecode interpreter for embedded applications where wasm is a little too heavy and you want some syscalls to be inline opcodes in the bytecode for maximum performance!

    ;; Import the required fd_write WASI function which will write the given io vectors to stdout
    ;; The function signature for fd_write is:
    ;; (File Descriptor, *iovs, iovs_len, nwritten) -> Returns number of bytes written
    ;; (import "wasi_unstable" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32)))
    (import "wasi_snapshot_preview1" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32)))

    (memory 1)
    (export "memory" (memory 0))

    (data (i32.const 0) "\08\00\00\00\0c\00\00\00hello world\n")

    (func $main (export "_start")

        (call $fd_write
            (i32.const 1) ;; file_descriptor - 1 for stdout
            (i32.const 0) ;; *iovs - The pointer to the iov array, which is stored at memory location 0
            (i32.const 1) ;; iovs_len - We're printing 1 string stored in an iov - so one.
            (i32.const 20) ;; nwritten - A place in memory to store the number of bytes written
        drop ;; Discard the number of bytes written from the top of the stack

Consider this wat module above. This is the most minimal way to implement hello world when using the wasi ABI. In Encantis it would look like the following:

import "wasi_snapshot_preview1" (
  "fd_write" func fd-write (fd:u32 iovec:[[u8]] outsize:*u32) -> result:i32

define stdout:i32 = 1
define iovec:[[u8]] = (message 1)

export "_start"
func ()
    fd-write(stdout iovec outsize)

export "memory"
memory 1

data 0 (
    message  -> "Hello World\n":[u8]
    out-size -> u32

There is more to come, but this is just a teaser and a test of this blogging platform.