ilusm.dev

Host Contract

The __sys_* interface between ilusm programs and the host environment.

Overview

ilusm programs are isolated from the host OS. All I/O, process, network, and crypto operations go through the host contract - a set of named syscalls prefixed with __sys_. The runtime dispatches these calls to the platform implementation.

A conforming host implements all required syscalls. Optional syscalls may be absent; the stdlib module that uses them should check availability and fail gracefully.

Core I/O

SyscallArgsReturnsDescription
__sys_readpath: strstr | nilRead file contents
__sys_writepath: str, data: strtru | nilWrite file
__sys_appendpath: str, data: strtru | nilAppend to file
__sys_existspath: strtru | flsFile/dir exists
__sys_lspath: strlist[str]List directory
__sys_rmpath: strtru | nilDelete file
__sys_mkdirpath: strtru | nilCreate directory
__sys_statpath: strobj | nilFile metadata

Output

SyscallArgsReturnsDescription
__sys_prnval: anynilPrint to stdout + newline
__sys_prnrval: anynilPrint to stdout (no newline)
__sys_prneval: anynilPrint to stderr + newline
__sys_stdin(none)strRead line from stdin

Process

SyscallArgsReturnsDescription
__sys_argv(none)list[str]Command-line arguments
__sys_envname: strstr | nilEnvironment variable
__sys_exitcode: num(no return)Exit process
__sys_spawncmd: str, args: listobjSpawn subprocess
__sys_execcmd: str, args: listobjExecute and wait
__sys_pid(none)numCurrent process ID

Time

SyscallArgsReturnsDescription
__sys_now(none)numUnix timestamp (ms)
__sys_sleepms: numnilSleep for ms milliseconds
__sys_datets: numobjParse timestamp to date obj

Networking

SyscallArgsReturnsDescription
__sys_http_geturl: str, headers: objobjHTTP GET
__sys_http_posturl: str, body: str, headers: objobjHTTP POST
__sys_tcp_connhost: str, port: numobjOpen TCP connection
__sys_tcp_sendconn: obj, data: strnumSend bytes
__sys_tcp_recvconn: obj, n: numstrReceive bytes
__sys_dnshost: strlist[str]DNS lookup

Cryptography

SyscallArgsReturnsDescription
__sys_sha256data: strstrSHA-256 hex digest
__sys_sha512data: strstrSHA-512 hex digest
__sys_hmackey: str, data: str, algo: strstrHMAC digest
__sys_randn: numstrn random bytes (hex)
__sys_aes_enckey: str, data: strstrAES-256-GCM encrypt
__sys_aes_deckey: str, ct: strstrAES-256-GCM decrypt

Conforming host rules

  1. All required syscalls must be implemented and return the documented types.
  2. On error, syscalls return nil (not an exception) unless the contract specifies otherwise.
  3. Syscalls must not block the event loop for more than 100ms without yielding.
  4. New syscalls must be added to lib/runtime/syscall_contract.ilu before use.