⚠️ 本网站已停止维护,文档已迁移至 GitHub docs/ 目录 | ⚠️ This website is no longer maintained. Docs moved to GitHub docs/

128-bit 指令集架构128-bit Instruction Set

JVAV 使用固定 16 字节(128-bit)的指令格式。每条指令包含 8-bit 操作码、三个 8-bit 寄存器索引, 以及最多 96-bit 的立即数。支持算术(ADD/SUB/MUL/DIV/MOD)、位运算(AND/OR/XOR/SHL/SHR/NOT)、 比较跳转、内存读写与函数调用。

JVAV uses a fixed 16-byte (128-bit) instruction format. Each instruction contains an 8-bit opcode, three 8-bit register indices, and up to 96 bits of immediate value. Supports arithmetic (ADD/SUB/MUL/DIV/MOD), bitwise (AND/OR/XOR/SHL/SHR/NOT), compare & branch, memory access, and function calls.

FieldWidth说明Description
op8-bit操作码Opcode
dst8-bit目标寄存器Destination register
src18-bit源操作数1Source operand 1
src28-bit源操作数2Source operand 2
imm_low64-bit立即数低 64 位Lower immediate bits
imm_high32-bit立即数高 32 位Upper immediate bits

.syscall 系统调用抽象.syscall System Call Abstraction

后端汇编器支持 .syscall name, cmd_id, arg_count 伪指令, 自动生成标准函数包装器:保存寄存器、从栈帧读取参数、写入 VM 系统调用邮箱(0xFFE00xFFE4)、触发 syscall、恢复寄存器并返回。 前端 I/O 函数(putintputchar 等)不再内联特殊汇编,而是作为普通 CALL 调用。

The backend assembler supports the .syscall name, cmd_id, arg_count pseudo-instruction, automatically generating a standard function wrapper: save registers, read arguments from the stack frame, write to the VM syscall mailbox (0xFFE00xFFE4), trigger the syscall, restore registers, and return. Frontend I/O functions (putint, putchar, etc.) no longer use inline special assembly; they are ordinary CALL invocations.

    .syscall putint, 15, 1   ; name=putint, cmd=15, 1 arg
    .syscall exit, 18, 1     ; set process exit code
    .syscall putstr, 19, 2   ; print string (addr, len)
    .syscall sleep, 20, 1    ; sleep for ms milliseconds

自定义 syscall 声明Custom Syscall Declaration

JVL 前端支持 syscall name, cmd_id, arg_count; 语法,让用户无需修改编译器源码即可声明任意系统调用。 编译器将其注册为 builtin 函数,并自动在汇编末尾生成对应的 .syscall 指令。 你可以用它暴露 VM 内置的文件 I/O(cmd 4–9)、内存操作(cmd 1–3, 10–13),甚至自定义扩展。

The JVL frontend supports syscall name, cmd_id, arg_count; syntax, allowing users to declare any system call without modifying the compiler source. The compiler registers it as a builtin and automatically emits the corresponding .syscall directive at the end of the assembly. You can use it to expose VM built-in file I/O (cmd 4–9), memory operations (cmd 1–3, 10–13), or even custom extensions.

syscall fopen, 4, 2;   // FILE* fopen(path_addr, mode_addr)
syscall fclose, 5, 1;  // int  fclose(fd)
syscall fread, 6, 3;   // int  fread(fd, buf_addr, count)
syscall fwrite, 7, 3;  // int  fwrite(fd, buf_addr, count)

func main(): int {
    var fd = fopen(path, mode);
    /* ... read / write ... */
    fclose(fd);
    return 0;
}

JVL 高级语言JVL Language

JVL 是一门类 C 的前端语言,支持函数、变量、控制流、import 模块化导入、 以及 Rust 风格的借用表达式。编译器 jvlc 将 JVL 编译为 JVAV 汇编。

JVL is a C-like frontend language supporting functions, variables, control flow, modular imports, and Rust-style borrow expressions.

import "std/io.jvl";
import "std/math.jvl";

func factorial(n: int): int {
    if (n <= 1) { return 1; }
    return n * factorial(n - 1);
}

func main(): int {
    println(factorial(5));   // 120
    return 0;
}

MimiWorld 所有权系统MimiWorld Ownership

受 Rust 启发的所有权与借用检查系统。非 Copy 类型(ptr<T>array<T>) 在赋值时移动所有权,避免双重释放和野指针。Copy 类型(intcharbool) 按值复制,不受所有权规则约束。

A Rust-inspired ownership and borrow checker. Non-Copy types move ownership on assignment, preventing double-free and use-after-free.

var p: ptr<int> = alloc(1);   // p 拥有堆分配
var q = p;                      // ERROR: p 已被移动

var r = &p;                      // OK: 不可变借用
var s = &mut p;                 // OK: 可变借用(独占)
var t = &p;                      // ERROR: p 正被可变借用

标准库Standard Library

位于 std/ 目录,包含 io、math、mem、string 四个模块。 安装包中 std/bin/ 同级,将 bin/ 加入 PATH 后即可从任意位置使用。 查看详情 →

Located in std/ with io, math, mem, and string modules. In release packages std/ sits alongside bin/; add bin/ to PATH and use from anywhere. View details →

运算符Operators

PrecedenceOperators
1 (lowest)=
2||
3&&
4|, ^, &
5==, !=
6<, >, <=, >=
7<<, >>
8+, -
9*, /, %
10 (highest)-, !, ~, &, &mut

类型系统Type System

TypeCopy?说明Description
int有符号 128-bit 整数Signed 128-bit integer
char字符(word-sized)Character (word-sized)
bool布尔值Boolean
void-仅用于函数返回值Function return type only
ptr<T>指针(Move 语义)Pointer (Move semantics)
array<T>array<T> 是 ptr<T> 别名Alias for ptr<T>

Rust 风格诊断信息Rust-Style Diagnostics

编译器输出带有错误码、源文件位置、上下文行、源代码片段和 ^ 下划线的 Rust 风格诊断信息。 覆盖词法错误(E0100)、语法错误(E0200)、语义错误(E1000+)与 I/O 错误(E0300)。

The compiler emits Rust-style diagnostics with error codes, source locations, context lines, source snippets, and ^ caret underlines. Covers lexer (E0100), parser (E0200), semantic (E1000+), and I/O (E0300) errors.

error[E0200]: expected `;`, but found `return`
 --> hello.jvl:3:5
  |
2 |     var x = 5
3 |     return 0
  |     ^
4 | }
   = note: unexpected token in this position

跨平台与分发Cross-Platform & Distribution

支持 Linux、Windows 与 Android(x86、x64、ARM、ARM64)。 所有二进制均为静态链接,解压即可运行,无需额外安装运行时库。 GitHub Actions 多架构矩阵 CI 保证每次提交都通过编译与测试。

Supports Linux, Windows & Android (x86, x64, ARM, ARM64). All binaries are statically linked — extract and run, no extra runtime dependencies. GitHub Actions multi-arch matrix CI ensures every commit builds and passes tests.

PATH 就绪PATH-Ready

发布包中 std/bin/ 同级。将 bin/ 加入 PATH 后, jvlcjvavcjvmdisasm 均可从任意目录调用, 并自动定位标准库。

In release packages std/ sits alongside bin/. Add bin/ to PATH and use jvlc, jvavc, jvm, disasm from anywhere — the standard library is discovered automatically.