← Dolaima← Docs indexD原文中文

D

C-style syntax, a little more relaxed than C to write.

How to run it on your phone

vml run examples/d/test/sysinfo.d

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.dCatch the blocks
test/sysinfo.dDevice information

Also in this folder: demo/demo_std.d, test/libs.d, tty/demo_tty.d, ui/demo_ui.d


The rest of this page is taken straight from the VML source (third_party/vml/VMLPrepares/DCompiler/): 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

D language compiler specification

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

Metadata

PropertyValue
LanguageD
StandardD 2.0 subset
Yearfirst released in 2001
Completeness~97%
Source file extension.d
File encodingUTF-8 (default)

Overview

D is a systems programming language with C-like syntax and a modular design. This compiler implements a functional subset of the D 2.0 specification, running against the MCU-safe subset environment of the VML virtual machine. The compilation flow is:

source.d → [preprocessor] → [Lexer] → [Parser] → [CodeGenerator] → VML assembly (.vml)
Compiler entry points
Calling convention

A C-like calling convention is used: arguments are pushed onto the stack from right to left and the caller is responsible for stack cleanup. Register R0 holds integer/boolean/pointer return values; floating-point return values use register F0.


Supported features

1. Data types
TypeKeywordVML IR widthDescription
Voidvoid—function has no return value
Integerint32-bit signedsupports decimal and hexadecimal (0x) literals
Single-precision floatfloat32-bitIEEE 754 single precision
Double-precision floatdouble64-bitcurrently stored downgraded to float
Booleanbool32-bittrue = 1, false = 0
Stringstringpointer (32-bit)immutable character array; literals go into the data section
Characterchar8-bitsingle-quoted literal, stored as an int
Classclassreference typemembers are accessed through R12-0 (this)
Structstructvalue typesyntactically supported, parsed the same as class
Interfaceinterfaceplaceholderinner declarations are skipped during parsing
Enumenum32-bitsupports explicit assignment = expr

Literal syntax:

2. Module system
module mymodule;                    // declare the current module name
import std.stdio;                   // import a module
import foo.bar.baz;                 // dotted import path

The import statement only supports the static import syntax; the module name is extracted during parsing and used for library linking. The module declaration is syntactically accepted but has no actual semantic effect.

3. Variable declarations
int x = 10;                         // declaration + initialization
float pi;                           // declaration (default-initialized to 0)
string name = "hello";              // string variable
bool flag = true;                   // boolean variable
char c = 'A';                       // character variable
ClassName obj;                      // class-type variable (default-initialized to 0/null)

Semantics:

4. Operators
4.1 Arithmetic operators
OperatorOperationExample
+additiona + b
-subtractiona - b
*multiplicationa * b
/divisiona / b
%moduloa % b
^^exponentiationa ^^ b

Note: ^^ exponentiation has no native power instruction at the VML level, so the compiler lowers ^^ to multiplication * as an approximation.

4.2 Comparison operators
OperatorOperationDescription
==equalreturns 1/0
!=not equalreturns 1/0
<less thanreturns 1/0
>greater thanreturns 1/0
<=less than or equalreturns 1/0
>=greater than or equalreturns 1/0

A comparison returns an integer value: 1 for true, 0 for false.

4.3 Logical operators
OperatorOperationDescription
&&logical ANDCMP + JE short-circuit evaluation
||logical ORshort-circuit evaluation
!logical NOTunary negation

Logical operations use a short-circuit strategy: && skips the right operand when the left one is false; || skips the right operand when the left one is true.

4.4 Assignment operators
OperatorOperation
=direct assignment
+=add and assign
-=subtract and assign
*=multiply and assign
/=divide and assign

Compound assignment operators (+=, -=, *=, /=) are expanded internally into the form a = a op value:

a += b;    // equivalent to a = a + b;
a -= 5;    // equivalent to a = a - 5;
a *= 2;    // equivalent to a = a * 2;
a /= 3;    // equivalent to a = a / 3;
5. Control flow
5.1 if / else statements
if (condition) {
    // then body
}

if (condition) {
    // then body
} else {
    // else body
}

if (x > 0) {
    return 1;
} else if (x < 0) {
    return -1;
} else {
    return 0;
}

The condition is evaluated and compared with 0; when false the jump goes to the else label or the end label.

5.2 while statements
while (condition) {
    // loop body
}
5.3 do-while statements
do {
    // loop body
} while (condition);

Implementation: do-while is expanded at compile time into { body; while (cond) { body } }.

5.4 for statements (C style)
for (init; condition; increment) {
    // loop body
}

// example
for (int i = 0; i < 10; i = i + 1) {
    x = x + i;
}

All three clauses are optional:

5.5 break / continue

The break and continue keywords are not implemented at present. They are absent from the lexer's keyword table, so they are treated as ordinary identifiers.

5.6 return statements
return;              // void return
return expression;   // return with a value

The return value is stored in register R0, R12 is restored and then RET is executed.

6. Functions
// full declaration form
int add(int a, int b) {
    return a + b;
}

// void return type
void greet(string name) {
    // ...
}

// no parameters
int getAnswer() {
    return 42;
}

Syntax: returnType functionName(paramType paramName, ...) { body }

Internal implementation:

7. Classes and structs
7.1 class
class Animal {
    void speak() {
        // member function
    }

    int getAge() {
        return this.age;   // the this keyword
    }
}
7.2 struct
struct Point {
    int x;
    int y;
}

Syntactically the same as class, sharing the ClassDeclNode AST node. The difference is only at the semantic level (value type vs reference type) and the current implementation does not distinguish them.

7.3 interface
interface Drawable {
    void draw();
}

An interface declaration is parsed, its inner declaration body is skipped and a placeholder AST node is returned. Interface methods generate no code.

7.4 enum
enum Color {
    Red,           // implicit value 0
    Green,         // implicit value 1
    Blue = 5,      // explicit assignment
    Yellow         // implicit value 6
}
8. Comments
TypeSyntaxDescription
Single-line comment// textfrom // to the end of the line
Block comment/* text */multi-line, cannot nest
Nested block comment/+ text +/D's native nested comment, not specially supported at present

Inside the compiler LexerBase.SkipBlockComment handles /* ... */ and SkipLineComment handles // .... The /+ ... +/ nested comment syntax is not implemented in the lexer at present.

Note: comment tokens are produced during tokenization but do not take part in parsing (they are skipped by SkipComments()).

9. String literals
"hello world"                       // ordinary string
"line1\nline2"                      // with an escape sequence
"quote: \"inside\""                 // escaped double quote
10. Character literals
'a'                                 // the character 'a'
'\n'                                // newline
'\t'                                // tab
'\\'                                // backslash
11. Expression grammar
Expression := Assignment
Assignment := LogicalOr ('=' | '+=' | '-=' | '*=' | '/=') Assignment | LogicalOr
LogicalOr  := LogicalAnd ('||' LogicalAnd)*
LogicalAnd := Comparison ('&&' Comparison)*
Comparison := Additive (('==' | '!=' | '<' | '>' | '<=' | '>=') Additive)*
Additive   := Multiplicative (('+' | '-') Multiplicative)*
Multiplicative := Unary (('*' | '/' | '%' | '^^') Unary)*
Unary      := ('-' | '!') Unary | Postfix
Postfix    := Primary ('(' Arguments? ')')*
Primary    := Integer | Float | String | Char | true | false | null
            | this | Identifier | '(' Expression ')'
12. Expression precedence

Listed from lowest to highest precedence:

PrecedenceOperatorsAssociativity
1 (lowest)= += -= *= /=right
2||left
3&&left
4== != < > <= >=left
5+ -left
6* / % ^^left
7- (unary) ! (unary)right
8 (highest)() (function call)left
13. Preprocessor support

The compiler integrates a C-style preprocessor (Preprocessor) that runs before lexing:

Predefined macros
Macro nameValueDescription
__VML__1VML target platform marker
__VML_VERSION__"1.65.32"VML toolchain version
__D__1D language source file marker
__DATE__"MMM dd yyyy"compilation date
__TIME__"HH:mm:ss"compilation time
Preprocessor directives

Standard C preprocessor directives are supported; the preprocessor is only activated when the source file contains a # character:

14. Entry point and library linking

Limitations and unimplemented features

The following features belong to the full D language specification but are currently not supported:

Metaprogramming
Contract programming
Memory management
Control flow
Type system
Composite types
Other

Compilation options

Compilation options supported when invoking through the CLI tool VMLTool:

OptionMeaning
-o <file>output file path
-mode mcuMCU-safe subset mode (default)
-mode osfull OS mode
--std=<std>specify the language standard version
-D <macro>define a preprocessor macro
-U <macro>undefine a preprocessor macro
-I <path>add an include search path
-L <path>add a library search path
-staticstatic linking
-shareddynamic linking
-target <arch>specify the target architecture

Full grammar reference (EBNF)

Program       := { TopLevelDecl }

TopLevelDecl  := ModuleDecl | ImportDecl | FuncDef | VarDecl
               | ClassDecl | StructDecl | InterfaceDecl | EnumDecl

ModuleDecl    := "module" Identifier ";"
ImportDecl    := "import" Identifier { "." Identifier } ";"

Type          := "void" | "int" | "float" | "double" | "bool"
               | "string" | "char" | Identifier

VarDecl       := Type Identifier [ "=" Expression ] ";"

FuncDef       := Type Identifier "(" [ ParamList ] ")" Block
ParamList     := Type Identifier { "," Type Identifier }

ClassDecl     := "class" Identifier "{" { Declaration } "}" ";"
StructDecl    := "struct" Identifier "{" { Declaration } "}" ";"
InterfaceDecl := "interface" Identifier "{" { Declaration } "}" ";"
EnumDecl      := "enum" Identifier "{" EnumMember { "," EnumMember } [ "," ] "}" ";"
EnumMember    := Identifier [ "=" Expression ]

Block         := "{" { Statement } "}"
Statement     := ReturnStmt | IfStmt | WhileStmt | DoWhileStmt
               | ForStmt | VarDecl | ExpressionStmt

ReturnStmt    := "return" [ Expression ] ";"
IfStmt        := "if" "(" Expression ")" Block [ "else" (IfStmt | Block) ]
WhileStmt     := "while" "(" Expression ")" Block
DoWhileStmt   := "do" Block "while" "(" Expression ")" ";"
ForStmt       := "for" "(" [ForInit] ";" [ Expression ] ";" [ Expression ] ")" Block
ForInit       := VarDecl | Expression
ExpressionStmt:= Expression ";"

Expression    := Assignment
Assignment    := LogicalOr [ ("=" | "+=" | "-=" | "*=" | "/=") Assignment ]
LogicalOr     := LogicalAnd { "||" LogicalAnd }
LogicalAnd    := Comparison { "&&" Comparison }
Comparison    := Additive [ ("==" | "!=" | "<" | ">" | "<=" | ">=") Additive ]
Additive      := Multiplicative { ("+" | "-") Multiplicative }
Multiplicative:= Unary { ("*" | "/" | "%" | "^^") Unary }
Unary         := ["-" | "!"] Postfix
Postfix       := Primary { "(" [ Expression { "," Expression } ] ")" }

Primary       := Integer | FloatLiteral | StringLiteral | CharLiteral
               | "true" | "false" | "null" | "this"
               | Identifier
               | "(" Expression ")"

Identifier    := Letter { Letter | Digit | "_" }
Integer       := Digit { Digit } | "0x" HexDigit { HexDigit }
FloatLiteral  := Digit { Digit } "." Digit { Digit }
StringLiteral := '"' { Character } '"'
CharLiteral   := "'" Character "'"

Comment       := "//" { Character }
BlockComment  := "/*" { Character } "*/"

🆕 String encoding (v1.65.19)

This language compiler uses the VML string system indirectly through the shared library (Lib/shared/).

DirectiveWidthEncodingC type
.string8-bitUTF-8char*
.wstring16-bitUTF-16LEwchar_t*
.ustring32-bitUTF-32LEchar32_t*

MCU mode (default): string output is UTF-8 (.string) OS mode: the encoding can be determined through the VML_WSTRING macro

The shared library already provides wide-string conversion functions (wchar.h/uchar.h) that each language compiler can use as needed.

Compiler README

D compiler

Path: VMLPrepares/DCompiler/ Completeness: ~97% | 🟢 production ready Standard library: Lib/d/

Features

Compile modes

MCU mode (default, --mode mcu)

MCU mode is tuned for microcontroller / bare-metal environments.

Skipped (MCU does not support them):

Kept:

OS mode (--mode os)

OS mode supports the full set of language features.

RAM level

Usage

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

Tests