123 lines
2.7 KiB
Plaintext
123 lines
2.7 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 71,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"opcodes = {\n",
|
|
" \"IDK\": 0x00,\n",
|
|
" \"LIT\": 0x01,\n",
|
|
" \"SWAP\": 0x02,\n",
|
|
" \"DEL\": 0x03,\n",
|
|
" \"COPY\": 0x04,\n",
|
|
" \"DEF\": 0x05,\n",
|
|
" \"END\": 0x06,\n",
|
|
" \"ADD\": 0x10,\n",
|
|
" \"SUB\": 0x11,\n",
|
|
" \"MUL\": 0x12,\n",
|
|
" \"DIV\": 0x13,\n",
|
|
" \"POW\": 0x14,\n",
|
|
" \"SQRT\": 0x15,\n",
|
|
" \"ONEMIN\": 0x16,\n",
|
|
" \"ROUND\": 0x17,\n",
|
|
" \"CEIL\": 0x18,\n",
|
|
" \"FLOOR\": 0x19,\n",
|
|
" \"MOD\": 0x1a,\n",
|
|
" \"FRACT\": 0x1b,\n",
|
|
" \"COMP\": 0x1c,\n",
|
|
" \"LERP\": 0x1d,\n",
|
|
" \"MIN\": 0x1e,\n",
|
|
" \"MAX\": 0x1f\n",
|
|
"}"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 72,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"source_file = open(\"Test.slc\")\n",
|
|
"source_code = source_file.read()\n",
|
|
"source_code = source_code.replace(\" \", \"\\n\")\n",
|
|
"source_code = source_code.split(\"\\n\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 74,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"1\n",
|
|
"1\n",
|
|
"2\n",
|
|
"16\n",
|
|
"4\n",
|
|
"16\n",
|
|
"4\n",
|
|
"25\n",
|
|
"17\n",
|
|
"1\n",
|
|
"17\n",
|
|
"25\n",
|
|
"1\n",
|
|
"18\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import struct\n",
|
|
"\n",
|
|
"byte_code = bytearray()\n",
|
|
"is_literal = False\n",
|
|
"for line in source_code:\n",
|
|
" if is_literal:\n",
|
|
" lit_bytes = bytearray(struct.pack(\">f\", float(line)))\n",
|
|
" byte_code.extend(lit_bytes)\n",
|
|
" is_literal = False\n",
|
|
" else:\n",
|
|
" if line == \"LIT\":\n",
|
|
" is_literal = True\n",
|
|
" instruction = opcodes[line]\n",
|
|
" print(instruction)\n",
|
|
" byte_code.append(instruction)\n",
|
|
"\n",
|
|
"pure_bytes = bytes(byte_code)\n",
|
|
"with open(\"Test.slb\", \"wb\") as binary_file:\n",
|
|
" binary_file.write(pure_bytes)"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"interpreter": {
|
|
"hash": "57baa5815c940fdaff4d14510622de9616cae602444507ba5d0b6727c008cbd6"
|
|
},
|
|
"kernelspec": {
|
|
"display_name": "Python 3.7.8 64-bit",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.8.8"
|
|
},
|
|
"orig_nbformat": 4
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|