Initial commit
This commit is contained in:
commit
3eab4fddc6
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Auto detect text files and perform LF normalization
|
||||||
|
* text=auto
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2021 Skye Terran
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
2
README.md
Normal file
2
README.md
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# slipcompiler
|
||||||
|
A compiler to create slipcode binaries
|
122
SlipcodeCompilationTest.ipynb
Normal file
122
SlipcodeCompilationTest.ipynb
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
{
|
||||||
|
"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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user