User referenceΒΆ

User reference for the Pythas package.

The Compiler instance (imported as compiler) and SourceModule constructor are the major constituents of the API. Everything else, all the necessary setup, is executed automatically at import time.

CompilerΒΆ

class pythas.compiler.Compiler(flags=('-O2'))

Interface for the compiler used to create shared libraries.

Parameters

flags (Tuple[str]) – Compile time flags to append. Default value is using the β€œ-O2” flag.

GHC_VERSION

Version number string of the used GHC instance.

Type

str

flags

Flags for compiler.

Type

tuple(str)

stack_usage

Enable the usage of stack for compilation. Will default to False if stack is not available.

Type

bool

add_flag(flag)

Adds a flag to flags.

Parameters

flag (str) – A valid compile time flag.

compile(filename)

Creates an FFI file, compiles and links it against the Python runtime.

Parameters

filename (str) – Pathlike object to a Haskell source file.

Returns

ffi_libs – List of tuples of linked libraries and their respective parsed infos.

Return type

[(ctypes.CDLL, pythas.parser.data.ParseInfo)]

copy()

Creates a new instance of Compiler from an existing one. Flags and stack_usage will be consistent.

Returns

new – The new Compiler instance.

Return type

Compiler

remove_flag(flag)

Removes a flag from flags.

Parameters

flag (str) – A flag contained within flags.

SourceModuleΒΆ

class pythas.compiler.SourceModule(code, compiler=None, use_stack=True, flags=('-O2'))

Module created from inline Haskell source code. Will instantiate its own instance of Compiler unless an alternative is provided. Other settings will not be permanently made in the compiler instance.

Parameters
  • code (str) – The Haskell source code to construct the module from.

  • compiler (Compiler) – Compiler instance to use settings from.

  • use_stack (bool) – Use stack if available. Default value is True.

  • flags (Tuple[str]) – Compile time flags to append. Default value is using the β€œ-O2” flag.