Hemashushu’s Homepage

Curiosity, exploration and creation

XiaoXuan Core

The XiaoXuan Core Programming Language is used to build powerful user-space system programs with extremely fast startup speed and small footprint, it can directly call syscall and interoperate with C shared libraries. Single-file, statically linked runtime make applications highly portable.

Quick start

The following code demostrates how to call syscalls and external functions (from shared libraries). The code prints the current working directory.

  1. Create a file named pwd.anc in any directory with the following content:
config(runtime, "1.0")

external shared "libc.so.6" {
    function puts(addr:long)
}

function main() {
    const buf_length = 1024
    let buf = std::Array::<byte>::fill(0, buf_length)

    // invoke syscall
    syscall(
        syscall::number::getcwd,
        buf.raw_addr,
        buf.length)

    // call external function
    puts(buf.raw_addr)
}
  1. Download the XiaoXuan Core launcher ancl-1.0.1.x86_64-linux-gnu.tar.gz from the offical website and extract it to the ~/.local/bin or /usr/bin directory.

  2. Run the following command:

$ ancl pwd.anc

The launcher will first check the version of the runtime required by the application and then start the corresponding runtime to execute it.

Since this is the first time we are running an XiaoXuan Core application, the launcher will download the runtime from the internet. Then the runtime will compile and cache the application on-the-fly. Finally, you should see the application output a line of text, which is the current working directory.

The XiaoXuan Core standard library provides simpler ways to get the current working directory or print strings. The code below is written for demostration purposes only. Additionally, the following steps assume a Linux operation system. If you are using other platform or want to try a simpler “Hello, World!” program, please refer to the XiaoXuan Code Documentation.

The XiaoXuan Core VM

The XiaoXuan Core VM

The XiaoXuan Core VM

XiaoXuan Runtime is a self-contained, statically linked executable that combines a compiler and a virtual machine (VM) designed specifically for running system programs. It offers serveral key advantages:

  • Fast loading: The structure of the application’s image file and the instruction set architecture (ISA) are specially designed to eliminate the need for parsing and preprocessing by the VM. Instead, the file is simply mapped to memory and the bytecode can be executed directly.
  • Program security: The XiaoXuan Core VM uses indexes instead of pointers to locate functions, data, and local variables. The stack is also divided into three separate stack: frame information, local variables, and operands. This effectively prevents memory boundary and overflow issues, reducing program vulnerabilities.
  • Seamless interoperability with C/C++/Rust shared libraries: The VM’s memory model closely resembles that of the local native machine, allowing VM functions to directly call shared libraries built in C/C++/Rust. Additionally, VM functions can be also passed to shared libraries as callback functions (enabling shared libraries to call back into the VM). This feature allows XiaoXuan Core to take full advantage of the rich ecosystem of existing shared libraries.
  • Data-race-free parallelism model: The XiaoXuan Core VM has no “global data”, and threads are only allowed to communicate by passing copies of data through channels. This prevent data races and ensures thread safety.
  • Embeddable in Rust applications: XiaoXuan Core programs and the VM can be embedded as a library in Rust applications. Rust can then call VM functions just like regular functions (using a JIT generated “bridge function”).

Motivation

Availability and portability

Traditional system programs, as well as command-line utilities, can be difficult for ordinary users to set up and run if they are not maintained by a distribution and have not been updated for a while, this is because:

For applications built with compiled languages, may encounter excessive dependencies that require manual compilation during the build process, or compilation may fail due to changes in shared library version.

For applications built with script languages, may encounter version incompatibility issues, or may encounter dependency version conflict issues.

XiaoXuan Core has learned from these lessons and is designed to ensure that once an application is created and can run, it will continue to run correctly even if it is not maintained and after a long period of time.

Ease of development, maintaince, and high performance

The XiaoXuan Core language strikes a good balance between “ease of development” and “high performance”. The XiaoXuan Core language has the following features:

  • Data-race-free concurrency model
  • GC-free automatic memory management
  • Discards difficult-to-master concepts such as pointers, ownership, borrow checking and lifetimes.

These features make it easy for developers to develop safe, stable and high-performance applications.

How XiaoXuan Core solves verison compatibility issues?

XiaoXiao Core applications can maintain correct operation even when the runtime environment changes (e.g., major version changes to the shared libraries in the system). This is achieved through the following two measures:

The XiaoXuan Core Applications Version Control

The XiaoXuan Core Applications Version Control

  1. Runtime version specification

Each XiaoXuan Core application is required to specify a runtime version number. For single-file applications, this is specified using the config(runtime, "1.0") statement. For multi-file applications, it is specified in the package descriptor file package.anon, for example:

{
    name: "myapp"
    runtime: "1.1"
}

The XiaoXuan Core Application Launcher (ancl) will start the corresponding runtime based on the version number specified by the application to compile or run.

  1. Bundled shared modules and shared libraries

Each verson of the runtime comes with its own shared modules (e.g., std and math) and, most importantly, a set of dynamic shared libraries (e.g., libc, libsqlite3, libz etc.). This allows applications to not rely on the shared libraries of the OS.

Therefore, whether the XiaoXuan Core runtime is updated or the system shared library versions change, the application can run in the same environment as it was developed in.

This feature improves application compatibility and stability, reduces dependency on the system environment, simplifies application deployment and maintenance.

Get started

  • Get started with XiaoXuan Core in 5 minutes

Manuals & Tutorials

  • M01 - The XiaoXuan Programming Language Reference

    Syntax, fundamental, and the standard library
    2023-04-16
    • Data types and Literals
    • Variables
    • Functions
    • Collection
    • Control Flow
    • Error Handling
    • Method, Generic and Interface
    • Pattern
    • Chain
    • Modules, Packages and Properties
    • Annotations and IoC
    • Macro
  • M02 - An introduction to the XiaoXuan Core Assembly

    The syntax, structure, and the VM instructions
    2023-09-10
    • Literals
    • Module Nodes
    • Instructions
    • Control Flow
    • Function Call
    • System Call
    • Environment Call
    • Packages and Modules
  • M03 - An introduction to the XiaoXuan Core Intermediate Representation (IR)

    The syntax, structure and modules
    2023-10-12
    • Data Types and Literals
    • Functions
    • Control Flow
    • Struct and Array
    • Packages and Modules
  • S71 - Designing a Runtime Virtual Machine (VM) for Systems Programming

    The memory, stack and the concurrency model of XiaoXuan Core VM
    2023-06-13
    • Data types and thoughts on floating-pointer numbers
    • The triadic stack
    • Using indexes instead of pointer
    • The instruction set
    • Using structured blocks instead of jumps for control flow
    • Tail call optimization
    • Environment calls
    • System calls
    • Bridge functions and external calls
    • A Data-race-free parallel Model
  • S80 - Zero to OS: Building Your Own Usable Operating System, Volumn 1: The User Space

    Build the user-space part of an OS for RISC-V platform from scratch in XiaoXuan Core
    2024-01-09
    • Set up a RISC-V virtual machine using QEMU
    • Write a minimal `init` program
    • Write a minimal `shell` program
    • Fundamentals of file system and processes, implementing the `pwd` and `ls` commands
    • Implement the `mount` and `umount` commands
    • Principals of `redirect`, implementing the `echo` and `cat` commands
    • Principal of `pipe`, implementing the `tee` and `tr` commands
    • Session and process groups
    • The `root` privileges, users and groups, and the `setuid` bit
    • Add support for shell scripts
  • S82 - Building a Docker-like Container Utility from Scratch using XiaoXuan Core

    Linux namespaces, capabilities, seccomp and virtual networking
    2024-01-15
    • The principal of Linux container
    • Isolating the file system
    • Isolating the process space
    • Isolating the accounts
    • The virtual networking devices and route
  • An introduction to the XiaoXuan Core application image file format
  • XiaoXuan Object Notation (ANON): a Human-readable object notation format
  • XiaoXuan Allocator: a low-latency, scalable memory allocator

The source code repositories of related projects:

  • XiaoXuan Core VM
  • XiaoXuan Core Assembly
  • XiaoXuan Core IR
  • XiaoXuan Core Compiler
  • XiaoXuan Core Runtime
  • XiaoXuan Core Launcher
  • XiaoXuan Core Standard Library
  • XiaoXuan Allocator
  • XiaoXuan Object Notation (ANON)