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

It must be possible to embed Rust atoms into objects #33

Open
yegor256 opened this issue Nov 18, 2022 · 0 comments
Open

It must be possible to embed Rust atoms into objects #33

yegor256 opened this issue Nov 18, 2022 · 0 comments

Comments

@yegor256
Copy link
Member

yegor256 commented Nov 18, 2022

At the moment, there is only a very limited set of \lambda objects is supported. Let's make it possible to have Rust atoms, specified according to the notation of SODG. Each atom will communicate with phie through the SODG graph API. We should implement here a bridge between SODG and our internal representation of objects/baskets.

The source program may look like this:

[] > app
  sum > @
    4
    8
  [a b] > sum
    rust > @
      """
      pub fn f(mut& uni: Universe, v: u32) -> u32 {
        let a = uni.dataize("v{v}.𝛼0")?.as_i64()?;
        let b = uni.dataize("v{v}.𝛼1")?.as_i64()?;
        let v = uni.add(uni.next_id())?;
        uni.put(v, a + b)?;
        return v;
      }
      """

It will be translated to XMIR by eo-parser. Then, it will be passed through a number of optimizers. In the end, we will have something like this:

<program>
  <objects>
    <o name="app">
      <!-- ... -->
    </o>
    <o name="app$sum">
      <o name="@" base="org.eolang.rust">
        <o base="org.eolang.string">
          let a = uni.dataize("$.𝛼0")?.as_i64()?;
          let b = uni.dataize("$.𝛼1")?.as_i64()?;
          let v = uni.add(uni.next_id())?;
          uni.put(v, a + b)?;
          return v;
        </o>
      </o>
    </o>
  </objects>
</program>

Then, phie takes a directory with such XMIR files, and starts. First, it converts XMIR to something like this (pay attention to 547483.rs):

ν0(𝜋) ↦ ⟦ 𝜑 ↦ ν3(𝜋) ⟧
ν1(𝜋) ↦ ⟦ Δ ↦ 0x002A ⟧
ν2(𝜋) ↦ ⟦ λ ↦ "547483.rs", ρ ↦ 𝜋.𝛼0, 𝛼0 ↦ 𝜋.𝛼1 ⟧
ν3(𝜋) ↦ ⟦ 𝜑 ↦ ν2(ξ), 𝛼0 ↦ ν1(𝜋), 𝛼1 ↦ ν1(𝜋) ⟧
ν5(𝜋) ↦ ⟦ 𝜑 ↦ ν3(ξ) ⟧

Then, it puts Rust code to 547483.rs file, adds cargo.toml, and compiles all together. It gets 547483.so -- a binary shared Linux library.

Then, phie in runtime links the shared library and runs the emulation of the entire program.

In order to make Rust snippets to work, we should implement Universe, according to SODG specification.

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

No branches or pull requests

1 participant