gnolang / gno

Gno: An interpreted, stack-based Go virtual machine to build succinct and composable apps + Gno.land: a blockchain for timeless code and fair open-source
https://gno.land/
Other
842 stars 343 forks source link

Improve `gno run` #930

Open moul opened 1 year ago

moul commented 1 year ago

The gno run command is presently in a pre-alpha phase and may not perform reliably due to its specific requirements for package and function naming.

Its primary objective is to facilitate a smooth transition for developers from Go by allowing them to start with a basic main function. Additionally, it aims to provide utility tools for those who are forking or reviewing a package.

To enhance its usability and commence documentation in guides, two primary enhancements are urgently needed:

  1. The inclusion of argument passing support akin to os.Args, enabling more dynamic results from a single main function based on various parameters.
  2. Increased flexibility in the package PKGPATH specification, making it easier to add a main function and execute gno run on a package without having to specify a file (related to issue #768).

Addresses #972

ajnavarro commented 1 year ago

Starting with the implementation of the first enhancement (os.Args).

ajnavarro commented 11 months ago

I refactored the RunMain() method to accept a slice of arguments. Apart from that, I added the os package into the stdlibs gnovm folder.

stdlib is loaded when using VMKeeper but RunMain() is on the Machine struct, so it looks a bit strange that to make Args work, you need to use the VM through the VMKeeper.

I'm having some problems injecting the Args into a var inside a package, waiting for https://github.com/gnolang/gno/pull/859 which should make the process simpler.

If someone has some insights about how to move forward, I'd be willing to chat with you about it.

moul commented 11 months ago

Do you already have a PR for your work? can you share, the link?

ajnavarro commented 11 months ago

@moul I don't. Because I wasn't able to make it work, I just discarded the changes. I can recreate and add them to a draft PR.

moul commented 11 months ago

Yes please, a draft PR may be useful to help you.

ajnavarro commented 11 months ago

@moul This is what I was trying to do: https://github.com/gnolang/gno/pull/982