← Dolaima← Docs indexScheme原文中文

Scheme

A Lisp dialect where brackets are everything.

How to run it on your phone

vml run examples/scheme/test/sysinfo.scm

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.scmCatch the blocks
test/sysinfo.scmDevice information

Also in this folder: demo/demo_std.scm, math/main.scm, sicp/1.2.5-greatest_common_divisors_gcd.scm, test/libs.scm, tty/demo_tty.scm, ui/demo_ui.scm

Pitfalls we hit on real devices


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

Scheme language compiler specification

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

Specification standard

FieldValue
Target standardR5RS (1998) subset
Publication year1998
Completeness~93%
Tests32 passing

Keywords

define lambda let let* if cond else begin and or not set! display newline print peek poke asm chipasm eq? equal? null?

Overview

A subset of the Scheme (R5RS) language is supported, compiled to VML assembly. The architecture parses S-expressions and supports the core features of functional programming.

Supported language features

1. Data types
2. Expressions
3. Functions
4. Binding forms
5. Input and output
6. Memory access
7. Inline assembly

Compile modes

MCU mode (default, --mode mcu)

Tuned for microcontroller environments.

OS mode (--mode os, reserved)

Every language feature is available.

Usage examples

;; factorial
(define (fact n)
  (if (<= n 1)
      1
      (* n (fact (- n 1)))))

;; anonymous function
(define f (lambda (x) (+ x 1)))
(print (f 5))

;; let binding
(let ((x 10) (y 20))
  (print (+ x y)))

;; let* sequential binding
(let* ((x 1) (y (+ x 1)))
  (print y))

;; cond with several branches
(define (sign x)
  (cond ((< x 0) (print -1))
        ((> x 0) (print 1))
        (else (print 0))))

;; memory access
(asm "nop")
(peek 0x4000)
(poke 16384 65)

Floating-point and 64-bit compile modes

The VML toolchain controls how floating-point values and 64-bit integers are handled through three compile options:

OptionValuesDefaultDescription
--float32hard / soft / nonehardHow 32-bit floating point (flonum) is handled
--float64hard / soft / nonesoftHow 64-bit floating point is handled
--int64hard / soft / nonesoftHow 64-bit integers are handled
32-bit floating point (float32)

The flonum (inexact floating-point number) in Scheme is handled in one of the following modes when compiling to VML:

64-bit floating point (double)

Double-precision floating-point arithmetic in Scheme is compiled in one of the following modes:

64-bit integers (int64)

Large integers in Scheme (bignum) that go beyond the 32-bit range are handled in one of the following modes:

Software simulation libraries

The software simulation libraries above all live in the Lib/shared/ directory. They are written in C and compiled to VML by the C compiler, and every language shares them:

Library filePurposeCore functions
softfloat.cQ15.16 fixed-point 32-bit floating-point simulation__vml_float_add/sub/mul/div/neg/abs/cmp, __vml_int2float/float2int
softdouble.cIEEE 754 double-precision 64-bit floating-point simulation__vml_double_add/sub/mul/div/neg/abs/cmp, __vml_int2double/double2int, __vml_float2double/double2float
softint64.c64-bit integer double-register simulation__vml_i64_add/sub/neg/and/or/xor/not/shl/shr

Compiling

# compile Scheme to VML
dotnet run --project VMLPrepares/SchemeCompiler input.scm -o output.vml

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

Tests

# run the Scheme tests
dotnet test VMLTests/VMLTests.csproj --filter "SchemeTests"

🆕 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): strings are output as UTF-8 (.string) OS mode: the encoding can be tested with the VML_WSTRING macro

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

Compiler README

Scheme (R5RS subset) compiler

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

Features

Missing features

Compile modes

MCU mode (default, --mode mcu)

MCU mode is tuned for microcontroller and bare-metal environments (Arduino/STM32/8051 and the like) and automatically skips features that need an operating system.

Skipped (no code is generated when these appear):

Kept (the low-level parts are provided by the BIOS):

OS mode (--mode os, reserved)

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

Usage

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

Tests

Tests are embedded in the compiler source as verification