Plutonomicon / pluto

An untyped Plutus Core assembler
32 stars 8 forks source link

More examples please #5

Open blamario opened 2 years ago

blamario commented 2 years ago

A side-by-side example of Plutus output and an equivalent hand-written Pluto expression could go a long way to justify the project.

srid commented 2 years ago

For the record, you can get the UPLC for examples/hello.pluto by running cabal run pluto -- run examples/hello.pluto -v in nix-shell.

For following pluto program,

-- Hello world
let 
  defaultGreeting = "Hello";
  greet = (\greeting name -> 
    (greeting +s ", ") +s name
  )
in 
  greet defaultGreeting "world"

translates to UPLC:

Program
  ()
  (Version () 1 0 0)
  (Apply
     ()
     (LamAbs
        ()
        (DeBruijn {dbnIndex = 0})
        (Apply
           ()
           (LamAbs
              ()
              (DeBruijn {dbnIndex = 0})
              (Apply
                 ()
                 (Apply
                    ()
                    (Var () (DeBruijn {dbnIndex = 2}))
                    (Var () (DeBruijn {dbnIndex = 1})))
                 (Constant () (Some (ValueOf string "world")))))
           (Constant () (Some (ValueOf string "Hello")))))
     (LamAbs
        ()
        (DeBruijn {dbnIndex = 0})
        (LamAbs
           ()
           (DeBruijn {dbnIndex = 0})
           (Apply
              ()
              (Apply
                 ()
                 (Builtin () AppendString)
                 (Apply
                    ()
                    (Apply
                       ()
                       (Builtin () AppendString)
                       (Var () (DeBruijn {dbnIndex = 2})))
                    (Constant () (Some (ValueOf string ", ")))))
              (Var () (DeBruijn {dbnIndex = 1}))))))
blamario commented 2 years ago

The benefit of this comparison is the whole justification for the project, so you want to put it up front. Sure anybody with a Plutus repo clone can get the same output but it takes some effort to produce it and visually compare to the hand-written Pluto expression. Speaking of which, do you plan to write a disassembler?

blamario commented 2 years ago

Never mind the last question, I opened issue #4 about that.