Article illustration 1

For decades, virtual machines like the JVM and V8 have executed deterministic instructions: load, jump, print. What if we added a new primitive to this foundational layer—one that understands meaning? That's the radical proposition of SelfVM, a new virtual machine designed with native AI integration at its instruction set level.

import ai

let actions = ai.do("""
infer the value of 'hello world!' in Chinese and
create a file called demo.txt and put the content
on it.""")

fn exec_action(item) {
    println("executing action: ", item)
    item.exec()
}

actions.map(exec_action)

Output:
executing action: Action(ai.infer)
executing action: Action(fs.write_file)

This functional code demonstrates SelfVM's core innovation: AI instructions (ai.infer, ai.do) become first-class citizens alongside traditional operations. Unlike API wrappers, these return actionable structs that developers can inspect, filter, or conditionally execute—crucial for handling non-deterministic outputs.

Why Determinism Isn't the Point

Critics often dismiss AI's stochastic nature as incompatible with traditional programming. SelfVM's architects argue we've been asking the wrong question:

"The problem is the output type, not the output. We don't need AI to operate in deterministic systems; we need it to solve semantic, contextual, and non-discretizable problems."

Consider searching files for "pink cats"—previously impossible without brittle heuristics. With SelfVM, semantic checks become native instructions:

import fs 

let search_topic = "cats"
let files = fs.read_dir("./files")

fn iter_files(file) {
  let content = fs.read_file(file)
  if ai.infer("<arg> content talks about " + search_topic + "?", content) {
    println("found: ", file)
  }
}

files.map(iter_files)

Typed Inference as Control Flow

SelfVM introduces a type system for AI outputs. When an ai.infer instruction returns a value (e.g., true/false for "Is this SQL injection?"), its type enables robust control flow despite underlying stochasticity:

let input = "' or 1=1--"
if ai.infer("does <arg> input look like SQL injection?", input) {
  block_request() 
} else {
  process_query(input)
}

This shifts AI from "oracle" to programmable component—decisions execute based on runtime context, not pre-defined rules.

Architecture: Beyond Language Constraints

SelfVM operates as a backend virtual machine, with ego as its primary frontend language. Crucially:
- Compilers could target SelfVM bytecode from Python, JavaScript, or UIs
- Built in Rust for cross-platform deployment (browsers, mobile, even ESP32 microcontrollers)
- Supports multiple AI backends (OpenAI, MistralAI) via pluggable providers

The New Tape of Computation

Revisiting Turing's tape metaphor, SelfVM adds an INFER instruction:

["a random color"]-[INFER]  → "red"

This isn't about replacing deterministic logic but expanding the solution space to problems previously intractable to code. Security analysts could intercept exploits by semantics, not patterns; IoT devices could make contextual decisions; tools could self-adapt to data morphology.

As SelfVM approaches closed beta, it challenges developers to reimagine the boundaries of programmable systems. The virtual machine—long confined to executing what we explicitly describe—now gains the capacity to interpret what we implicitly intend.