#programming-language #historical #arithmetic-operations #tiny #minimalist #vtl-2 #altair

bin+lib vtl-rs

Very Tiny Language (VTL) in Rust, inspired by the historical VTL-2 on Altair 680b and others

3 releases

0.0.3 Oct 5, 2024
0.0.2 Oct 5, 2024
0.0.1 Oct 4, 2024

#180 in Programming languages

Download history 322/week @ 2024-09-29 97/week @ 2024-10-06 8/week @ 2024-10-13

427 downloads per month

GPL-3.0-only

295KB
589 lines

vtl-rs

vtl-rs is a Rust implementation of the Very Tiny Language (VTL-2), a simple, high-level language originally designed for the Altair microcomputers in the 1970s. This project aims to be a spiritual successor with simplicity and hackability in mind.

What is VTL-2?

Introduction excerpt from the VTL-2 manual. Source: [1]

VTL-2, or Very Tiny Language, was a minimalist programming language developed to run on microcomputers like the Altair 680b, often with as little as 1-2 KB of memory. Despite its size, VTL-2 provided essential programming constructs, including:

  • Basic arithmetic operations (+, -, *, /, %)
  • Variables and simple assignments
  • Simple control structures (IF statements and GOTO, but originally in a weird way)
  • Support for integer division and remainder operations

What vtl-rs Currently Does

The current implementation of vtl-rs in Rust is an early-stage interpreter with several core features already working:

1. CPU and Memory Structures:

  • CPU: Manages an accumulator, handles variables, and stores the remainder from division operations.
  • Memory: Allows for reading and writing at specific memory addresses (a feature still under development but modeled after historical architectures like the Altair).

2. Parser and Lexer:

  • The Lexer converts user input (expressions) into tokens (e.g., numbers, variables, and operators).
  • The Parser converts tokens into an Abstract Syntax Tree (AST), which can then be evaluated by the CPU.

3. Evaluator:

  • Supports evaluation of arithmetic expressions, including addition (+), subtraction (-), multiplication (*), division (/), and modulo (%).
  • Variable handling: You can assign values to variables like ?, and they will store intermediate results for use in further calculations.
  • String Handling: The evaluator supports string output using the ?= syntax. For example, ?="HELLO" will print "HELLO" to the output.

4. REPL (Read-Eval-Print Loop):

  • The interpreter runs in a REPL loop, allowing you to enter expressions interactively. The REPL supports expression evaluation and variable assignment.
  • It also has a shell history file, which is ~/.vtl-rs_history on Linux.

Example Usage

Here's a simple example of using vtl-rs in its current state ("OK" lines skipped for clarity):

VTL> ?=2+2
4
VTL> ?="HELLO WORLD!"
HELLO WORLD!
VTL> ?=2+2
4
VTL> A=123
OK (123)
VTL> B=456
OK (456)
VTL> ?=A+B
579
VTL> ?=7/3
2
VTL> ?=%
1

Build/Run

You can easily build the REPL (a library build is possible, too!) on Linux/macOS/Windows or wherever Rust is running. You will need current Rust and Cargo installed, then:

# to run vtl-rs:
cargo run
# this will give you the REPL prompt shown in the example

# or

# to build vtl-rs:
cargo build
# the executable will be somewhere inside the target/ directory after that

References

For those interested in the history of VTL-2, or the original manuals and documents, here are some useful references:

Dependencies

~5–17MB
~168K SLoC