commit 3eab4fddc633c8244dfada74dcef45350d8a692e Author: Skye Terran Date: Wed Dec 8 16:01:04 2021 -0800 Initial commit diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4e2eafa --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..a3737bb --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# slipcompiler + A compiler to create slipcode binaries diff --git a/SlipcodeCompilationTest.ipynb b/SlipcodeCompilationTest.ipynb new file mode 100644 index 0000000..25abc12 --- /dev/null +++ b/SlipcodeCompilationTest.ipynb @@ -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 +} diff --git a/Test.slb b/Test.slb new file mode 100644 index 0000000..37d9a5a Binary files /dev/null and b/Test.slb differ diff --git a/Test.slc b/Test.slc new file mode 100644 index 0000000..fc626a7 --- /dev/null +++ b/Test.slc @@ -0,0 +1,14 @@ +LIT -1.0 +LIT 57.33 +SWAP +ADD +COPY +ADD +COPY +FLOOR +SUB +LIT 100.0 +SUB +FLOOR +LIT -0.97 +MUL \ No newline at end of file