Skip to main content

Minimalist Human Resource Machine interpreter

Project description

Human Resource Machine interpreter

This is a Python interpreter for programs from the Human Resource Machine game from Tomorrow Corporation. Within the game, one may copy/paste the source code that is edited visually. This library features a parser for this code, and CLI/TUI interpreters.

>>> from hrm import HRM
>>> hrm = HRM.parse('level-2.hrm')
>>> hrm([1, 0, -2, 'D', 0, 0, 8, 9])
1 0 -2 D 0 0 8 9

Installation

Just run pip install hrm-interpreter or clone the git repository and run python setup.py install.

Language

If not copied from the game, a program may be written from scratch:

  • each command is given on a single line
  • empty line and spacing are non-significant
  • comments start with -- and extend up to the end of the line
  • code is case insensitive (in the implementation at least)
  • available commands are:
    • inbox grab a value from the INBOX
    • outbox put the value at hand to the OUTBOX
    • copyfrom N put a copy of the value at hand onto floor tile N
    • copyto N grab a copy of the value stored on floor tile N.
    • add N add the value stored on tile N to that at hand, the result goes to hands
    • sub N substract the value stored on tile N from that at hand, the result goes to hands. This operation is valid on letters in which case it computes the distance between two letters in the alphabet
    • bumpup N increments the value stored on tile N and copies to result to hands
    • bumpdn N decrements the value stored on tile N and copies to result to hands
    • jump L jump to label L that should be defined somewhere as L: alone on its line
    • jumpz L jump to label L if the value at hand is zero
    • jumpn L jump to label L if the value at hand is less that zero
  • if a tile number N is [A], the tile from which the value is copied is that whose number is stored on tile A
  • labels are defined using NAME:

Copying code from the game may yield other elements (like drawn tiles labels and comments), but they are ignored in this implementation.

API

Class hrm.HRM is the interpreter itself, it is initialised as either:

  • HRM(prog) creates an instance to run an already parsed program prog
  • HRM.parse(source) creates an instance by parsing source code source, it can be a file path, an opened file, or source code given as a str
  • HRM.from_level(number) load a level from the game and returns the corresponding instance, together with a valid inbox and tiles initial state to run it

An HRM instance hrm can execute the program for various inputs using method hrm(inbox, floor=[], verbose=False) which runs the program with inbox (list of integers or uppercase characters). If floor is provided, it initialised the tiles on the floor. If verbose is True, program execution is traced.

Limitations

  • the parser is not very robust

Differences with the game:

  • the number of available tiles is not limited
  • indirection [A] is not limited to copyfrom
  • a label may be jumped to from several locations in the program, which is never the case in code copied from the game as each jump is attached to exactly one target

Borrowed files

Licence

Appart from the borrowed files above, this package is (C) 2023 Franck Pommereau franck.pommereau@univ-evry.fr and released under the MIT Licence, see LICENCE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hrm_interpreter-1.4.tar.gz (215.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hrm_interpreter-1.4-py3-none-any.whl (36.7 kB view details)

Uploaded Python 3

File details

Details for the file hrm_interpreter-1.4.tar.gz.

File metadata

  • Download URL: hrm_interpreter-1.4.tar.gz
  • Upload date:
  • Size: 215.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.0

File hashes

Hashes for hrm_interpreter-1.4.tar.gz
Algorithm Hash digest
SHA256 b5585fc8f350f77f530a6a52ed138750be15f236b89e7168dde4ea694e2d1422
MD5 45db0f622346abae8105296748b42e9b
BLAKE2b-256 4793cd72e339dea19aff297e1bd083e8c86642c892e868fa84581a5d47802445

See more details on using hashes here.

File details

Details for the file hrm_interpreter-1.4-py3-none-any.whl.

File metadata

  • Download URL: hrm_interpreter-1.4-py3-none-any.whl
  • Upload date:
  • Size: 36.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.0

File hashes

Hashes for hrm_interpreter-1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 288aa4601814cd6500c632d6a9e63341af23f191769743fe0e45d12dc56f3531
MD5 0e15e8f8abe73323713bf6eb03ba3c0e
BLAKE2b-256 3c2f7385f20d449a7a35aa8fb6e057058707cbc98ec7d8c619f3826d7fb75777

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page