Skip to main content

Python bindings for GNU Lightning JIT

Project description

_Lyn_ provides Python bindings for GNU Lightning, the light-weight just-in-time compiler that translates RISC instructions to native machine code.

The bindings are made through ctypes, so all of the Lyn source code is in pure Python: All you need is liblightning.so/dylib/dll!

“Lyn” is the Norwegian word for “lightning”.

NOTE: This project is currently in extremely early stages (hours in!)

Status

As mentioned above, Lyn is fledgling: I’ve just spent a few hours on it, so almost nothing is supported and — in particular — I’ve only targeted x86-64 opcodes just yet.

In spite of this, I’ve managed to create a really simple program in Python that is JIT-compiled to native x86-64 machine code: A glorious function that returns the value of 123! Here’s the code:

#!/usr/bin/env python

from lyn import *

lib = Lightning()

with lib.state() as jit:
    jit.prolog()

    # The actual code
    jit.movi(Register.V0, 123)
    jit.retr(Register.V0)

    function = jit.emit_function()
    print("Should get 123 here: %s" % function())

I’m using ctypes for creating the bindings, which comes with some challenges: GNU Lightning is written in C, and relies heavily on compile-time macros that define machine specific opcodes, register values and so on. Because of this, it would be more natural to simply create bindings through a C extension. On the other hand, though, ctypes makes it possible to ship Lyn as a platform independent, pure Python source. I’ll chew on this for a while, and we’ll see what happens.

Requirements

You need GNU Lightning. Lyn was made specifically for version 2.1.0, but may also work on later versions. It currently does not support earlier versions.

To download and install GNU Lightning, see

http://www.gnu.org/software/lightning/

Since Lyn loads Lightning using the ctypes foreign-function interface, you will most likely need to build a shared library. To do that, configure Lightning with --enable-shared.

If you want to be able to disassemble your compiled code, you also need GNU Binutils, along with a --enable-disassembler option to GNU Lightning’s configure. Consult its documentation for more information.

Author and license

Copyright (C) 2015 Christian Stigen Larsen

Distributed under the LGPL v2.1 or later. You are allowed to change the license on a particular copy to the LGPL v3.0, the GPL v2.0 or the GPL v3.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lyn-0.0.2.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

lyn-0.0.2-py2.py3-none-any.whl (9.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file lyn-0.0.2.tar.gz.

File metadata

  • Download URL: lyn-0.0.2.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for lyn-0.0.2.tar.gz
Algorithm Hash digest
SHA256 733ef67b352f756c344561d0519c548e69e3900e1d16ae6d3e88b03c17bdb698
MD5 1c59ff8d01b9c19d8b350d1621bfd986
BLAKE2b-256 49340bc95d89ca33861e5ce5c2f470b698398ed96388e8818f77d456918dcf41

See more details on using hashes here.

File details

Details for the file lyn-0.0.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for lyn-0.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 54aa71cddb8d6f02fae82fffc98224654e2f56d296aacdcb05ff47f9fee5ec3f
MD5 d0216dab0bd94b3073bb36068e3c00bf
BLAKE2b-256 fcf002f4042e5ad93aca1fdd1abee433591f25c8033403872539ddffa432d755

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page