ram-machine

Crates.ioram-machine
lib.rsram-machine
version2.0.1
sourcesrc
created_at2024-02-03 20:35:50.227867
updated_at2024-03-02 13:10:58.65627
descriptionRAM machine code interpreter
homepage
repositoryhttps://github.com/kamack38/ram-machine
max_upload_size
id1125630
size96,150
Kamack38 (kamack38)

documentation

README

RAM Machine Interpreter

This repo contains a code for a RAM Machine code parser and interpreter as defined by Łukasz Szkup in his Master Thesis

Installation

From crates.io

cargo install ram-machine

From GitHub

cargo install --git https://github.com/kamack38/ram-machine

Usage

RAM machine code interpreter

Usage: ram [OPTIONS] <COMMAND>

Commands:
  run    Run ram machine code from file
  check  Validates ram code syntax of a given file
  init   Generate a shell completion file
  debug  Run ram machine code and see the tape, input, output for each instruction
  help   Print this message or the help of the given subcommand(s)

Options:
  -q, --quiet    Don't pass code output to STDOUT
  -h, --help     Print help
  -V, --version  Print version

Generating TAB completion

To generate TAB completion file for a given shell run

ram init <shell>

Running code from file

ram run file.ram 1 2 3 4

Debugging code

ram debug examples/three_sum.ram 1 2 3

Here's the debug output:

╭───╮
│ 0 │
├───┤
│ ? │
╰───╯
Input: 1 2 3
Output:
Next instruction: READ 1
╭───┬───╮
│ 0 │ 1 │
├───┼───┤
│ ? │ 1 │
╰───┴───╯
Input: 1 2 3
Output:
Next instruction: READ 0
╭───┬───╮
│ 0 │ 1 │
├───┼───┤
│ 2 │ 1 │
╰───┴───╯
Input: 1 2 3
Output:
Next instruction: READ 2
╭───┬───┬───╮
│ 0 │ 1 │ 2 │
├───┼───┼───┤
│ 2 │ 1 │ 3 │
╰───┴───┴───╯
Input: 1 2 3
Output:
Next instruction: ADD 1
╭───┬───┬───╮
│ 0 │ 1 │ 2 │
├───┼───┼───┤
│ 3 │ 1 │ 3 │
╰───┴───┴───╯
Input: 1 2 3
Output:
Next instruction: ADD 2
╭───┬───┬───╮
│ 0 │ 1 │ 2 │
├───┼───┼───┤
│ 6 │ 1 │ 3 │
╰───┴───┴───╯
Input: 1 2 3
Output:
Next instruction: WRITE 0
╭───┬───┬───╮
│ 0 │ 1 │ 2 │
├───┼───┼───┤
│ 6 │ 1 │ 3 │
╰───┴───┴───╯
Input: 1 2 3
Output: 6
Next instruction: HALT

Roadmap for v1

  • Automatic changelog
  • Cargo crate with automatic publish to crates.io
  • Use clap to parse args
  • Repl
  • Debug mode
Commit count: 0

cargo fmt