Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/frewtypebbles/bytecode-virtual-machine-python-prototype
https://github.com/frewtypebbles/bytecode-virtual-machine-python-prototype
Last synced: 14 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/frewtypebbles/bytecode-virtual-machine-python-prototype
- Owner: FrewtyPebbles
- License: mit
- Created: 2024-03-16T06:12:10.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2024-03-16T06:31:07.000Z (11 months ago)
- Last Synced: 2025-01-19T13:56:42.226Z (14 days ago)
- Language: Python
- Size: 23.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Bytecode Interpreter/Compiler Implemented in a Bytecode Interpreted/Compiled Language
> This program compiles LLVM-IR style instructions into proprietary bytecode and interprets said proprietary bytecode.
Things to consider:
- This was a 2 day project I made for fun, therefore there are likely bugs.
- This is not meant to have any practical use case and strictly exists to be redundant.
- Please dont take this seriously.
## Example Program
This program performs math operations on an initial input value. Kinda like a bad calculator where all of the operations are ordered from left to right.
```py
# Calculates numbers with unordered operations.
NUM result 0
NUM curr_val 0STR eq_disp ""
STR add_str "+"
STR sub_str "-"
STR mul_str "*"
STR div_str "/"
STR eq_str "="
STR input ""
STR op ""# Helper blocks
BLOCK add
ADD result result curr_val
JUMP get_operationBLOCK sub
SUB result result curr_val
JUMP get_operationBLOCK mul
MUL result result curr_val
JUMP get_operationBLOCK div
DIV result result curr_val
JUMP get_operationBLOCK get_operation
STDOUT eq_disp
STDIN op
EQ eq_cond op eq_str
COND_JUMP eq eq_cond
ADD eq_disp eq_disp op
JUMP get_input_numBLOCK get_input_num
STDOUT eq_disp
STDIN input
ADD eq_disp eq_disp input
CAST_NUM curr_val input
JUMP condsSTART
STDIN original_val
ADD eq_disp eq_disp original_val
CAST_NUM result original_val
JUMP get_operationBLOCK conds
# Operators
## add
EQ add_cond op add_str
COND_JUMP add add_cond## sub
EQ sub_cond op sub_str
COND_JUMP sub sub_cond## mul
EQ mul_cond op mul_str
COND_JUMP mul mul_cond## div
EQ div_cond op div_str
COND_JUMP div div_condBLOCK eq
STR str_result "{} = {}\n"
FMT str_result str_result eq_disp result
STDOUT str_result
```