Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a new NIF to support Rust library #10

Open
niamtokik opened this issue Sep 8, 2023 · 1 comment
Open

Create a new NIF to support Rust library #10

niamtokik opened this issue Sep 8, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@niamtokik
Copy link
Owner

niamtokik commented Sep 8, 2023

The current implementation is using libcozo_c, but this library has lot of limitation. Instead of passing a cozoscript query, we should pass a cozo query data-structure, based on Erlang syntax (or from something close to Erlang syntax).

 When invoking cozoscript:parse/1, this code will

  ____________________       ___________________       ___
 |                    |     |                   |     /   |
 | cozoscript:parse/1 |---->| cozo_rust:parse/1 |--->| {ok, bytecode}
 |____________________|     |___________________|    |____|

 The same bytecode can be reinjected into another module
 lie cozo_bytecode:eval/1 to be evaluated and get back the result.
 
   ___      ______________________      __________________
  /   |    |                      |    |                  |
 |  B |--->| cozo_bytecode:eval/1 |--->| cozo_rust:eval/1 |
 |____|    |______________________|    |__________________|
                                                ||
                                               _||_
                                               \  /
                                                \/
                                               ___
                                              /   |
                                             | {ok, Result}
                                             |____|

 In fact, by using this strategy, we don't modify the current
 structure of cozo application.

                           ______________________
                          |                      |
                     +--->| cozo_nif:run_query/4 |-->Result
  ______________     |    |______________________|
 |              |    |
 | cozo:query/3 |---(+)
 |______________|  / |     ___________________     __________________
                  /  |    |                   |   |                  |
                 /   +--->| cozo_rust:parse/1 |-->| cozo_rust:eval/1 |-->Result
 [based on params]        |___________________|   |__________________|

Cozo Rust Interfaces

A cozo core example can be seen in cozo bin source (REPL and server).

Cozoscript to Cozo bytecode

  1. send a cozoscript to cozo parser
  2. instead of returning a json get the cozo bytecode (or an error)

Erlang Terms to Cozo bytecode

  1. identify and understand cozo bytecode generated from cozoscript and based on source code
  2. select adequate Erlang Terms to be use as equivalent to cozo bytecode
  3. create an erlang terms to cozo bytecode compiler

Cozo bytecode to Erlang Terms

  1. based on previous translation, convert cozo bytecode to Erlang terms

Erlang interfaces

  1. Create a new interface using Erlang Terms instead of cozoscript

Resources

@niamtokik niamtokik added the enhancement New feature or request label Sep 8, 2023
@niamtokik
Copy link
Owner Author

At this time, Rustler is not compatible with Erlang for many reasons but rebar3_rust is based on ecozodb project. I need to fork official cozodb project in my own space to inject some code and export data-structures and functions, modification will be done here for the moment: https://github.com/niamtokik/cozodb/tree/test/public-export-before-creating-custom-module

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

1 participant