From 85f62bad851e4cfdd167c14fde4539e08dac01a0 Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Thu, 22 Feb 2024 14:09:15 +0100 Subject: [PATCH 1/3] refactor(gnovm): rename precompiler to transpiler, move to own package --- PLAN.md | 2 +- docs/gno-tooling/cli/gno.md | 6 +- docs/reference/go-gno-compatibility.md | 2 +- examples/Makefile | 10 +-- gno.land/pkg/gnoclient/client_txs.go | 8 +- gno.land/pkg/keyscli/addpkg.go | 5 +- gno.land/pkg/keyscli/run.go | 5 +- gnovm/cmd/gno/README.md | 2 +- gnovm/cmd/gno/lint_test.go | 2 +- gnovm/cmd/gno/main.go | 2 +- gnovm/cmd/gno/precompile.go | 90 +++++++++---------- gnovm/cmd/gno/precompile_test.go | 4 +- gnovm/cmd/gno/test.go | 23 ++--- .../testdata/gno_precompile/01_no_args.txtar | 6 +- .../gno_precompile/02_empty_dir.txtar | 4 +- .../03_gno_files_parse_error.txtar | 6 +- .../gno_precompile/04_valid_gno_files.txtar | 4 +- .../gno_precompile/05_skip_fmt_flag.txtar | 6 +- .../gno_precompile/06_build_flag.txtar | 4 +- .../07_build_flag_with_build_error.txtar | 6 +- .../08_build_flag_with_parse_error.txtar | 4 +- .../09_gno_files_whitelist_error.txtar | 6 +- .../gno/testdata/gno_test/empty_gno1.txtar | 2 +- .../gno/testdata/gno_test/empty_gno2.txtar | 2 +- .../gno/testdata/gno_test/empty_gno3.txtar | 2 +- .../testdata/gno_test/failing_filetest.txtar | 2 +- .../gno/testdata/gno_test/failing_test.txtar | 2 +- gnovm/cmd/gno/util.go | 10 +-- gnovm/pkg/gnolang/realm.go | 13 +-- .../transpiler.go} | 44 ++++----- .../transpiler_test.go} | 8 +- gnovm/pkg/gnomod/file.go | 8 +- gnovm/pkg/gnomod/gnomod.go | 25 +++--- 33 files changed, 165 insertions(+), 160 deletions(-) rename gnovm/pkg/gnolang/{precompile.go => transpiler/transpiler.go} (87%) rename gnovm/pkg/gnolang/{precompile_test.go => transpiler/transpiler_test.go} (96%) diff --git a/PLAN.md b/PLAN.md index dfcae264727..138eee35bb8 100644 --- a/PLAN.md +++ b/PLAN.md @@ -16,7 +16,7 @@ the Discord server. ### Gnolang * Get basic Go tests working _COMPLETE_ -* Implement minimal toolsuite (precompile, gnodev) +* Implement minimal toolsuite (transpile, gnodev) * Tweak/enforce gas limitations * Implement flat-as-struct supported * Implement ownership/realm logic; phase 1: no cycles diff --git a/docs/gno-tooling/cli/gno.md b/docs/gno-tooling/cli/gno.md index e72f1414102..5c73a5cee34 100644 --- a/docs/gno-tooling/cli/gno.md +++ b/docs/gno-tooling/cli/gno.md @@ -19,7 +19,7 @@ gno {SUB_COMMAND} | Name | Description | | ------------ | ------------------------------------------ | | `test` | Tests a gno package. | -| `precompile` | Precompiles a `.gno` file to a `.go` file. | +| `transpile` | Transpiles a `.gno` file to a `.go` file. | | `repl` | Starts a GnoVM REPL. | ### `test` @@ -32,9 +32,9 @@ gno {SUB_COMMAND} | `root-dir` | String | Clones location of github.com/gnolang/gno (gno tries to guess it). | | `run` | String | Test name filtering pattern. | | `timeout` | time.Duration | The maximum execution time in ns. | -| `precompile` | Boolean | Precompiles a `.gno` file to a `.go` file before testing. | +| `transpile` | Boolean | Transpiles a `.gno` file to a `.go` file before testing. | -### `precompile` +### `transpile` #### **Options** diff --git a/docs/reference/go-gno-compatibility.md b/docs/reference/go-gno-compatibility.md index 71f46adf836..4b65b6c32ef 100644 --- a/docs/reference/go-gno-compatibility.md +++ b/docs/reference/go-gno-compatibility.md @@ -303,7 +303,7 @@ Legend: | + go mod init | gno mod init | same behavior | | + go mod download | gno mod download | same behavior | | + go mod tidy | gno mod tidy | same behavior | -| | gno precompile | | +| | gno transpile | | | go work | | | | | gno repl | | | go run | gno run | | diff --git a/examples/Makefile b/examples/Makefile index 56ad4b30b42..2fd5c70daf4 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -9,13 +9,13 @@ help: @echo "Available make commands:" @cat Makefile | grep '^[a-z][^:]*:' | cut -d: -f1 | sort | sed 's/^/ /' -.PHONY: precompile -precompile: - go run ../gnovm/cmd/gno precompile --verbose . +.PHONY: transpile +transpile: + go run ../gnovm/cmd/gno transpile --verbose . .PHONY: build -build: precompile - go run ../gnovm/cmd/gno build --verbose . +build: + go run ../gnovm/cmd/gno transpile --verbose --gobuild . .PHONY: test test: diff --git a/gno.land/pkg/gnoclient/client_txs.go b/gno.land/pkg/gnoclient/client_txs.go index 39088bc30d5..34759b565e3 100644 --- a/gno.land/pkg/gnoclient/client_txs.go +++ b/gno.land/pkg/gnoclient/client_txs.go @@ -2,7 +2,7 @@ package gnoclient import ( "github.com/gnolang/gno/gno.land/pkg/sdk/vm" - gno "github.com/gnolang/gno/gnovm/pkg/gnolang" + "github.com/gnolang/gno/gnovm/pkg/gnolang/transpiler" "github.com/gnolang/gno/tm2/pkg/amino" ctypes "github.com/gnolang/gno/tm2/pkg/bft/rpc/core/types" "github.com/gnolang/gno/tm2/pkg/crypto" @@ -208,10 +208,10 @@ func (c *Client) Run(cfg RunCfg) (*ctypes.ResultBroadcastTxCommit, error) { caller := c.Signer.Info().GetAddress() - // precompile and validate syntax - err = gno.PrecompileAndCheckMempkg(memPkg) + // transpile and validate syntax + err = transpiler.TranspileAndCheckMempkg(memPkg) if err != nil { - return nil, errors.Wrap(err, "precompile and check") + return nil, errors.Wrap(err, "transpile and check") } memPkg.Name = "main" memPkg.Path = "" diff --git a/gno.land/pkg/keyscli/addpkg.go b/gno.land/pkg/keyscli/addpkg.go index 1882f6de3d0..82aef1315d4 100644 --- a/gno.land/pkg/keyscli/addpkg.go +++ b/gno.land/pkg/keyscli/addpkg.go @@ -7,6 +7,7 @@ import ( "github.com/gnolang/gno/gno.land/pkg/sdk/vm" gno "github.com/gnolang/gno/gnovm/pkg/gnolang" + "github.com/gnolang/gno/gnovm/pkg/gnolang/transpiler" "github.com/gnolang/gno/tm2/pkg/amino" "github.com/gnolang/gno/tm2/pkg/commands" "github.com/gnolang/gno/tm2/pkg/crypto/keys" @@ -101,8 +102,8 @@ func execMakeAddPkg(cfg *MakeAddPkgCfg, args []string, io commands.IO) error { panic(fmt.Sprintf("found an empty package %q", cfg.PkgPath)) } - // precompile and validate syntax - err = gno.PrecompileAndCheckMempkg(memPkg) + // transpile and validate syntax + err = transpiler.TranspileAndCheckMempkg(memPkg) if err != nil { panic(err) } diff --git a/gno.land/pkg/keyscli/run.go b/gno.land/pkg/keyscli/run.go index 7d329c18566..3dd1879bcfa 100644 --- a/gno.land/pkg/keyscli/run.go +++ b/gno.land/pkg/keyscli/run.go @@ -9,6 +9,7 @@ import ( "github.com/gnolang/gno/gno.land/pkg/sdk/vm" gno "github.com/gnolang/gno/gnovm/pkg/gnolang" + "github.com/gnolang/gno/gnovm/pkg/gnolang/transpiler" "github.com/gnolang/gno/tm2/pkg/amino" "github.com/gnolang/gno/tm2/pkg/commands" "github.com/gnolang/gno/tm2/pkg/crypto/keys" @@ -108,8 +109,8 @@ func execMakeRun(cfg *MakeRunCfg, args []string, cmdio commands.IO) error { if memPkg.IsEmpty() { panic(fmt.Sprintf("found an empty package %q", memPkg.Path)) } - // precompile and validate syntax - err = gno.PrecompileAndCheckMempkg(memPkg) + // transpile and validate syntax + err = transpiler.TranspileAndCheckMempkg(memPkg) if err != nil { panic(err) } diff --git a/gnovm/cmd/gno/README.md b/gnovm/cmd/gno/README.md index 97285684785..d49ca85736e 100644 --- a/gnovm/cmd/gno/README.md +++ b/gnovm/cmd/gno/README.md @@ -10,7 +10,7 @@ * `gno run` - run a Gno file * `gno build` - build a gno package -* `gno precompile` - precompile .gno to .go +* `gno transpile` - transpile .gno to .go * `gno test` - test a gno package * `gno mod` - manages dependencies * `gno repl` start a GnoVM REPL diff --git a/gnovm/cmd/gno/lint_test.go b/gnovm/cmd/gno/lint_test.go index d700467965d..1966eab7c9e 100644 --- a/gnovm/cmd/gno/lint_test.go +++ b/gnovm/cmd/gno/lint_test.go @@ -31,7 +31,7 @@ func TestLintApp(t *testing.T) { // TODO: is gno source valid? // TODO: are dependencies valid? // TODO: is gno source using unsafe/discouraged features? - // TODO: consider making `gno precompile; go lint *gen.go` + // TODO: consider making `gno transpile; go lint *gen.go` // TODO: check for imports of native libs from non _test.gno files } testMainCaseRun(t, tc) diff --git a/gnovm/cmd/gno/main.go b/gnovm/cmd/gno/main.go index aecb5d0f1e5..5271bcb1e9f 100644 --- a/gnovm/cmd/gno/main.go +++ b/gnovm/cmd/gno/main.go @@ -28,7 +28,7 @@ func newGnocliCmd(io commands.IO) *commands.Command { newTestCmd(io), newLintCmd(io), newRunCmd(io), - newPrecompileCmd(io), + newTranspileCmd(io), newCleanCmd(io), newReplCmd(), newDocCmd(io), diff --git a/gnovm/cmd/gno/precompile.go b/gnovm/cmd/gno/precompile.go index 2d7a727a13a..7b32df556b5 100644 --- a/gnovm/cmd/gno/precompile.go +++ b/gnovm/cmd/gno/precompile.go @@ -10,13 +10,13 @@ import ( "os" "path/filepath" - gno "github.com/gnolang/gno/gnovm/pkg/gnolang" + "github.com/gnolang/gno/gnovm/pkg/gnolang/transpiler" "github.com/gnolang/gno/tm2/pkg/commands" ) type importPath string -type precompileCfg struct { +type transpileCfg struct { verbose bool skipFmt bool skipImports bool @@ -26,52 +26,52 @@ type precompileCfg struct { output string } -type precompileOptions struct { - cfg *precompileCfg - // precompiled is the set of packages already - // precompiled from .gno to .go. - precompiled map[importPath]struct{} +type transpileOptions struct { + cfg *transpileCfg + // transpiled is the set of packages already + // transpiled from .gno to .go. + transpiled map[importPath]struct{} } -var defaultPrecompileCfg = &precompileCfg{ +var defaultTranspileCfg = &transpileCfg{ verbose: false, goBinary: "go", } -func newPrecompileOptions(cfg *precompileCfg) *precompileOptions { - return &precompileOptions{cfg, map[importPath]struct{}{}} +func newTranspileOptions(cfg *transpileCfg) *transpileOptions { + return &transpileOptions{cfg, map[importPath]struct{}{}} } -func (p *precompileOptions) getFlags() *precompileCfg { +func (p *transpileOptions) getFlags() *transpileCfg { return p.cfg } -func (p *precompileOptions) isPrecompiled(pkg importPath) bool { - _, precompiled := p.precompiled[pkg] - return precompiled +func (p *transpileOptions) isTranspiled(pkg importPath) bool { + _, transpiled := p.transpiled[pkg] + return transpiled } -func (p *precompileOptions) markAsPrecompiled(pkg importPath) { - p.precompiled[pkg] = struct{}{} +func (p *transpileOptions) markAsTranspiled(pkg importPath) { + p.transpiled[pkg] = struct{}{} } -func newPrecompileCmd(io commands.IO) *commands.Command { - cfg := &precompileCfg{} +func newTranspileCmd(io commands.IO) *commands.Command { + cfg := &transpileCfg{} return commands.NewCommand( commands.Metadata{ - Name: "precompile", - ShortUsage: "precompile [flags] [...]", - ShortHelp: "Precompiles .gno files to .go", + Name: "transpile", + ShortUsage: "transpile [flags] [...]", + ShortHelp: "Transpiles .gno files to .go", }, cfg, func(_ context.Context, args []string) error { - return execPrecompile(cfg, args, io) + return execTranspile(cfg, args, io) }, ) } -func (c *precompileCfg) RegisterFlags(fs *flag.FlagSet) { +func (c *transpileCfg) RegisterFlags(fs *flag.FlagSet) { fs.BoolVar( &c.verbose, "verbose", @@ -90,7 +90,7 @@ func (c *precompileCfg) RegisterFlags(fs *flag.FlagSet) { &c.skipImports, "skip-imports", false, - "do not precompile imports recursively", + "do not transpile imports recursively", ) fs.BoolVar( @@ -122,25 +122,25 @@ func (c *precompileCfg) RegisterFlags(fs *flag.FlagSet) { ) } -func execPrecompile(cfg *precompileCfg, args []string, io commands.IO) error { +func execTranspile(cfg *transpileCfg, args []string, io commands.IO) error { if len(args) < 1 { return flag.ErrHelp } - // precompile .gno files. + // transpile .gno files. paths, err := gnoFilesFromArgs(args) if err != nil { return fmt.Errorf("list paths: %w", err) } - opts := newPrecompileOptions(cfg) + opts := newTranspileOptions(cfg) var errlist scanner.ErrorList for _, filepath := range paths { - if err := precompileFile(filepath, opts); err != nil { + if err := transpileFile(filepath, opts); err != nil { var fileErrlist scanner.ErrorList if !errors.As(err, &fileErrlist) { // Not an scanner.ErrorList: return immediately. - return fmt.Errorf("%s: precompile: %w", filepath, err) + return fmt.Errorf("%s: transpile: %w", filepath, err) } errlist = append(errlist, fileErrlist...) } @@ -169,16 +169,16 @@ func execPrecompile(cfg *precompileCfg, args []string, io commands.IO) error { for _, err := range errlist { io.ErrPrintfln(err.Error()) } - return fmt.Errorf("%d precompile error(s)", errlist.Len()) + return fmt.Errorf("%d transpile error(s)", errlist.Len()) } return nil } -func precompilePkg(pkgPath importPath, opts *precompileOptions) error { - if opts.isPrecompiled(pkgPath) { +func transpilePkg(pkgPath importPath, opts *transpileOptions) error { + if opts.isTranspiled(pkgPath) { return nil } - opts.markAsPrecompiled(pkgPath) + opts.markAsTranspiled(pkgPath) files, err := filepath.Glob(filepath.Join(string(pkgPath), "*.gno")) if err != nil { @@ -186,7 +186,7 @@ func precompilePkg(pkgPath importPath, opts *precompileOptions) error { } for _, file := range files { - if err = precompileFile(file, opts); err != nil { + if err = transpileFile(file, opts); err != nil { return fmt.Errorf("%s: %w", file, err) } } @@ -194,7 +194,7 @@ func precompilePkg(pkgPath importPath, opts *precompileOptions) error { return nil } -func precompileFile(srcPath string, opts *precompileOptions) error { +func transpileFile(srcPath string, opts *transpileOptions) error { flags := opts.getFlags() gofmt := flags.gofmtBinary if gofmt == "" { @@ -212,12 +212,12 @@ func precompileFile(srcPath string, opts *precompileOptions) error { } // compute attributes based on filename. - targetFilename, tags := gno.GetPrecompileFilenameAndTags(srcPath) + targetFilename, tags := transpiler.GetTranspileFilenameAndTags(srcPath) // preprocess. - precompileRes, err := gno.Precompile(string(source), tags, srcPath) + transpileRes, err := transpiler.Transpile(string(source), tags, srcPath) if err != nil { - return fmt.Errorf("precompile: %w", err) + return fmt.Errorf("transpile: %w", err) } // resolve target path @@ -233,31 +233,31 @@ func precompileFile(srcPath string, opts *precompileOptions) error { } // write .go file. - err = WriteDirFile(targetPath, []byte(precompileRes.Translated)) + err = WriteDirFile(targetPath, []byte(transpileRes.Translated)) if err != nil { return fmt.Errorf("write .go file: %w", err) } // check .go fmt, if `SkipFmt` sets to false. if !flags.skipFmt { - err = gno.PrecompileVerifyFile(targetPath, gofmt) + err = transpiler.TranspileVerifyFile(targetPath, gofmt) if err != nil { return fmt.Errorf("check .go file: %w", err) } } - // precompile imported packages, if `SkipImports` sets to false + // transpile imported packages, if `SkipImports` sets to false if !flags.skipImports { - importPaths := getPathsFromImportSpec(precompileRes.Imports) + importPaths := getPathsFromImportSpec(transpileRes.Imports) for _, path := range importPaths { - precompilePkg(path, opts) + transpilePkg(path, opts) } } return nil } -func goBuildFileOrPkg(fileOrPkg string, cfg *precompileCfg) error { +func goBuildFileOrPkg(fileOrPkg string, cfg *transpileCfg) error { verbose := cfg.verbose goBinary := cfg.goBinary @@ -265,5 +265,5 @@ func goBuildFileOrPkg(fileOrPkg string, cfg *precompileCfg) error { fmt.Fprintf(os.Stderr, "%s\n", fileOrPkg) } - return gno.PrecompileBuildPackage(fileOrPkg, goBinary) + return transpiler.TranspileBuildPackage(fileOrPkg, goBinary) } diff --git a/gnovm/cmd/gno/precompile_test.go b/gnovm/cmd/gno/precompile_test.go index f8436fad768..2770026a01a 100644 --- a/gnovm/cmd/gno/precompile_test.go +++ b/gnovm/cmd/gno/precompile_test.go @@ -9,9 +9,9 @@ import ( "github.com/gnolang/gno/gnovm/pkg/integration" ) -func Test_ScriptsPrecompile(t *testing.T) { +func Test_ScriptsTranspile(t *testing.T) { p := testscript.Params{ - Dir: "testdata/gno_precompile", + Dir: "testdata/gno_transpile", } if coverdir, ok := integration.ResolveCoverageDir(); ok { diff --git a/gnovm/cmd/gno/test.go b/gnovm/cmd/gno/test.go index 1deac5aac48..082e2066ff5 100644 --- a/gnovm/cmd/gno/test.go +++ b/gnovm/cmd/gno/test.go @@ -19,6 +19,7 @@ import ( "github.com/gnolang/gno/gnovm/pkg/gnoenv" gno "github.com/gnolang/gno/gnovm/pkg/gnolang" + "github.com/gnolang/gno/gnovm/pkg/gnolang/transpiler" "github.com/gnolang/gno/gnovm/pkg/gnomod" "github.com/gnolang/gno/gnovm/tests" "github.com/gnolang/gno/tm2/pkg/commands" @@ -33,7 +34,7 @@ type testCfg struct { rootDir string run string timeout time.Duration - precompile bool // TODO: precompile should be the default, but it needs to automatically precompile dependencies in memory. + transpile bool // TODO: transpile should be the default, but it needs to automatically transpile dependencies in memory. updateGoldenTests bool printRuntimeMetrics bool withNativeFallback bool @@ -110,10 +111,10 @@ func (c *testCfg) RegisterFlags(fs *flag.FlagSet) { ) fs.BoolVar( - &c.precompile, - "precompile", + &c.transpile, + "transpile", false, - "precompile gno to go before testing", + "transpile gno to go before testing", ) fs.BoolVar( @@ -166,7 +167,7 @@ func execTest(cfg *testCfg, args []string, io commands.IO) error { verbose := cfg.verbose - tempdirRoot, err := os.MkdirTemp("", "gno-precompile") + tempdirRoot, err := os.MkdirTemp("", "gno-transpile") if err != nil { log.Fatal(err) } @@ -174,7 +175,7 @@ func execTest(cfg *testCfg, args []string, io commands.IO) error { // go.mod modPath := filepath.Join(tempdirRoot, "go.mod") - err = makeTestGoMod(modPath, gno.ImportPrefix, "1.21") + err = makeTestGoMod(modPath, transpiler.ImportPrefix, "1.21") if err != nil { return fmt.Errorf("write .mod file: %w", err) } @@ -208,14 +209,14 @@ func execTest(cfg *testCfg, args []string, io commands.IO) error { buildErrCount := 0 testErrCount := 0 for _, pkg := range subPkgs { - if cfg.precompile { + if cfg.transpile { if verbose { io.ErrPrintfln("=== PREC %s", pkg.Dir) } - precompileOpts := newPrecompileOptions(&precompileCfg{ + transpileOpts := newTranspileOptions(&transpileCfg{ output: tempdirRoot, }) - err := precompilePkg(importPath(pkg.Dir), precompileOpts) + err := transpilePkg(importPath(pkg.Dir), transpileOpts) if err != nil { io.ErrPrintln(err) io.ErrPrintln("FAIL") @@ -233,7 +234,7 @@ func execTest(cfg *testCfg, args []string, io commands.IO) error { if err != nil { return errors.New("cannot resolve build dir") } - err = goBuildFileOrPkg(tempDir, defaultPrecompileCfg) + err = goBuildFileOrPkg(tempDir, defaultTranspileCfg) if err != nil { io.ErrPrintln(err) io.ErrPrintln("FAIL") @@ -317,7 +318,7 @@ func gnoTestPkg( gnoPkgPath = pkgPathFromRootDir(pkgPath, rootDir) if gnoPkgPath == "" { // unable to read pkgPath from gno.mod, generate a random realm path - gnoPkgPath = gno.GnoRealmPkgsPrefixBefore + random.RandStr(8) + gnoPkgPath = transpiler.GnoRealmPkgsPrefixBefore + random.RandStr(8) } } memPkg := gno.ReadMemPackage(pkgPath, gnoPkgPath) diff --git a/gnovm/cmd/gno/testdata/gno_precompile/01_no_args.txtar b/gnovm/cmd/gno/testdata/gno_precompile/01_no_args.txtar index 239d3860e11..6d8592d4e3b 100644 --- a/gnovm/cmd/gno/testdata/gno_precompile/01_no_args.txtar +++ b/gnovm/cmd/gno/testdata/gno_precompile/01_no_args.txtar @@ -1,6 +1,6 @@ -# Run gno precompile without args +# Run gno transpile without args -! gno precompile +! gno transpile -! stdout .+ +! stdout .+ stderr 'USAGE' diff --git a/gnovm/cmd/gno/testdata/gno_precompile/02_empty_dir.txtar b/gnovm/cmd/gno/testdata/gno_precompile/02_empty_dir.txtar index 7afc7ed0683..2bd1841d2b4 100644 --- a/gnovm/cmd/gno/testdata/gno_precompile/02_empty_dir.txtar +++ b/gnovm/cmd/gno/testdata/gno_precompile/02_empty_dir.txtar @@ -1,6 +1,6 @@ -# Run gno precompile on an empty dir +# Run gno transpile on an empty dir -gno precompile . +gno transpile . ! stdout .+ ! stderr .+ diff --git a/gnovm/cmd/gno/testdata/gno_precompile/03_gno_files_parse_error.txtar b/gnovm/cmd/gno/testdata/gno_precompile/03_gno_files_parse_error.txtar index 6e2475e5962..b94b86992af 100644 --- a/gnovm/cmd/gno/testdata/gno_precompile/03_gno_files_parse_error.txtar +++ b/gnovm/cmd/gno/testdata/gno_precompile/03_gno_files_parse_error.txtar @@ -1,12 +1,12 @@ -# Run gno precompile with gno files with parse errors +# Run gno transpile with gno files with parse errors -! gno precompile . +! gno transpile . ! stdout .+ stderr '^main.gno:3:1: expected declaration, found invalid$' stderr '^main.gno:7:2: expected declaration, found wrong$' stderr '^sub/sub.gno:3:1: expected declaration, found invalid$' -stderr '^3 precompile error\(s\)$' +stderr '^3 transpile error\(s\)$' # no *.gen.go files are created ! exec test -f main.gno.gen.go diff --git a/gnovm/cmd/gno/testdata/gno_precompile/04_valid_gno_files.txtar b/gnovm/cmd/gno/testdata/gno_precompile/04_valid_gno_files.txtar index 0f9d909f627..4770386e7f5 100644 --- a/gnovm/cmd/gno/testdata/gno_precompile/04_valid_gno_files.txtar +++ b/gnovm/cmd/gno/testdata/gno_precompile/04_valid_gno_files.txtar @@ -1,6 +1,6 @@ -# Run gno precompile with valid gno files +# Run gno transpile with valid gno files -gno precompile . +gno transpile . ! stdout .+ ! stderr .+ diff --git a/gnovm/cmd/gno/testdata/gno_precompile/05_skip_fmt_flag.txtar b/gnovm/cmd/gno/testdata/gno_precompile/05_skip_fmt_flag.txtar index 0f7780efdad..6f7a5e16665 100644 --- a/gnovm/cmd/gno/testdata/gno_precompile/05_skip_fmt_flag.txtar +++ b/gnovm/cmd/gno/testdata/gno_precompile/05_skip_fmt_flag.txtar @@ -1,8 +1,8 @@ -# Run gno precompile with -skip-fmt flag +# Run gno transpile with -skip-fmt flag # NOTE(tb): this flag doesn't actually prevent the code format, because -# `gnolang.Precompile()` calls `format.Node()`. +# `gnolang.Transpile()` calls `format.Node()`. -gno precompile -skip-fmt . +gno transpile -skip-fmt . ! stdout .+ ! stderr .+ diff --git a/gnovm/cmd/gno/testdata/gno_precompile/06_build_flag.txtar b/gnovm/cmd/gno/testdata/gno_precompile/06_build_flag.txtar index b93fae95fcf..23eac452058 100644 --- a/gnovm/cmd/gno/testdata/gno_precompile/06_build_flag.txtar +++ b/gnovm/cmd/gno/testdata/gno_precompile/06_build_flag.txtar @@ -1,6 +1,6 @@ -# Run gno precompile with -gobuild flag +# Run gno transpile with -gobuild flag -gno precompile -gobuild . +gno transpile -gobuild . ! stdout .+ ! stderr .+ diff --git a/gnovm/cmd/gno/testdata/gno_precompile/07_build_flag_with_build_error.txtar b/gnovm/cmd/gno/testdata/gno_precompile/07_build_flag_with_build_error.txtar index 85b411e9db1..1c3727e2072 100644 --- a/gnovm/cmd/gno/testdata/gno_precompile/07_build_flag_with_build_error.txtar +++ b/gnovm/cmd/gno/testdata/gno_precompile/07_build_flag_with_build_error.txtar @@ -1,11 +1,11 @@ -# Run gno precompile with -gobuild flag +# Run gno transpile with -gobuild flag -! gno precompile -gobuild . +! gno transpile -gobuild . ! stdout .+ stderr '^./main.gno:4:6: x declared and not used$' stderr '^./main.gno:5:6: y declared and not used$' -stderr '^2 precompile error\(s\)$' +stderr '^2 transpile error\(s\)$' cmp main.gno.gen.go main.gno.gen.go.golden cmp sub/sub.gno.gen.go sub/sub.gno.gen.go.golden diff --git a/gnovm/cmd/gno/testdata/gno_precompile/08_build_flag_with_parse_error.txtar b/gnovm/cmd/gno/testdata/gno_precompile/08_build_flag_with_parse_error.txtar index 74dbfa5d06f..629de2b7f3d 100644 --- a/gnovm/cmd/gno/testdata/gno_precompile/08_build_flag_with_parse_error.txtar +++ b/gnovm/cmd/gno/testdata/gno_precompile/08_build_flag_with_parse_error.txtar @@ -1,6 +1,6 @@ -# Run gno precompile with -gobuild flag on file with parse error +# Run gno transpile with -gobuild flag on file with parse error -! gno precompile -gobuild . +! gno transpile -gobuild . ! stdout .+ stderr '^main.gno:3:1: expected declaration, found invalid$' diff --git a/gnovm/cmd/gno/testdata/gno_precompile/09_gno_files_whitelist_error.txtar b/gnovm/cmd/gno/testdata/gno_precompile/09_gno_files_whitelist_error.txtar index a64a44f466c..79d4d6a4a2c 100644 --- a/gnovm/cmd/gno/testdata/gno_precompile/09_gno_files_whitelist_error.txtar +++ b/gnovm/cmd/gno/testdata/gno_precompile/09_gno_files_whitelist_error.txtar @@ -1,11 +1,11 @@ -# Run gno precompile with gno files with whitelist errors +# Run gno transpile with gno files with whitelist errors -! gno precompile . +! gno transpile . ! stdout .+ stderr '^main.gno:5:2: import "xxx" is not in the whitelist$' stderr '^sub/sub.gno:3:8: import "xxx" is not in the whitelist$' -stderr '^2 precompile error\(s\)$' +stderr '^2 transpile error\(s\)$' # no *.gen.go files are created ! exec test -f main.gno.gen.go diff --git a/gnovm/cmd/gno/testdata/gno_test/empty_gno1.txtar b/gnovm/cmd/gno/testdata/gno_test/empty_gno1.txtar index cc673bb38ff..6d7d73a5e20 100644 --- a/gnovm/cmd/gno/testdata/gno_test/empty_gno1.txtar +++ b/gnovm/cmd/gno/testdata/gno_test/empty_gno1.txtar @@ -5,7 +5,7 @@ gno test . ! stdout .+ stderr '\? \. \[no test files\]' -! gno test --precompile . +! gno test --transpile . ! stdout .+ stderr 'expected ''package'', found ''EOF''' diff --git a/gnovm/cmd/gno/testdata/gno_test/empty_gno2.txtar b/gnovm/cmd/gno/testdata/gno_test/empty_gno2.txtar index 0ea13294a1b..fa14c412548 100644 --- a/gnovm/cmd/gno/testdata/gno_test/empty_gno2.txtar +++ b/gnovm/cmd/gno/testdata/gno_test/empty_gno2.txtar @@ -5,7 +5,7 @@ ! stdout .+ stderr 'expected ''package'', found ''EOF''' -! gno test --precompile . +! gno test --transpile . ! stdout .+ stderr 'expected ''package'', found ''EOF''' diff --git a/gnovm/cmd/gno/testdata/gno_test/empty_gno3.txtar b/gnovm/cmd/gno/testdata/gno_test/empty_gno3.txtar index c095de6c358..3ffe7adcedd 100644 --- a/gnovm/cmd/gno/testdata/gno_test/empty_gno3.txtar +++ b/gnovm/cmd/gno/testdata/gno_test/empty_gno3.txtar @@ -5,7 +5,7 @@ ! stdout .+ stderr 'expected ''package'', found ''EOF''' -! gno test --precompile . +! gno test --transpile . ! stdout .+ stderr 'expected ''package'', found ''EOF''' diff --git a/gnovm/cmd/gno/testdata/gno_test/failing_filetest.txtar b/gnovm/cmd/gno/testdata/gno_test/failing_filetest.txtar index c739c1ce328..ae1db2b67e5 100644 --- a/gnovm/cmd/gno/testdata/gno_test/failing_filetest.txtar +++ b/gnovm/cmd/gno/testdata/gno_test/failing_filetest.txtar @@ -6,7 +6,7 @@ stdout 'Machine.RunMain\(\) panic: beep boop' stderr '=== RUN file/failing_filetest.gno' stderr 'panic: fail on failing_filetest.gno: got unexpected error: beep boop' -! gno test -verbose --precompile . +! gno test -verbose --transpile . stdout 'Machine.RunMain\(\) panic: beep boop' stderr '=== PREC \.' diff --git a/gnovm/cmd/gno/testdata/gno_test/failing_test.txtar b/gnovm/cmd/gno/testdata/gno_test/failing_test.txtar index 0bf4aab21ff..e5c103fd95b 100644 --- a/gnovm/cmd/gno/testdata/gno_test/failing_test.txtar +++ b/gnovm/cmd/gno/testdata/gno_test/failing_test.txtar @@ -7,7 +7,7 @@ stderr '=== RUN TestAlwaysFailing' stderr '--- FAIL: TestAlwaysFailing' stderr 'FAIL: 0 build errors, 1 test errors' -! gno test -verbose --precompile . +! gno test -verbose --transpile . ! stdout .+ stderr '=== RUN TestAlwaysFailing' diff --git a/gnovm/cmd/gno/util.go b/gnovm/cmd/gno/util.go index a8e835d4759..c46e5d4e8f0 100644 --- a/gnovm/cmd/gno/util.go +++ b/gnovm/cmd/gno/util.go @@ -12,7 +12,7 @@ import ( "time" "github.com/gnolang/gno/gnovm/pkg/gnoenv" - gno "github.com/gnolang/gno/gnovm/pkg/gnolang" + "github.com/gnolang/gno/gnovm/pkg/gnolang/transpiler" ) func isGnoFile(f fs.DirEntry) bool { @@ -203,8 +203,8 @@ func makeTestGoMod(path string, packageName string, goversion string) error { func getPathsFromImportSpec(importSpec []*ast.ImportSpec) (importPaths []importPath) { for _, i := range importSpec { path := i.Path.Value[1 : len(i.Path.Value)-1] // trim leading and trailing `"` - if strings.HasPrefix(path, gno.ImportPrefix) { - res := strings.TrimPrefix(path, gno.ImportPrefix) + if strings.HasPrefix(path, transpiler.ImportPrefix) { + res := strings.TrimPrefix(path, transpiler.ImportPrefix) importPaths = append(importPaths, importPath("."+res)) } } @@ -213,9 +213,9 @@ func getPathsFromImportSpec(importSpec []*ast.ImportSpec) (importPaths []importP // ResolvePath joins the output dir with relative pkg path // e.g -// Output Dir: Temp/gno-precompile +// Output Dir: Temp/gno-transpile // Pkg Path: ../example/gno.land/p/pkg -// Returns -> Temp/gno-precompile/example/gno.land/p/pkg +// Returns -> Temp/gno-transpile/example/gno.land/p/pkg func ResolvePath(output string, path importPath) (string, error) { absOutput, err := filepath.Abs(output) if err != nil { diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 519b183ad3a..d146b3fa7db 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -1511,13 +1511,14 @@ func isUnsaved(oo Object) bool { return oo.GetIsNewReal() || oo.GetIsDirty() } +// realmPathPrefix is the prefix used to identify pkgpaths which are meant to +// be realms and as such to have their state persisted. This is used by [IsRealmPath]. +const realmPathPrefix = "gno.land/r/" + +// IsRealmPath determines whether the given pkgpath is for a realm, and as such +// should persist the global state. func IsRealmPath(pkgPath string) bool { - // TODO: make it more distinct to distinguish from normal paths. - if strings.HasPrefix(pkgPath, GnoRealmPkgsPrefixBefore) { - return true - } else { - return false - } + return strings.HasPrefix(pkgPath, realmPathPrefix) } func prettyJSON(jstr []byte) []byte { diff --git a/gnovm/pkg/gnolang/precompile.go b/gnovm/pkg/gnolang/transpiler/transpiler.go similarity index 87% rename from gnovm/pkg/gnolang/precompile.go rename to gnovm/pkg/gnolang/transpiler/transpiler.go index af51e962416..d9a3398f2f1 100644 --- a/gnovm/pkg/gnolang/precompile.go +++ b/gnovm/pkg/gnolang/transpiler/transpiler.go @@ -1,4 +1,4 @@ -package gnolang +package transpiler import ( "bytes" @@ -81,13 +81,13 @@ var importPrefixWhitelist = []string{ const ImportPrefix = "github.com/gnolang/gno" -type precompileResult struct { +type transpileResult struct { Imports []*ast.ImportSpec Translated string } -// TODO: func PrecompileFile: supports caching. -// TODO: func PrecompilePkg: supports directories. +// TODO: func TranspileFile: supports caching. +// TODO: func TranspilePkg: supports directories. func guessRootDir(fileOrPkg string, goBinary string) (string, error) { abs, err := filepath.Abs(fileOrPkg) @@ -105,8 +105,8 @@ func guessRootDir(fileOrPkg string, goBinary string) (string, error) { return rootDir, nil } -// GetPrecompileFilenameAndTags returns the filename and tags for precompiled files. -func GetPrecompileFilenameAndTags(gnoFilePath string) (targetFilename, tags string) { +// GetTranspileFilenameAndTags returns the filename and tags for transpiled files. +func GetTranspileFilenameAndTags(gnoFilePath string) (targetFilename, tags string) { nameNoExtension := strings.TrimSuffix(filepath.Base(gnoFilePath), ".gno") switch { case strings.HasSuffix(gnoFilePath, "_filetest.gno"): @@ -122,7 +122,7 @@ func GetPrecompileFilenameAndTags(gnoFilePath string) (targetFilename, tags stri return } -func PrecompileAndCheckMempkg(mempkg *std.MemPackage) error { +func TranspileAndCheckMempkg(mempkg *std.MemPackage) error { gofmt := "gofmt" tmpDir, err := os.MkdirTemp("", mempkg.Name) @@ -136,7 +136,7 @@ func PrecompileAndCheckMempkg(mempkg *std.MemPackage) error { if !strings.HasSuffix(mfile.Name, ".gno") { continue // skip spurious file. } - res, err := Precompile(mfile.Body, "gno,tmp", mfile.Name) + res, err := Transpile(mfile.Body, "gno,tmp", mfile.Name) if err != nil { errs = multierr.Append(errs, err) continue @@ -147,7 +147,7 @@ func PrecompileAndCheckMempkg(mempkg *std.MemPackage) error { errs = multierr.Append(errs, err) continue } - err = PrecompileVerifyFile(tmpFile, gofmt) + err = TranspileVerifyFile(tmpFile, gofmt) if err != nil { errs = multierr.Append(errs, err) continue @@ -155,12 +155,12 @@ func PrecompileAndCheckMempkg(mempkg *std.MemPackage) error { } if errs != nil { - return fmt.Errorf("precompile package: %w", errs) + return fmt.Errorf("transpile package: %w", errs) } return nil } -func Precompile(source string, tags string, filename string) (*precompileResult, error) { +func Transpile(source string, tags string, filename string) (*transpileResult, error) { fset := token.NewFileSet() f, err := parser.ParseFile(fset, filename, source, parser.ParseComments) if err != nil { @@ -170,9 +170,9 @@ func Precompile(source string, tags string, filename string) (*precompileResult, isTestFile := strings.HasSuffix(filename, "_test.gno") || strings.HasSuffix(filename, "_filetest.gno") shouldCheckWhitelist := !isTestFile - transformed, err := precompileAST(fset, f, shouldCheckWhitelist) + transformed, err := transpileAST(fset, f, shouldCheckWhitelist) if err != nil { - return nil, fmt.Errorf("precompileAST: %w", err) + return nil, fmt.Errorf("transpileAST: %w", err) } header := "// Code generated by github.com/gnolang/gno. DO NOT EDIT.\n\n" @@ -186,17 +186,17 @@ func Precompile(source string, tags string, filename string) (*precompileResult, return nil, fmt.Errorf("format.Node: %w", err) } - res := &precompileResult{ + res := &transpileResult{ Imports: f.Imports, Translated: out.String(), } return res, nil } -// PrecompileVerifyFile tries to run `go fmt` against a precompiled .go file. +// TranspileVerifyFile tries to run `go fmt` against a transpiled .go file. // // This is fast and won't look the imports. -func PrecompileVerifyFile(path string, gofmtBinary string) error { +func TranspileVerifyFile(path string, gofmtBinary string) error { // TODO: use cmd/parser instead of exec? args := strings.Split(gofmtBinary, " ") @@ -210,16 +210,16 @@ func PrecompileVerifyFile(path string, gofmtBinary string) error { return nil } -// PrecompileBuildPackage tries to run `go build` against the precompiled .go files. +// TranspileBuildPackage tries to run `go build` against the transpiled .go files. // // This method is the most efficient to detect errors but requires that // all the import are valid and available. -func PrecompileBuildPackage(fileOrPkg, goBinary string) error { +func TranspileBuildPackage(fileOrPkg, goBinary string) error { // TODO: use cmd/compile instead of exec? // TODO: find the nearest go.mod file, chdir in the same folder, rim prefix? // TODO: temporarily create an in-memory go.mod or disable go modules for gno? // TODO: ignore .go files that were not generated from gno? - // TODO: automatically precompile if not yet done. + // TODO: automatically transpile if not yet done. files := []string{} @@ -272,7 +272,7 @@ var errorRe = regexp.MustCompile(`(?m)^(\S+):(\d+):(\d+): (.+)$`) // Each errors are translated into their correlated gno files, by: // - changing the filename from *.gno.gen.go to *.gno // - shifting line number according to the added header in generated go files -// (see [Precompile] for that header). +// (see [Transpile] for that header). func parseGoBuildErrors(out string) error { var errList goscanner.ErrorList matches := errorRe.FindAllStringSubmatch(out, -1) @@ -293,7 +293,7 @@ func parseGoBuildErrors(out string) error { Filename: strings.TrimSuffix(filename, ".gen.go"), // Shift the 4 lines header added in *.gen.go files. // NOTE(tb): the 4 lines shift below assumes there's always a //go:build - // directive. But the tags are optional in the Precompile() function + // directive. But the tags are optional in the Transpile() function // so that leaves some doubts... We might want something more reliable than // constants to shift lines. Line: line - 4, @@ -303,7 +303,7 @@ func parseGoBuildErrors(out string) error { return errList.Err() } -func precompileAST(fset *token.FileSet, f *ast.File, checkWhitelist bool) (ast.Node, error) { +func transpileAST(fset *token.FileSet, f *ast.File, checkWhitelist bool) (ast.Node, error) { var errs goscanner.ErrorList imports := astutil.Imports(fset, f) diff --git a/gnovm/pkg/gnolang/precompile_test.go b/gnovm/pkg/gnolang/transpiler/transpiler_test.go similarity index 96% rename from gnovm/pkg/gnolang/precompile_test.go rename to gnovm/pkg/gnolang/transpiler/transpiler_test.go index 3f36a16a5e8..03659be6c37 100644 --- a/gnovm/pkg/gnolang/precompile_test.go +++ b/gnovm/pkg/gnolang/transpiler/transpiler_test.go @@ -1,4 +1,4 @@ -package gnolang +package transpiler import ( "go/ast" @@ -11,7 +11,7 @@ import ( "github.com/jaekwon/testify/require" ) -func TestPrecompile(t *testing.T) { +func TestTranspile(t *testing.T) { t.Parallel() cases := []struct { @@ -196,7 +196,7 @@ import "reflect" func foo() { _ = reflect.ValueOf } `, - expectedError: `precompileAST: foo.gno:3:8: import "reflect" is not in the whitelist`, + expectedError: `transpileAST: foo.gno:3:8: import "reflect" is not in the whitelist`, }, { name: "syntax-error", @@ -268,7 +268,7 @@ func foo() { _ = regexp.MatchString } // "\n" is added for better test case readability, now trim it source := strings.TrimPrefix(c.source, "\n") - res, err := Precompile(source, c.tags, "foo.gno") + res, err := Transpile(source, c.tags, "foo.gno") if c.expectedError != "" { require.EqualError(t, err, c.expectedError) diff --git a/gnovm/pkg/gnomod/file.go b/gnovm/pkg/gnomod/file.go index 25189ebc71d..d1dff4ee816 100644 --- a/gnovm/pkg/gnomod/file.go +++ b/gnovm/pkg/gnomod/file.go @@ -17,7 +17,7 @@ import ( "path/filepath" "strings" - "github.com/gnolang/gno/gnovm/pkg/gnolang" + "github.com/gnolang/gno/gnovm/pkg/gnolang/transpiler" "golang.org/x/mod/modfile" "golang.org/x/mod/module" ) @@ -184,12 +184,12 @@ func (f *File) FetchDeps(path string, remote string, verbose bool) error { continue } // skip if `std`, special case. - if path == gnolang.GnoStdPkgAfter { + if path == transpiler.GnoStdPkgAfter { continue } - if strings.HasPrefix(path, gnolang.ImportPrefix) { - path = strings.TrimPrefix(path, gnolang.ImportPrefix+"/examples/") + if strings.HasPrefix(path, transpiler.ImportPrefix) { + path = strings.TrimPrefix(path, transpiler.ImportPrefix+"/examples/") modFile.AddNewRequire(path, "v0.0.0-latest", true) } } diff --git a/gnovm/pkg/gnomod/gnomod.go b/gnovm/pkg/gnomod/gnomod.go index d750b7c9f29..54a30df73dd 100644 --- a/gnovm/pkg/gnomod/gnomod.go +++ b/gnovm/pkg/gnomod/gnomod.go @@ -9,6 +9,7 @@ import ( "github.com/gnolang/gno/gnovm/pkg/gnoenv" "github.com/gnolang/gno/gnovm/pkg/gnolang" + "github.com/gnolang/gno/gnovm/pkg/gnolang/transpiler" "github.com/gnolang/gno/tm2/pkg/std" "golang.org/x/mod/modfile" "golang.org/x/mod/module" @@ -61,21 +62,21 @@ func writePackage(remote, basePath, pkgPath string) (requirements []string, err } } else { // Is File - // Precompile and write generated go file + // Transpile and write generated go file if strings.HasSuffix(fileName, ".gno") { filePath := filepath.Join(basePath, pkgPath) - targetFilename, _ := gnolang.GetPrecompileFilenameAndTags(filePath) - precompileRes, err := gnolang.Precompile(string(res.Data), "", fileName) + targetFilename, _ := transpiler.GetTranspileFilenameAndTags(filePath) + transpileRes, err := transpiler.Transpile(string(res.Data), "", fileName) if err != nil { - return nil, fmt.Errorf("precompile: %w", err) + return nil, fmt.Errorf("transpile: %w", err) } - for _, i := range precompileRes.Imports { + for _, i := range transpileRes.Imports { requirements = append(requirements, i.Path.Value) } targetFileNameWithPath := filepath.Join(basePath, dirPath, targetFilename) - err = os.WriteFile(targetFileNameWithPath, []byte(precompileRes.Translated), 0o644) + err = os.WriteFile(targetFileNameWithPath, []byte(transpileRes.Translated), 0o644) if err != nil { return nil, fmt.Errorf("writefile %q: %w", targetFileNameWithPath, err) } @@ -97,9 +98,9 @@ func writePackage(remote, basePath, pkgPath string) (requirements []string, err func GnoToGoMod(f File) (*File, error) { gnoModPath := GetGnoModPath() - if strings.HasPrefix(f.Module.Mod.Path, gnolang.GnoRealmPkgsPrefixBefore) || - strings.HasPrefix(f.Module.Mod.Path, gnolang.GnoPackagePrefixBefore) { - f.AddModuleStmt(gnolang.ImportPrefix + "/examples/" + f.Module.Mod.Path) + if strings.HasPrefix(f.Module.Mod.Path, transpiler.GnoRealmPkgsPrefixBefore) || + strings.HasPrefix(f.Module.Mod.Path, transpiler.GnoPackagePrefixBefore) { + f.AddModuleStmt(transpiler.ImportPrefix + "/examples/" + f.Module.Mod.Path) } for i := range f.Require { @@ -110,10 +111,10 @@ func GnoToGoMod(f File) (*File, error) { } } path := f.Require[i].Mod.Path - if strings.HasPrefix(f.Require[i].Mod.Path, gnolang.GnoRealmPkgsPrefixBefore) || - strings.HasPrefix(f.Require[i].Mod.Path, gnolang.GnoPackagePrefixBefore) { + if strings.HasPrefix(f.Require[i].Mod.Path, transpiler.GnoRealmPkgsPrefixBefore) || + strings.HasPrefix(f.Require[i].Mod.Path, transpiler.GnoPackagePrefixBefore) { // Add dependency with a modified import path - f.AddRequire(gnolang.ImportPrefix+"/examples/"+f.Require[i].Mod.Path, f.Require[i].Mod.Version) + f.AddRequire(transpiler.ImportPrefix+"/examples/"+f.Require[i].Mod.Path, f.Require[i].Mod.Version) } f.AddReplace(f.Require[i].Mod.Path, f.Require[i].Mod.Version, filepath.Join(gnoModPath, path), "") // Remove the old require since the new dependency was added above From 9409285591d21bddc3a9c6f7f0d1d6122d0843f4 Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Thu, 22 Feb 2024 14:17:00 +0100 Subject: [PATCH 2/3] move transpiler to pkg --- gno.land/pkg/gnoclient/client_txs.go | 2 +- gno.land/pkg/keyscli/addpkg.go | 2 +- gno.land/pkg/keyscli/run.go | 2 +- gnovm/cmd/gno/test.go | 2 +- .../testdata/{gno_precompile => gno_transpile}/01_no_args.txtar | 0 .../{gno_precompile => gno_transpile}/02_empty_dir.txtar | 0 .../03_gno_files_parse_error.txtar | 0 .../{gno_precompile => gno_transpile}/04_valid_gno_files.txtar | 0 .../{gno_precompile => gno_transpile}/05_skip_fmt_flag.txtar | 0 .../{gno_precompile => gno_transpile}/06_build_flag.txtar | 0 .../07_build_flag_with_build_error.txtar | 0 .../08_build_flag_with_parse_error.txtar | 0 .../09_gno_files_whitelist_error.txtar | 0 gnovm/cmd/gno/{precompile.go => transpile.go} | 2 +- gnovm/cmd/gno/{precompile_test.go => transpile_test.go} | 0 gnovm/cmd/gno/util.go | 2 +- gnovm/pkg/gnomod/file.go | 2 +- gnovm/pkg/gnomod/gnomod.go | 2 +- gnovm/pkg/{gnolang => }/transpiler/transpiler.go | 0 gnovm/pkg/{gnolang => }/transpiler/transpiler_test.go | 0 20 files changed, 8 insertions(+), 8 deletions(-) rename gnovm/cmd/gno/testdata/{gno_precompile => gno_transpile}/01_no_args.txtar (100%) rename gnovm/cmd/gno/testdata/{gno_precompile => gno_transpile}/02_empty_dir.txtar (100%) rename gnovm/cmd/gno/testdata/{gno_precompile => gno_transpile}/03_gno_files_parse_error.txtar (100%) rename gnovm/cmd/gno/testdata/{gno_precompile => gno_transpile}/04_valid_gno_files.txtar (100%) rename gnovm/cmd/gno/testdata/{gno_precompile => gno_transpile}/05_skip_fmt_flag.txtar (100%) rename gnovm/cmd/gno/testdata/{gno_precompile => gno_transpile}/06_build_flag.txtar (100%) rename gnovm/cmd/gno/testdata/{gno_precompile => gno_transpile}/07_build_flag_with_build_error.txtar (100%) rename gnovm/cmd/gno/testdata/{gno_precompile => gno_transpile}/08_build_flag_with_parse_error.txtar (100%) rename gnovm/cmd/gno/testdata/{gno_precompile => gno_transpile}/09_gno_files_whitelist_error.txtar (100%) rename gnovm/cmd/gno/{precompile.go => transpile.go} (99%) rename gnovm/cmd/gno/{precompile_test.go => transpile_test.go} (100%) rename gnovm/pkg/{gnolang => }/transpiler/transpiler.go (100%) rename gnovm/pkg/{gnolang => }/transpiler/transpiler_test.go (100%) diff --git a/gno.land/pkg/gnoclient/client_txs.go b/gno.land/pkg/gnoclient/client_txs.go index 34759b565e3..ece7507d569 100644 --- a/gno.land/pkg/gnoclient/client_txs.go +++ b/gno.land/pkg/gnoclient/client_txs.go @@ -2,7 +2,7 @@ package gnoclient import ( "github.com/gnolang/gno/gno.land/pkg/sdk/vm" - "github.com/gnolang/gno/gnovm/pkg/gnolang/transpiler" + "github.com/gnolang/gno/gnovm/pkg/transpiler" "github.com/gnolang/gno/tm2/pkg/amino" ctypes "github.com/gnolang/gno/tm2/pkg/bft/rpc/core/types" "github.com/gnolang/gno/tm2/pkg/crypto" diff --git a/gno.land/pkg/keyscli/addpkg.go b/gno.land/pkg/keyscli/addpkg.go index 82aef1315d4..1f89b2c2b82 100644 --- a/gno.land/pkg/keyscli/addpkg.go +++ b/gno.land/pkg/keyscli/addpkg.go @@ -7,7 +7,7 @@ import ( "github.com/gnolang/gno/gno.land/pkg/sdk/vm" gno "github.com/gnolang/gno/gnovm/pkg/gnolang" - "github.com/gnolang/gno/gnovm/pkg/gnolang/transpiler" + "github.com/gnolang/gno/gnovm/pkg/transpiler" "github.com/gnolang/gno/tm2/pkg/amino" "github.com/gnolang/gno/tm2/pkg/commands" "github.com/gnolang/gno/tm2/pkg/crypto/keys" diff --git a/gno.land/pkg/keyscli/run.go b/gno.land/pkg/keyscli/run.go index 3dd1879bcfa..6fcee7434eb 100644 --- a/gno.land/pkg/keyscli/run.go +++ b/gno.land/pkg/keyscli/run.go @@ -9,7 +9,7 @@ import ( "github.com/gnolang/gno/gno.land/pkg/sdk/vm" gno "github.com/gnolang/gno/gnovm/pkg/gnolang" - "github.com/gnolang/gno/gnovm/pkg/gnolang/transpiler" + "github.com/gnolang/gno/gnovm/pkg/transpiler" "github.com/gnolang/gno/tm2/pkg/amino" "github.com/gnolang/gno/tm2/pkg/commands" "github.com/gnolang/gno/tm2/pkg/crypto/keys" diff --git a/gnovm/cmd/gno/test.go b/gnovm/cmd/gno/test.go index 082e2066ff5..a02c1abf192 100644 --- a/gnovm/cmd/gno/test.go +++ b/gnovm/cmd/gno/test.go @@ -19,7 +19,7 @@ import ( "github.com/gnolang/gno/gnovm/pkg/gnoenv" gno "github.com/gnolang/gno/gnovm/pkg/gnolang" - "github.com/gnolang/gno/gnovm/pkg/gnolang/transpiler" + "github.com/gnolang/gno/gnovm/pkg/transpiler" "github.com/gnolang/gno/gnovm/pkg/gnomod" "github.com/gnolang/gno/gnovm/tests" "github.com/gnolang/gno/tm2/pkg/commands" diff --git a/gnovm/cmd/gno/testdata/gno_precompile/01_no_args.txtar b/gnovm/cmd/gno/testdata/gno_transpile/01_no_args.txtar similarity index 100% rename from gnovm/cmd/gno/testdata/gno_precompile/01_no_args.txtar rename to gnovm/cmd/gno/testdata/gno_transpile/01_no_args.txtar diff --git a/gnovm/cmd/gno/testdata/gno_precompile/02_empty_dir.txtar b/gnovm/cmd/gno/testdata/gno_transpile/02_empty_dir.txtar similarity index 100% rename from gnovm/cmd/gno/testdata/gno_precompile/02_empty_dir.txtar rename to gnovm/cmd/gno/testdata/gno_transpile/02_empty_dir.txtar diff --git a/gnovm/cmd/gno/testdata/gno_precompile/03_gno_files_parse_error.txtar b/gnovm/cmd/gno/testdata/gno_transpile/03_gno_files_parse_error.txtar similarity index 100% rename from gnovm/cmd/gno/testdata/gno_precompile/03_gno_files_parse_error.txtar rename to gnovm/cmd/gno/testdata/gno_transpile/03_gno_files_parse_error.txtar diff --git a/gnovm/cmd/gno/testdata/gno_precompile/04_valid_gno_files.txtar b/gnovm/cmd/gno/testdata/gno_transpile/04_valid_gno_files.txtar similarity index 100% rename from gnovm/cmd/gno/testdata/gno_precompile/04_valid_gno_files.txtar rename to gnovm/cmd/gno/testdata/gno_transpile/04_valid_gno_files.txtar diff --git a/gnovm/cmd/gno/testdata/gno_precompile/05_skip_fmt_flag.txtar b/gnovm/cmd/gno/testdata/gno_transpile/05_skip_fmt_flag.txtar similarity index 100% rename from gnovm/cmd/gno/testdata/gno_precompile/05_skip_fmt_flag.txtar rename to gnovm/cmd/gno/testdata/gno_transpile/05_skip_fmt_flag.txtar diff --git a/gnovm/cmd/gno/testdata/gno_precompile/06_build_flag.txtar b/gnovm/cmd/gno/testdata/gno_transpile/06_build_flag.txtar similarity index 100% rename from gnovm/cmd/gno/testdata/gno_precompile/06_build_flag.txtar rename to gnovm/cmd/gno/testdata/gno_transpile/06_build_flag.txtar diff --git a/gnovm/cmd/gno/testdata/gno_precompile/07_build_flag_with_build_error.txtar b/gnovm/cmd/gno/testdata/gno_transpile/07_build_flag_with_build_error.txtar similarity index 100% rename from gnovm/cmd/gno/testdata/gno_precompile/07_build_flag_with_build_error.txtar rename to gnovm/cmd/gno/testdata/gno_transpile/07_build_flag_with_build_error.txtar diff --git a/gnovm/cmd/gno/testdata/gno_precompile/08_build_flag_with_parse_error.txtar b/gnovm/cmd/gno/testdata/gno_transpile/08_build_flag_with_parse_error.txtar similarity index 100% rename from gnovm/cmd/gno/testdata/gno_precompile/08_build_flag_with_parse_error.txtar rename to gnovm/cmd/gno/testdata/gno_transpile/08_build_flag_with_parse_error.txtar diff --git a/gnovm/cmd/gno/testdata/gno_precompile/09_gno_files_whitelist_error.txtar b/gnovm/cmd/gno/testdata/gno_transpile/09_gno_files_whitelist_error.txtar similarity index 100% rename from gnovm/cmd/gno/testdata/gno_precompile/09_gno_files_whitelist_error.txtar rename to gnovm/cmd/gno/testdata/gno_transpile/09_gno_files_whitelist_error.txtar diff --git a/gnovm/cmd/gno/precompile.go b/gnovm/cmd/gno/transpile.go similarity index 99% rename from gnovm/cmd/gno/precompile.go rename to gnovm/cmd/gno/transpile.go index 7b32df556b5..b7708469e9d 100644 --- a/gnovm/cmd/gno/precompile.go +++ b/gnovm/cmd/gno/transpile.go @@ -10,7 +10,7 @@ import ( "os" "path/filepath" - "github.com/gnolang/gno/gnovm/pkg/gnolang/transpiler" + "github.com/gnolang/gno/gnovm/pkg/transpiler" "github.com/gnolang/gno/tm2/pkg/commands" ) diff --git a/gnovm/cmd/gno/precompile_test.go b/gnovm/cmd/gno/transpile_test.go similarity index 100% rename from gnovm/cmd/gno/precompile_test.go rename to gnovm/cmd/gno/transpile_test.go diff --git a/gnovm/cmd/gno/util.go b/gnovm/cmd/gno/util.go index c46e5d4e8f0..30d8f808d04 100644 --- a/gnovm/cmd/gno/util.go +++ b/gnovm/cmd/gno/util.go @@ -12,7 +12,7 @@ import ( "time" "github.com/gnolang/gno/gnovm/pkg/gnoenv" - "github.com/gnolang/gno/gnovm/pkg/gnolang/transpiler" + "github.com/gnolang/gno/gnovm/pkg/transpiler" ) func isGnoFile(f fs.DirEntry) bool { diff --git a/gnovm/pkg/gnomod/file.go b/gnovm/pkg/gnomod/file.go index d1dff4ee816..fda9263914e 100644 --- a/gnovm/pkg/gnomod/file.go +++ b/gnovm/pkg/gnomod/file.go @@ -17,7 +17,7 @@ import ( "path/filepath" "strings" - "github.com/gnolang/gno/gnovm/pkg/gnolang/transpiler" + "github.com/gnolang/gno/gnovm/pkg/transpiler" "golang.org/x/mod/modfile" "golang.org/x/mod/module" ) diff --git a/gnovm/pkg/gnomod/gnomod.go b/gnovm/pkg/gnomod/gnomod.go index 54a30df73dd..af946f2bf39 100644 --- a/gnovm/pkg/gnomod/gnomod.go +++ b/gnovm/pkg/gnomod/gnomod.go @@ -9,7 +9,7 @@ import ( "github.com/gnolang/gno/gnovm/pkg/gnoenv" "github.com/gnolang/gno/gnovm/pkg/gnolang" - "github.com/gnolang/gno/gnovm/pkg/gnolang/transpiler" + "github.com/gnolang/gno/gnovm/pkg/transpiler" "github.com/gnolang/gno/tm2/pkg/std" "golang.org/x/mod/modfile" "golang.org/x/mod/module" diff --git a/gnovm/pkg/gnolang/transpiler/transpiler.go b/gnovm/pkg/transpiler/transpiler.go similarity index 100% rename from gnovm/pkg/gnolang/transpiler/transpiler.go rename to gnovm/pkg/transpiler/transpiler.go diff --git a/gnovm/pkg/gnolang/transpiler/transpiler_test.go b/gnovm/pkg/transpiler/transpiler_test.go similarity index 100% rename from gnovm/pkg/gnolang/transpiler/transpiler_test.go rename to gnovm/pkg/transpiler/transpiler_test.go From 37c9e6690b64703670a9049191a7504cd6027fab Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Thu, 22 Feb 2024 21:15:29 +0100 Subject: [PATCH 3/3] fixup --- .github/workflows/examples.yml | 2 +- docs/getting-started/local-setup.md | 2 +- gnovm/cmd/gno/test.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index e5178c3e4c2..53d6a58abdd 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -32,7 +32,7 @@ jobs: with: go-version: ${{ matrix.goversion }} - run: go install -v ./gnovm/cmd/gno - - run: go run ./gnovm/cmd/gno precompile --verbose --gobuild ./examples + - run: go run ./gnovm/cmd/gno transpile --verbose --gobuild ./examples test: strategy: fail-fast: false diff --git a/docs/getting-started/local-setup.md b/docs/getting-started/local-setup.md index cbef4522477..753b6688b1a 100644 --- a/docs/getting-started/local-setup.md +++ b/docs/getting-started/local-setup.md @@ -28,7 +28,7 @@ git clone https://github.com/gnolang/gno.git ## 2. Installing the `gno` development toolkit Next, we are going to build and install the `gno` development toolkit. -`gno` provides ample functionality to the user, among which is running, precompiling, testing and building `.gno` files. +`gno` provides ample functionality to the user, among which is running, transpiling, testing and building `.gno` files. To install the toolkit, navigate to the `gnovm` folder from the repository root, and run the `build` make directive: diff --git a/gnovm/cmd/gno/test.go b/gnovm/cmd/gno/test.go index a02c1abf192..ca64227aada 100644 --- a/gnovm/cmd/gno/test.go +++ b/gnovm/cmd/gno/test.go @@ -19,8 +19,8 @@ import ( "github.com/gnolang/gno/gnovm/pkg/gnoenv" gno "github.com/gnolang/gno/gnovm/pkg/gnolang" - "github.com/gnolang/gno/gnovm/pkg/transpiler" "github.com/gnolang/gno/gnovm/pkg/gnomod" + "github.com/gnolang/gno/gnovm/pkg/transpiler" "github.com/gnolang/gno/gnovm/tests" "github.com/gnolang/gno/tm2/pkg/commands" "github.com/gnolang/gno/tm2/pkg/errors"