aeternity / aesophia

Stand alone compiler for the Sophia smart contract language
https://docs.aeternity.com/aesophia
ISC License
51 stars 19 forks source link

Return mapping from variables to registers in fate compilation #411

Closed ghallak closed 1 year ago

ghallak commented 2 years ago

This PR will change the result of the compilation to include a mapping from variables to fate registers.

Code example:

contract X =
  function g(z) =
    let g = 1
    g + z

  entrypoint f() =
    let g = g(5)
    let h = g + 2
    h + h

main contract C =
  entrypoint f(x) =
    let x = x + x
    let y = x + x
    let x = y + y
    x + x

  entrypoint g() =
    let x = 3
    x + x

  entrypoint q(x) =
    x + 1

  stateful entrypoint xz() =
    let aa : X = Chain.create()
    aa.f()

Registers in the compilation result:

variables_registers =>
 #{{"C","f","x"} => {var,2},
   {"C","f","y"} => {var,1},
   {"C","g","x"} => {var,0},
   {"C","q","x"} => {arg,0},
   {"C","x","a"} => {var,0},
   {"X",".X.g","g"} => {var,0},
   {"X",".X.g","z"} => {arg,0},
   {"X","f","g"} => {var,0},
   {"X","f","h"} => {var,1}},
ghallak commented 1 year ago

@radrow Notice how the local function X.g is called .X.g. I'm using an existing function (aeso_fcode_to_fate:make_function_name/1) to get the functions names. I don't think we need this distinction in the names between local function and entrypoints. Should it just be called g instead of .X.g?

radrow commented 1 year ago

Yes, let's make it just g. I think you can hack it around by calling that make name with the env set to entrypoint/nonprivate or something like that

ghallak commented 1 year ago

I have made the change here f0db4fb96b9b6edcada96291d656a45c3eb1b924 and here is how the new output looks like:

variables_registers =>
 #{{"C","f","x"} => {var,2},
   {"C","f","y"} => {var,1},
   {"C","g","x"} => {var,0},
   {"C","q","x"} => {arg,0},
   {"C","x","a"} => {var,0},
   {"X","f","g"} => {var,0},
   {"X","f","h"} => {var,1},
   {"X","g","g"} => {var,0},
   {"X","g","z"} => {arg,0}}
ghallak commented 1 year ago

@hanssv I have added a compiler option that enables/disables the returning of the newly introduced map here ee37e187e892c32303370919ee048a21ec18e25f.