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 pip 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:
inboxgrab a value from the INBOXoutboxput the value at hand to the OUTBOXcopyfrom Nput a copy of the value at hand onto floor tileNcopyto Ngrab a copy of the value stored on floor tileN.add Nadd the value stored on tileNto that at hand, the result goes to handssub Nsubstract the value stored on tileNfrom 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 alphabetbumpup Nincrements the value stored on tileNand copies to result to handsbumpdn Ndecrements the value stored on tileNand copies to result to handsjump Ljump to labelLthat should be defined somewhere asL:alone on its linejumpz Ljump to labelLif the value at hand is zerojumpn Ljump to labelLif the value at hand is less that zero
- if a tile number
Nis[A], the tile from which the value is copied is that whose number is stored on tileA - 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 programprogHRM.parse(source)creates an instance by parsing source codesource, it can be a file path, an opened file, or source code given as astrHRM.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 tocopyfrom - 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
- the content of directory
solutionsis from atesgoral.github.io/hrm-solutions - file
hrm/levels.jsonis from github.com/atesgoral/hrm-level-data
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.
Metadata
Release files for hrm-interpreter 1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hrm-interpreter-1.5.tar.gz | 191.8 kB | Without provenance | Details for hrm-interpreter-1.5.tar.gz |
Release files / hrm-interpreter-1.5.tar.gz
| Download URL | hrm-interpreter-1.5.tar.gz |
|---|---|
| Size | 191.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b5c2b3f4528eef527d713160b8d8830adde344218810f3774d2244ed7a2e736c
|
|
BLAKE2b-256 checksum How to use checksums |
2aff6ced57d07547b1b625b5f7c9761eebeeda7d8f045a84c1335265827ca80e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.2
|
Security for hrm-interpreter 1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.