← Dolaima← Docs indexKotlin原文中文

Kotlin

The same approach as Java, with shorter syntax.

How to run it on your phone

vml run examples/kotlin/test/sysinfo.kt

Compiling takes a while (one to two minutes for C, a few seconds for scripting languages). Once the program is running, the gamepad is at the bottom of the screen - the D-pad and the four action buttons are all there. Tap the back arrow in the top-right corner to return to the Shell.

What to know before you write

Examples

FileWhat it shows
test/catch.ktCatch the blocks
test/sysinfo.ktDevice information

Also in this folder: app/gomoku.kt, app/minesweeper.kt, app/puzzle15.kt, app/snake.kt, demo/demo_std.kt, fibonacci/main.kt, geometry/main.kt, test/libs.kt, tty/demo_tty.kt, ui/demo_ui.kt

Pitfalls we hit on real devices


The rest of this page is taken straight from the VML source (third_party/vml/VMLPrepares/KotlinCompiler/): the README covers what this front end supports and how to compile it, and the language reference covers the syntax itself. When upstream changes, regenerating this page brings it up to date.

Language reference

Kotlin Language Compiler Specification

Version: v1.0 | Date: 2026-07-06 | Revised by: Shenzhen Tanso Intelligent Technology Co., Ltd.

Specification standard

FieldValue
Target standardKotlin 1.0+ (minimal subset)
Release year2016
Completeness~93%
MCU completeness~91%
Tests29 passing
Updates2026-05-21: data class toString/equals implemented; sealed-class exhaustiveness checks upgraded to compile errors; when-expression return values confirmed implemented

Overview

This compiler supports a subset of the Kotlin language and compiles Kotlin source into VML assembly. It uses a three-stage Lexer → Parser → CodeGenerator architecture, about 1200 lines of C#.

Supported language features

1. Data types and literals
2. Variable declarations
3. Functions
4. Control flow
5. Classes
6. Built-in functions
7. Operators

Code generation (VML)

Kotlin syntaxVML instruction
val/var declarationsSTORE into an R12-relative local variable frame
Arithmetic operationsADD SUB MUL DIV MOD
Conditionals if/elseJZ/JNE/JMP + LABEL
while/for loopsLABEL + comparison + JZ/JMP
when expressionsPUSH the subject; compare branch conditions; JNE to the next; on a match JMP to end
println(x)MOVE R0, x; SYSCALL #6; MOVE R0, #10; SYSCALL #4
Class constructionSYSCALL #40 heap allocation; STORE the properties; RET the return address
data classtoString/equals generated automatically
Function callsPUSH R15, PUSH R12, MOVE R12 R13 (prologue), caller cleans up R13
returnMOVE R13 R12, POP R12, POP R15, RET (epilogue)
LambdaPUSH R15/R14, MOVE R14 R13, closure body, POP R14, POP R15, RET

Missing features

Advanced language features
Standard library

Floating-point and 64-bit compile modes

The same three-parameter control as every VML compiler:

ParameterValuesDefaultDescription
--float32hard/soft/nonehard32-bit floating point (Float)
--float64hard/soft/nonesoft64-bit floating point (Double)
--int64hard/soft/nonesoft64-bit integers (Long)

How to compile

# compile directly
dotnet run --project VMLTool -- input.kt -o output.vml

# run
dotnet run --project VMLEmulators/ConsoleEmulator -- -r output.vml

Completeness assessment

ComponentCompleteness
Lexical analysis~98% (full token set, including the data keyword)
Syntax analysis~95% (fun/val/var/if/while/for/when/class/data class/is/in/lambda/range/sealed/when exhaustiveness)
Code generation~93% (expressions/control flow/strings/classes/data class/lambda/inline assembly/SafeCall/Elvis/generic erasure)
Standard library~50% (the basic functions in Lib/kotlin/ are already inlined)
Overall~93%

🆕 String types (v1.65.19)

This language's compiler uses .wstring (UTF-16LE) as its internal string storage by default.

ModeDefault encodingVML directiveSYSCALL output
MCU (default).string (UTF-8).string#1
OS.wstring (UTF-16LE).wstring#391

Predefined macro: VML_WSTRING — defined automatically in OS mode, undefined in MCU mode Output function: OS mode automatically uses shared_print_wstr (converts UTF-16LE→UTF-8 for you)

// user code can test the macro to tell which encoding is in use
#ifdef VML_WSTRING
  // strings are wstring (UTF-16LE) by default
#else
  // strings are UTF-8 by default
#endif

Compiler README

Kotlin 1.0 Compiler

Path: VMLPrepares/KotlinCompiler/ Completeness: ~93% | 🟢 production ready Standard library: Lib/kotlin/ (to be created)

Features

Missing features

Compile modes

MCU mode (default: --mode mcu)

MCU mode is tuned for single-chip and bare-metal environments (Arduino/STM32/8051 and so on) and automatically skips features that are incompatible with an operating system.

Skipped (these constructs generate no code):

Kept (implemented on top of the BIOS):

OS mode (--mode os, reserved)

OS mode targets environments that have an operating system (embedded Linux, an RTOS, and so on). It will support the full language feature set (file system, threads, async, exceptions, reflection).

Usage

dotnet run --project VMLTool -- input.kt -o output.vml

Tests

29 tests passing (embedded in the compiler source as verification)