boa.compiler.Compiler

What follows are the details of the Compiler implementation.

class boa.compiler.Compiler[source]

The main compiler interface class.

The following loads a python file, compiles it to the .avm format and saves it alongside the python file.

from boa.compiler import Compiler
Compiler.load_and_save('path/to/your/file.py')

# return the compiler object for inspection
compiler = Compiler.load('path/to/your/file.py')

# retrieve the default module for inpection
default_module = compiler.default

# retreive the default/entry method for the smart contract
entry_method = default_module.main
default

Retrieve the default or ‘entry’ module.

Returns:the default boa.code.Module object or None upon exception
static instance()[source]

Retrieve the current instance of the Compiler object, if it exists, or create one.

Returns:the singleton instance of the Compiler object
static load(path, use_nep8=True)[source]

Call load to load a Python file to be compiled but not to write to .avm

Parameters:path – the path of the Python file to compile
Returns:The instance of the compiler

The following returns the compiler object for inspection.

from boa.compiler import Compiler

compiler = Compiler.load('path/to/your/file.py')
static load_and_save(path, output_path=None, use_nep8=True)[source]

Call load_and_save to load a Python file to be compiled to the .avm format and save the result. By default, the resultant .avm file is saved along side the source file.

Parameters:
  • path – The path of the Python file to compile
  • output_path – Optional path to save the compiled .avm file
Returns:

the instance of the compiler

The following returns the compiler object for inspection

from boa.compiler import Compiler

Compiler.load_and_save('path/to/your/file.py')
write()[source]

Write the default module to a byte string.

Returns:the compiled Python program as a byte string
Return type:bytes
static write_file(data, path)[source]

Save the output data to the file system at the specified path.

Parameters:
  • data – a byte string of data to write to disk
  • path – the path to write the file to