Skip to content

dnaproject2/dna-compiler-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Neptune

Python compiler for DNA

Build Status

Overview

Neptune is a tool for compiling Python files to the .avm format for usage in smart contracts on the DNA blockchain. It currently only supports a subset of the Python language.

What does it currently do

  • Compiles a subset of the Python language to the .avm format for use in the DNA blockchain
  • Works for Python 3.6+

What will it do

  • Compile a larger subset of the Python language
  • Additional syntax checks
  • Optimize instr stream

What's new compared to neo-boa

Installation

Installation requires Python version 3.6 or later.

Setup

Clone the repository and navigate into the project directory. Make a Python 3 virtual environment and activate it via:

python3 -m venv venv
source venv/bin/activate

Then, install the requirements:

pip install -r requirements.txt

Usage

Import the compiler into a file with:

from dna.compiler import Compiler

The compiler can be used in three different ways:

  1. Compiling a python file to a new file
# Compiles the python file and creates an avm in 'path/to/your/file.avm'.
compiler = Compiler.Compile('path/to/your/file.py')
  1. Compiling a python file to .avm
# Compiles the python file and returns an avm.
avm = Compiler.Compile_File('path/to/your/file.py')
  1. Compiling a variable to .avm
# Compiles a contract stored in memory and returns an avm.
avm = Compiler.Compile_Contract('def Main(operation, args): ...')

You can also print out the instr instream:

compiler.DumpAsm()

Testing

You can run the tests using the runall.bash or runall-testing.bash files located in dna_test. You can run the compiler tests using the compile-avm-test.py file in the root directory.

DebugInfo

FuncName: indicate the opcode blongs to which function. Global#Code is for Code in Global.

Lineno: indicate the opcode blongs to which line number in source code.

Col : indicate the opcode blongs to which columns in source code.

offset: the address of Opcode. from 0 to len of avm.

Opcode: the Opcode.

JumpTarget: the target address(offset) of jump instruct.

TargetOff: the relative offset between target address and current jump instruction.

FuncName                       Lineno     Col   Offset     OpCode               JumpTarget           TargetOff           
Global#Code                    1          0     0          PUSH2               
Global#Code                    1          0     1          NEWARRAY            
Global#Code                    1          0     2          TOALTSTACK          
Global#Code                    1          14    3          PUSHBYTES5          
Global#Code                    1          0     9          DUPFROMALTSTACK     
Global#Code                    1          0     10         PUSH0               
Global#Code                    1          0     11         PUSH2               
Global#Code                    1          0     12         ROLL                
Global#Code                    1          0     13         SETITEM             
Global#Code                    3          4     14         PUSH2               
Global#Code                    3          0     15         DUPFROMALTSTACK     
Global#Code                    3          0     16         PUSH1               
Global#Code                    3          0     17         PUSH2               
Global#Code                    3          0     18         ROLL                
Global#Code                    3          0     19         SETITEM             
Global#Code                    4          0     20         FROMALTSTACK        
Main                           4          0     21         PUSH3               
Main                           4          0     22         NEWARRAY            
Main                           4          0     23         TOALTSTACK          
Main                           4          0     24         DUPFROMALTSTACK     
Main                           4          0     25         PUSH0               
Main                           4          0     26         PUSH2               
Main                           4          0     27         ROLL                
Main                           4          0     28         SETITEM             
Main                           5          8     29         PUSH0               
Main                           5          4     30         DUPFROMALTSTACK     
Main                           5          4     31         PUSH1               
Main                           5          4     32         PUSH2               
Main                           5          4     33         ROLL                
Main                           5          4     34         SETITEM             
Main                           6          8     35         DUPFROMALTSTACK     
Main                           6          8     36         PUSH0               
Main                           6          8     37         PICKITEM            
Main                           6          8     38         CALL                 49                   11    

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages