Ontology Neptune Released: Python Smart Contract Compiler for Developers

The Ontology Team
OntologyNetwork
Published in
3 min readJan 9, 2019

Ontology is dedicated to creating a collaborative open-source tech community. This requires constantly improving development tools and support to give developers easy access to decentralized technology.

We are excited to announce the release of Ontology Neptune, the new Python Compiler, which includes more syntax features and precise syntax checking while maintaining Python semantics, enabling developers to harness the power of smart contracts.

If you are a developer, make sure you have joined our Discord, there you can interact with Ontology core team developers and community developers. Also, take a look at the Developer Center on our website, there you can find developer tools, documentation, and more.

You can find Ontology Neptune on our Github.

Compiler features

  1. Rewrite the compilation framework to implement a compilation process based on an abstract syntax tree.
  2. Keywords like break and continue are supported and can be used in any nested loop.
  3. Support for logical operations while keeping Python semantics.
    e.g. if a == 2 or (a == 5 and b == 4) or a == 3 and a == 7
  4. Support for keywords like while, for, and loop else.
  5. Support for in keyword. You can use a statement in the form of if a in list.
  6. Support to write as many statements as you like on a single line.
  7. Global variables can have dependency assignments.
    e.g. a = 10; b = a
  8. Support for cascading comparisons while keeping Python semantics.
    e.g. if a < b < c < d >= e:
    a = 1
  9. Support for cascading assignments.
    e.g. a = b = c = 9
  10. Support for conditional expressions.
    e.g. c = a if x > 3 else b
  11. Map value content and nesting levels are unrestricted and can take many forms, such as list, map, function, and call.
  12. String slice supports string[ :], string[ : end], and string[start: ].
  13. Support for list comprehensions.
  14. Support for keyword assert.
  15. More strict function definition checks. Functions can be customized and imported, and any other function calls will report undefined errors. System calls and built-in functions both need to be imported.
  16. More syntax checking, such as number of function parameter, number mismatch, function redefinition and undefined variable, and so on. More precise syntax information for printing errors.
    For details of supported built-ins, please refer to builtins.py.
  17. Implement a series of commonly used library functions
    int, str, bytes2hexstring, hexstring2bytes, bytearray_reverse, split, list_remove_elt, elt_in
    Please see the function and implementation in libont.py.
  18. Will support dict’s has_key, values, keys functions, and list remove function. Also, restore the semantics of global code (supports global writable variables, implementing cross-function shared variables).
  19. More in line with Python syntax, supporting more grammatical features.

Compiler Design Framework

  1. Start with Compile Start and drive the entire build process with the Code Generate Driver. The decomposition of the process makes the code framework clearer and more logical, avoiding bugs in the version’s iteration process.
  2. Analyze Python source code to get Abstract Syntax Tree (AST).
  3. Using AST, obtain the function declaration, process the imported module, and analyze the function classification features, including user-defined functions (user defined), library functions (lib), built-in functions (builtins), system calls (systemcall), entry functions (Main/main), and find regular syntax errors such as function redefinition.
  4. Translate Python global code.
  5. Determine the stack size of the function.
  6. Determine if the function has a return value. The Compiler specifies that the function with the return value must be assigned to a variable to avoid disrupting the stack structure.
  7. Compiled function body
  8. All offsets can be determined only after all source code has been compiled. This version of the Compiler has reserved relocation space and corresponding label address, and the last step executes link work.
  9. Compile completed, print the instruction stream according to the option.

Are you a developer? Make sure you have joined our tech community on Discord. Also, take a look at the Developer Center on our website, there you can find developer tools, documentation, and more.

--

--