{ "info": { "author": "Christian Stigen Larsen", "author_email": "csl@csl.name", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Natural Language :: English" ], "description": "lyn \u2014 Python bindings for GNU Lightning\n=======================================\n\nLyn provides Python bindings for GNU Lightning::\n\n GNU lightning is a library that generates assembly language code at\n run-time; it is very fast, making it ideal for Just-In-Time compilers, and\n it abstracts over the target CPU, as it exposes to the clients a\n standardized RISC instruction set inspired by the MIPS and SPARC chips.\n\nThe source code is on GitHub: https://github.com/cslarsen/lyn/ \nReleases are uploaded to PyPI: https://pypi.python.org/pypi/lyn/\n\n*\"Lyn\"* is the Norwegian word for \"lightning\".\n\nWarning\n-------\n\nThis project is in early alpha! Many instructions have not been implemented\nyet, and tests are lacking for those that have This means that you shouldn't be\nsurprised to segfault the entire Python process (you will have to get used to\nthat anyway, unless you happen to always write bug-free Lightning code).\n\nBut, you can use it *right now* to JIT-compile native machine code, straight\nfrom Python. To get a taste of Lyn and GNU Lightning, scroll down to the\nexamples below.\n\nInstallation\n------------\n\n>From PyPi::\n\n $ pip install lyn\n\n>From the bleeding edge::\n\n $ git clone https://github.com/cslarsen/lyn\n $ cd lyn\n $ python setup.py test\n $ python setup.py install\n\nNon-Python Dependencies\n-----------------------\n\nYou must install the following libraries using your favourite package manager:\n\n * The GNU Lightning shared library v2.1.0 (later versions may also work),\n http://www.gnu.org/software/lightning/\n\n * Optional: The Capstone Disassembler,\n http://www.capstone-engine.org\n\nThe last time I compiled GNU Lightning on Linux, I had to disable the\ndisassembly options because of linker problems with ``libopcodes.so``. This\nworked for me::\n\n $ ./configure --enable-shared --disable-static --disable-disassembler\n\nTo use Capstone as a disassembler with Lyn, you have to install the Python\nmodules and the C library. The module can be installed with ``pip install\ncapstone``.\n\nExample: Multiply two numbers\n-----------------------------\n\nIn this example, we use ``with``-blocks so that the GNU Lightning environment\n(along with the ``mul`` function) is reclaimed::\n\n from lyn import Lightning, word_t, Register\n\n with Lightning() as lib:\n with lib.state() as jit:\n jit.prolog()\n jit.getarg(Register.r0, jit.arg())\n jit.getarg(Register.r1, jit.arg())\n jit.mulr(Register.r0, Register.r0, Register.r1)\n jit.retr(Register.r0)\n jit.epilog()\n\n mul = jit.emit_function(word_t, [word_t, word_t])\n\n for a in xrange(-100, 100):\n for b in xrange(-100, 100):\n assert(mul(a,b) == a*b)\n\nTo use the ``mul`` function elsewhere in your program, you need to keep a\nreference to the state ``jit`` and the GNU Lightning environment ``lib``. Both\nobjects have ``release()`` methods for doing it manually::\n\n lib = Lightning()\n jit = lib.state()\n # ...\n jit.release()\n lib.release()\n\nThe last two parts are order dependant, in that ``lib.release()`` must run\nafter its associated states. If you *don't* release them, it's not a big deal,\nbut you'll waste memory. In such a case, OS will free up the memory at exit.\n\nExample: Calling a C function\n-----------------------------\n\nThis example shows how to call C functions from GNU Lightning. In the example\nbelow, we create a function that takes a string argument and returns the result\nof passing it to ``strlen``::\n\n import lyn\n from lyn import Register, Lightning\n\n lightning = Lightning()\n libc = lightning.load(\"c\")\n\n jit = lightning.state()\n jit.prolog()\n\n # Get the Python argument\n jit.getarg(Register.r0, jit.arg())\n\n # Call strlen with it\n jit.pushargr(Register.r0)\n jit.finishi(libc.strlen)\n\n # Return strlen's return value\n jit.retval(Register.r0)\n jit.retr(Register.r0)\n jit.epilog()\n\n strlen = jit.emit_function(lyn.word_t, [lyn.char_p])\n\n self.assertEqual(strlen(\"\"), 0)\n self.assertEqual(strlen(\"h\"), 1)\n self.assertEqual(strlen(\"he\"), 2)\n self.assertEqual(strlen(\"hello\"), 5)\n\n lightning.release()\n\nNotice that we tell ``emit_function`` to create a function that returns a\n``lyn.word_t``. This is a datatype whose size equals the computer's pointer\nwidth, or ``sizeof(void*)``. ``lyn.word_t`` will then be either\n``ctypes.c_int64`` or ``ctypes.c_int32``.\n\nThe parameter type ``lyn.char_p`` is a subclass of ``ctypes.c_char_p`` that\nautomatically converts strings to ``bytes`` objects. This is provided as a\ncompatibility convenience for Python 2 and 3 users. Use this type instead of\n``ctypes.c_char_p``.\n\nExample: Disassembling native code with Capstone\n------------------------------------------------\n\nIf you install Capstone, you can use it as a disassembler for the generated\nfunctions. At some point, I'll integrate Capstone into Lyn::\n\n from lyn import Lightning, Register, word_t\n import capstone\n import ctypes\n\n lib = Lightning()\n jit = lib.state()\n\n # A function that returns one more than its integer input\n start = jit.note()\n jit.prolog()\n arg = jit.arg()\n jit.getarg(Register.r0, arg)\n jit.addi(Register.r0, Register.r0, 1)\n jit.retr(Register.r0)\n jit.epilog()\n end = jit.note()\n\n # Bind function to Python: returns a word (native integer), takes a word.\n incr = jit.emit_function(word_t, [word_t])\n\n # Sanity check\n assert(incr(1234) == 1235)\n\n # This part should be obvious to C programmers: We need to read data from raw\n # memory in to a Python iterable.\n length = (jit.address(end) - jit.address(start)).value\n codebuf = ctypes.create_string_buffer(length)\n ctypes.memmove(codebuf, ctypes.c_char_p(incr.address.value), length)\n print(\"Compiled %d bytes starting at 0x%x\" % (length, incr.address))\n\n def hexbytes(b):\n return \"\".join(map(lambda x: hex(x)[2:] + \" \", b))\n\n # Capstone is smart enough to stop at the first RET-like instruction.\n md = capstone.Cs(capstone.CS_ARCH_X86, capstone.CS_MODE_64)\n md.syntax = capstone.CS_OPT_SYNTAX_ATT # Change to Intel syntax if you want\n for i in md.disasm(codebuf, incr.address.value):\n print(\"0x%x %-15s%s %s\" % (i.address, hexbytes(i.bytes), i.mnemonic, i.op_str))\n\n raw = \"\".join(map(lambda x: \"\\\\x%02x\" % x, map(ord, codebuf)))\n print(\"\\nRaw bytes: %s\" % raw)\n\n jit.release()\n lib.release()\n\nOn my computer, this outputs::\n\n Compiled 34 bytes starting at 0x105ed3000\n 0x105ed3000 48 83 ec 30 subq $0x30, %rsp\n 0x105ed3004 48 89 2c 24 movq %rbp, (%rsp)\n 0x105ed3008 48 89 e5 movq %rsp, %rbp\n 0x105ed300b 48 83 ec 18 subq $0x18, %rsp\n 0x105ed300f 48 89 f8 movq %rdi, %rax\n 0x105ed3012 48 83 c0 1 addq $1, %rax\n 0x105ed3016 48 89 ec movq %rbp, %rsp\n 0x105ed3019 48 8b 2c 24 movq (%rsp), %rbp\n 0x105ed301d 48 83 c4 30 addq $0x30, %rsp\n 0x105ed3021 c3 retq\n\n Raw bytes:\n \\x48\\x83\\xec\\x30\\x48\\x89\\x2c\\x24\n \\x48\\x89\\xe5\\x48\\x83\\xec\\x18\\x48\n \\x89\\xf8\\x48\\x83\\xc0\\x01\\x48\\x89\n \\xec\\x48\\x8b\\x2c\\x24\\x48\\x83\\xc4\n \\x30\\xc3\n\nCapstone has a lot of neat features. I happen to favour AT&T assembly syntax,\nbut you can easily change that in the above code. But if you set ``md.detail =\nTrue``, you'll be able to see implicit registers and a lot of other cool stuff.\n\nAuthor and license\n------------------\n\nCopyright (C) 2015 Christian Stigen Larsen\n\nDistributed under the LGPL v2.1 or later. You are allowed to change the license\non a particular copy to the LGPL v3.0, the GPL v2.0 or the GPL v3.0.", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/cslarsen/lyn/tarball/v0.0.6", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/cslarsen/lyn", "keywords": "jit,compilation,bytecode,assembly,just-in-time,compiler,machine code,native code,speed", "license": "https://www.gnu.org/licenses/lgpl-2.1.html", "maintainer": null, "maintainer_email": null, "name": "lyn", "package_url": "https://pypi.org/project/lyn/", "platform": "unix,linux,osx,cygwin,win32", "project_url": "https://pypi.org/project/lyn/", "project_urls": { "Download": "https://github.com/cslarsen/lyn/tarball/v0.0.6", "Homepage": "https://github.com/cslarsen/lyn" }, "release_url": "https://pypi.org/project/lyn/0.0.6/", "requires_dist": [ "enum34", "six" ], "requires_python": null, "summary": "Python bindings for GNU Lightning JIT", "version": "0.0.6" }, "last_serial": 1695313, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "87be0cc4c3b9d261a79a13d528243d36", "sha256": "f3acf0c70f1e989472d6fe7a021e5b3993d029d4199a9f670f9b81a9aae9bc1e" }, "downloads": -1, "filename": "lyn-0.0.1-py2.py3-none-any.whl", "has_sig": true, "md5_digest": "87be0cc4c3b9d261a79a13d528243d36", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 9363, "upload_time": "2015-08-22T20:21:47", "url": "https://files.pythonhosted.org/packages/7a/f7/6240e020d6972249769377a8eb628fb9fa721ad2042450d846492214bb84/lyn-0.0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "afba9a8473d84dc546b7dad79d65f52d", "sha256": "654c38bb7ee26401a5eee3d820235ed37ab9051eadb7fcc31d0fbe3f376bd603" }, "downloads": -1, "filename": "lyn-0.0.1.tar.gz", "has_sig": true, "md5_digest": "afba9a8473d84dc546b7dad79d65f52d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15921, "upload_time": "2015-08-22T20:21:17", "url": "https://files.pythonhosted.org/packages/07/48/1269faa8205b6349dfb8de1fb5b3ef08f4c2b76ee169ea31755b6e4ca2c8/lyn-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "d0216dab0bd94b3073bb36068e3c00bf", "sha256": "54aa71cddb8d6f02fae82fffc98224654e2f56d296aacdcb05ff47f9fee5ec3f" }, "downloads": -1, "filename": "lyn-0.0.2-py2.py3-none-any.whl", "has_sig": true, "md5_digest": "d0216dab0bd94b3073bb36068e3c00bf", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 9361, "upload_time": "2015-08-22T20:24:02", "url": "https://files.pythonhosted.org/packages/fc/f0/02f4042e5ad93aca1fdd1abee433591f25c8033403872539ddffa432d755/lyn-0.0.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "1c59ff8d01b9c19d8b350d1621bfd986", "sha256": "733ef67b352f756c344561d0519c548e69e3900e1d16ae6d3e88b03c17bdb698" }, "downloads": -1, "filename": "lyn-0.0.2.tar.gz", "has_sig": true, "md5_digest": "1c59ff8d01b9c19d8b350d1621bfd986", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15925, "upload_time": "2015-08-22T20:24:11", "url": "https://files.pythonhosted.org/packages/49/34/0bc95d89ca33861e5ce5c2f470b698398ed96388e8818f77d456918dcf41/lyn-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "b64a67e3d19b2d74648172b9bc0de258", "sha256": "7b1e3bb8c5baba42d9ccdfae8c9cae6cb209f40f10d119134ac84f7049bdb530" }, "downloads": -1, "filename": "lyn-0.0.3-py2.py3-none-any.whl", "has_sig": true, "md5_digest": "b64a67e3d19b2d74648172b9bc0de258", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 9017, "upload_time": "2015-08-22T20:37:41", "url": "https://files.pythonhosted.org/packages/75/01/1757fb6ee6ef384354d162c62b74be254d9dd75f34f6a47b0e1f6c69f015/lyn-0.0.3-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "4443c534075e01fb3fe6c79e128aed66", "sha256": "b0a4be189e74b9fc25b55386fab72900a73a3f0bd46ce0aed4409615ade35cb4" }, "downloads": -1, "filename": "lyn-0.0.3.tar.gz", "has_sig": true, "md5_digest": "4443c534075e01fb3fe6c79e128aed66", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15758, "upload_time": "2015-08-22T20:37:45", "url": "https://files.pythonhosted.org/packages/f8/95/e9bbf8220df232a2a1ad8f026cdd02b746178eba6b7438cb80e2fd4fb368/lyn-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "3ebaff71d994e27740dfddb3c688a402", "sha256": "accb6407a6ce3b5147f93b2cd29afebca262931f767578ba9abd253c7e44a8d8" }, "downloads": -1, "filename": "lyn-0.0.4-py2.py3-none-any.whl", "has_sig": true, "md5_digest": "3ebaff71d994e27740dfddb3c688a402", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 12228, "upload_time": "2015-08-23T22:14:52", "url": "https://files.pythonhosted.org/packages/9a/da/6b89623375ae52d8c692891ebe73738e14a417bc9d40ce03e2063cae9860/lyn-0.0.4-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7264be668fb372875e5ccf6710d1e657", "sha256": "d41fd68150c4c68ee54c51ecce7c5d62f96a65a4d98180da50e0c56fc970a89a" }, "downloads": -1, "filename": "lyn-0.0.4.tar.gz", "has_sig": true, "md5_digest": "7264be668fb372875e5ccf6710d1e657", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18582, "upload_time": "2015-08-23T22:14:56", "url": "https://files.pythonhosted.org/packages/c7/65/dc6b5efb99272b297f81bdb086c44d3f259f063ab55bbc60e137a238082d/lyn-0.0.4.tar.gz" } ], "0.0.5": [ { "comment_text": "", "digests": { "md5": "62df3728f1dcfd09bb9ff05f389c4228", "sha256": "f7da48614f0cab7ce0e4b47e184b8b7af1ead494f85344548c99052ae17b9fe6" }, "downloads": -1, "filename": "lyn-0.0.5-py2.py3-none-any.whl", "has_sig": true, "md5_digest": "62df3728f1dcfd09bb9ff05f389c4228", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 13649, "upload_time": "2015-08-25T22:16:08", "url": "https://files.pythonhosted.org/packages/9d/dd/11f7592a7d32062d019454494fd8da56e9d44f170a8e2bfe7a3d9178dde4/lyn-0.0.5-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c4321f9a892579c17f609c5f636ef89e", "sha256": "cd706c68ac470655795243df08a4b5a49d469ff1c3a3d94b0ba3cab638260721" }, "downloads": -1, "filename": "lyn-0.0.5.tar.gz", "has_sig": true, "md5_digest": "c4321f9a892579c17f609c5f636ef89e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19559, "upload_time": "2015-08-25T22:16:14", "url": "https://files.pythonhosted.org/packages/bb/79/d2d4addbbb4bb6da6498d1eddf27c420e750778e057572f880d3b9dbee2f/lyn-0.0.5.tar.gz" } ], "0.0.6": [ { "comment_text": "", "digests": { "md5": "3a0caf8d96f4de7fb41c6e039847dd7d", "sha256": "ddfae87688014c381ebb020b872f8a5b9696a2c77bee11c755bf32c09f1b3d3a" }, "downloads": -1, "filename": "lyn-0.0.6-py2.py3-none-any.whl", "has_sig": true, "md5_digest": "3a0caf8d96f4de7fb41c6e039847dd7d", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 15608, "upload_time": "2015-08-26T20:39:20", "url": "https://files.pythonhosted.org/packages/44/27/9674ffe4ec66eb0eea061ce61855985d0033662ed316690434102639aea3/lyn-0.0.6-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6cd8e3564aef26b4a623cce2a9d5c0de", "sha256": "7369e70df62ceeb26f9c6a669b367c6a4150d9c94519295f705c92a1faa62da6" }, "downloads": -1, "filename": "lyn-0.0.6.tar.gz", "has_sig": true, "md5_digest": "6cd8e3564aef26b4a623cce2a9d5c0de", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 21204, "upload_time": "2015-08-26T20:39:24", "url": "https://files.pythonhosted.org/packages/86/19/04ee7160db8113580c8f2e2c4ec327ea75b199f9a201e48b595e81fe1cc2/lyn-0.0.6.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "3a0caf8d96f4de7fb41c6e039847dd7d", "sha256": "ddfae87688014c381ebb020b872f8a5b9696a2c77bee11c755bf32c09f1b3d3a" }, "downloads": -1, "filename": "lyn-0.0.6-py2.py3-none-any.whl", "has_sig": true, "md5_digest": "3a0caf8d96f4de7fb41c6e039847dd7d", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 15608, "upload_time": "2015-08-26T20:39:20", "url": "https://files.pythonhosted.org/packages/44/27/9674ffe4ec66eb0eea061ce61855985d0033662ed316690434102639aea3/lyn-0.0.6-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6cd8e3564aef26b4a623cce2a9d5c0de", "sha256": "7369e70df62ceeb26f9c6a669b367c6a4150d9c94519295f705c92a1faa62da6" }, "downloads": -1, "filename": "lyn-0.0.6.tar.gz", "has_sig": true, "md5_digest": "6cd8e3564aef26b4a623cce2a9d5c0de", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 21204, "upload_time": "2015-08-26T20:39:24", "url": "https://files.pythonhosted.org/packages/86/19/04ee7160db8113580c8f2e2c4ec327ea75b199f9a201e48b595e81fe1cc2/lyn-0.0.6.tar.gz" } ] }