vtl-rs

Crates.iovtl-rs
lib.rsvtl-rs
version0.0.3
sourcesrc
created_at2024-10-04 01:25:24.649543
updated_at2024-10-05 14:52:09.233629
descriptionVery Tiny Language (VTL) in Rust, inspired by the historical VTL-2 on Altair 680b and others.
homepage
repositoryhttps://codeberg.org/spezifisch/vtl-rs
max_upload_size
id1395895
size375,762
(spezifisch)

documentation

README

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:

Commit count: 0

cargo fmt