Coder Social home page Coder Social logo

ontology-python-compiler's Introduction

Neptune

Python compiler for Ontology

Overview

Neptune is a tool for compiling Python files to the .avm format for usage in smart contracts on the Ontology 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 Ontology 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

The compiler may be used like in the following example:

from ontology.compiler import Compiler

# Compiles the python file and creates an avm in 'path/to/your/file.avm'.
compiler = Compiler.Compile('path/to/your/file.py')

# dump the instr instream.
compiler.DumpAsm()

Testing

You can run the tests using the runall.bash or runall-testing.bash files located in ontology_test.

Contributing

Contributors are welcome to the ontology-python-compiler. Before beginning, please take a look at our contributing guidelines. You can open an issue by clicking here.

If you have any issues getting setup, open an issue or reach out in the Ontology Discord.

License

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    

ontology-python-compiler's People

Contributors

carltraveler avatar wyattmufson avatar jasonzhoupw avatar laizy avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.