← Dolaima← Docs indexRuby原文中文

Ruby

Usable, but this front end supports the fewest features of all: write everything flat.

How to run it on your phone

vml run examples/ruby/test/sysinfo.rb

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.rbCatch the blocks (a completely flat version; this path cannot do functions)
test/file_io.rbReading and writing files
test/sysinfo.rbDevice information

Also in this folder: app/invaders.rb, app/minesweeper.rb, demo/demo_std.rb, stringutil/main.rb, test/libs.rb, tty/demo_tty.rb, ui/demo_ui.rb

Pitfalls we hit on real devices


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

Ruby Language Compiler Specification

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

Specification standard

FieldValue
Target standardRuby 1.9+ subset
Release year1995 (Ruby 1.9: 2007)
Completeness~96%
File extension.rb

Overview

This compiler supports the core subset of the Ruby language and compiles Ruby source code into VML (Virtual Machine Language) assembly. Compiler flow: preprocessing → lexical analysis → syntax analysis → code generation.

Supported language features

1. Data types
2. Variables
x = 10           # local variable
@x = 20          # instance variable (recognized but limited in function)
name = "hello"   # string variable
3. Operators
Arithmetic operators
+    # addition
-    # subtraction
*    # multiplication
/    # division
%    # modulo
**   # exponentiation
Compound assignment
+=   # add and assign
-=   # subtract and assign
*=   # multiply and assign
/=   # divide and assign
Comparison operators
==   # equal
!=   # not equal
<    # less than
>    # greater than
<=   # less than or equal
>=   # greater than or equal
<=>  # spaceship operator (comparison result -1/0/1)
Logical operators
!    # logical not (not)
4. Control flow
Conditionals
if condition
  # then body
elsif other_condition
  # elsif body
else
  # else body
end

unless condition
  # then body (executed when the condition is false)
end
Loops
while condition
  # loop body
end

until condition
  # loop body (repeats while the condition is false)
end
for loop
for var in start..end
  # loop body
end
5. Method definitions
def method_name(param1, param2)
  # method body
  return value
end

def method_name  # method without parameters
  # body
end
6. Class definitions
class ClassName
  def method_name
    # method body
  end
end

Internally, classes are compiled into methods carrying a self. prefix, and self is stored as the first local variable.

7. Return values
return value     # with a return value
return           # returns nil
8. Method calls
method_name(arg1, arg2)
object.method_name(arg1)
method_name       # call without parameters
9. Comments
# single-line comment

Expression precedence

PrecedenceTypeOperators
1 (lowest)assignment= += -= *= /=
2comparison== != < > <= >= <=>
3addition+ -
4multiplication* / % **
5unary- !
6 (highest)primaryliterals, variables, function calls, parentheses

Predefined macros

MacroValue
__VML__1
__VML_VERSION__"1.65.32"
__RUBY__1
__DATE__compilation date
__TIME__compilation time

Known limitations


🆕 String encoding (v1.65.19)

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

Pseudo-opWidthEncodingC 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 may use them as needed.

Compiler README

Ruby Compiler

Path: VMLPrepares/RubyCompiler/ Completeness: ~96% | 🟢 Production ready Standard library: Lib/ruby/

Features

Compilation modes

MCU mode (default --mode mcu)

MCU mode is optimized for microcontroller/bare-metal environments and automatically skips features that are incompatible with an operating system.

Skipped (not supported on MCU):

Retained (implemented by the BIOS):

OS mode (--mode os)

OS mode supports the full set of language features (file system, threads, etc.).

RAM levels

Usage

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

Tests