From 1a0c74388e18747436d2afd61c1307a521be77d7 Mon Sep 17 00:00:00 2001 From: Emil Valeev Date: Sun, 18 Feb 2024 23:52:16 +0600 Subject: [PATCH] feat(manifest, cli): bump compiler version to 0.4.0; rename compiler->neva in manifesto; refactor --- cmd/neva/cli.go | 10 ++++++++++ examples/neva.yml | 2 +- internal/compiler/analyzer/analyzer.go | 4 ++-- internal/compiler/desugarer/desugarer.go | 4 ++-- internal/compiler/desugarer/desugarer_test.go | 4 ++-- internal/compiler/parser/manifest.go | 4 ++-- internal/pkgmanager/tests/intergration_test.go | 2 +- internal/pkgmanager/tests/testmod/neva.yml | 2 +- pkg/sourcecode/sourcecode.go | 4 ++-- pkg/version.go | 4 ++++ scripts/install.sh | 3 ++- std/neva.yml | 2 +- 12 files changed, 30 insertions(+), 15 deletions(-) create mode 100644 pkg/version.go diff --git a/cmd/neva/cli.go b/cmd/neva/cli.go index ec1bab4c..95006113 100644 --- a/cmd/neva/cli.go +++ b/cmd/neva/cli.go @@ -3,10 +3,12 @@ package main import ( "context" "errors" + "fmt" "path/filepath" "strings" "github.com/nevalang/neva/internal/interpreter" + "github.com/nevalang/neva/pkg" cli "github.com/urfave/cli/v2" ) @@ -46,6 +48,14 @@ func newApp(intr interpreter.Interpreter, wd string) *cli.App { panic("not implemented") }, }, + { + Name: "version", + Usage: "Get current Nevalang version", + Action: func(cCtx *cli.Context) error { + fmt.Println(pkg.Version) + return nil + }, + }, }, } } diff --git a/examples/neva.yml b/examples/neva.yml index 58a8dfb4..c2b436af 100644 --- a/examples/neva.yml +++ b/examples/neva.yml @@ -2,7 +2,7 @@ # They not only serve documentation purposes, they are also # e2e tests that you can manually run to ensure that Nevalang works. -compiler: 0.0.1 +neva: 0.4.0 deps: - path: github.com/nevalang/x diff --git a/internal/compiler/analyzer/analyzer.go b/internal/compiler/analyzer/analyzer.go index dfb02081..d00cc3ba 100644 --- a/internal/compiler/analyzer/analyzer.go +++ b/internal/compiler/analyzer/analyzer.go @@ -71,12 +71,12 @@ func (a Analyzer) AnalyzeBuild(build src.Build) (src.Build, *compiler.Error) { analyzedMods := make(map[src.ModuleRef]src.Module, len(build.Modules)) for modRef, mod := range build.Modules { - if mod.Manifest.WantCompilerVersion != a.compilerVersion { + if mod.Manifest.LanguageVersion != a.compilerVersion { return src.Build{}, &compiler.Error{ Err: fmt.Errorf( "%w: module %v wants %v while current is %v", ErrCompilerVersion, - modRef, mod.Manifest.WantCompilerVersion, a.compilerVersion, + modRef, mod.Manifest.LanguageVersion, a.compilerVersion, ), } } diff --git a/internal/compiler/desugarer/desugarer.go b/internal/compiler/desugarer/desugarer.go index 3798eb03..526d2241 100644 --- a/internal/compiler/desugarer/desugarer.go +++ b/internal/compiler/desugarer/desugarer.go @@ -37,8 +37,8 @@ func (d Desugarer) desugarModule(build src.Build, modRef src.ModuleRef) (src.Mod // create manifest copy with std module dependency desugaredManifest := src.ModuleManifest{ - WantCompilerVersion: mod.Manifest.WantCompilerVersion, - Deps: make(map[string]src.ModuleRef, len(mod.Manifest.Deps)+1), + LanguageVersion: mod.Manifest.LanguageVersion, + Deps: make(map[string]src.ModuleRef, len(mod.Manifest.Deps)+1), } maps.Copy(desugaredManifest.Deps, mod.Manifest.Deps) desugaredManifest.Deps["std"] = src.ModuleRef{Path: "std", Version: "0.0.1"} // TODO rethink stdlib diff --git a/internal/compiler/desugarer/desugarer_test.go b/internal/compiler/desugarer/desugarer_test.go index 0fb57e87..aeb9c944 100644 --- a/internal/compiler/desugarer/desugarer_test.go +++ b/internal/compiler/desugarer/desugarer_test.go @@ -23,7 +23,7 @@ func TestDesugarer_Desugar(t *testing.T) { build: src.Build{ Modules: map[src.ModuleRef]src.Module{ {}: { - Manifest: src.ModuleManifest{WantCompilerVersion: "0.0.1"}, + Manifest: src.ModuleManifest{LanguageVersion: "0.0.1"}, Packages: map[string]src.Package{ "main": { "file": src.File{ @@ -64,7 +64,7 @@ func TestDesugarer_Desugar(t *testing.T) { Modules: map[src.ModuleRef]src.Module{ {}: { Manifest: src.ModuleManifest{ - WantCompilerVersion: "0.0.1", + LanguageVersion: "0.0.1", Deps: map[string]src.ModuleRef{ "std": { // <-- stdlib mod dep added Path: "std", diff --git a/internal/compiler/parser/manifest.go b/internal/compiler/parser/manifest.go index 8ccd612e..fd34f0ae 100644 --- a/internal/compiler/parser/manifest.go +++ b/internal/compiler/parser/manifest.go @@ -42,7 +42,7 @@ func manifestToSourceCode(manifest Manifest) src.ModuleManifest { } } return src.ModuleManifest{ - WantCompilerVersion: manifest.WantCompilerVersion, - Deps: deps, + LanguageVersion: manifest.WantCompilerVersion, + Deps: deps, } } diff --git a/internal/pkgmanager/tests/intergration_test.go b/internal/pkgmanager/tests/intergration_test.go index 94194baa..3cf99243 100644 --- a/internal/pkgmanager/tests/intergration_test.go +++ b/internal/pkgmanager/tests/intergration_test.go @@ -19,7 +19,7 @@ func TestPkgManager(t *testing.T) { mod, ok := build.Modules[build.EntryModRef] require.True(t, ok) require.Len(t, mod.Packages, 1) - require.Equal(t, mod.Manifest.WantCompilerVersion, "0.0.1") + require.Equal(t, mod.Manifest.LanguageVersion, "0.0.1") pkg, ok := mod.Packages["do_nothing"] require.True(t, ok) diff --git a/internal/pkgmanager/tests/testmod/neva.yml b/internal/pkgmanager/tests/testmod/neva.yml index c14c3e92..e6264672 100644 --- a/internal/pkgmanager/tests/testmod/neva.yml +++ b/internal/pkgmanager/tests/testmod/neva.yml @@ -1 +1 @@ -compiler: 0.0.1 \ No newline at end of file +neva: 0.4.0 \ No newline at end of file diff --git a/pkg/sourcecode/sourcecode.go b/pkg/sourcecode/sourcecode.go index 492131b7..9b01b2a3 100644 --- a/pkg/sourcecode/sourcecode.go +++ b/pkg/sourcecode/sourcecode.go @@ -40,8 +40,8 @@ func (mod Module) Files(f func(file File, pkgName, fileName string)) { } type ModuleManifest struct { - WantCompilerVersion string `json:"compiler,omitempty" yaml:"compiler,omitempty"` - Deps map[string]ModuleRef `json:"deps,omitempty" yaml:"deps,omitempty"` + LanguageVersion string `json:"neva,omitempty" yaml:"neva,omitempty"` + Deps map[string]ModuleRef `json:"deps,omitempty" yaml:"deps,omitempty"` } type ModuleRef struct { diff --git a/pkg/version.go b/pkg/version.go new file mode 100644 index 00000000..e2cefdb3 --- /dev/null +++ b/pkg/version.go @@ -0,0 +1,4 @@ +package pkg + +// Current version of the language +var Version = "0.4.0" diff --git a/scripts/install.sh b/scripts/install.sh index e494bea9..0e2cc060 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -1,6 +1,7 @@ #!/bin/bash -BIN_URL="https://github.com/nevalang/neva/releases/download/v0.3.0/neva" +LATEST_TAG=$(curl -s https://api.github.com/repos/nevalang/neva/releases/latest | grep "tag_name" | cut -d '"' -f 4) +BIN_URL="https://github.com/nevalang/neva/releases/download/$LATEST_TAG/neva" INSTALL_DIR="/usr/local/bin" BIN_NAME="neva" diff --git a/std/neva.yml b/std/neva.yml index eb5401c7..1440bd74 100644 --- a/std/neva.yml +++ b/std/neva.yml @@ -1 +1 @@ -compiler: 0.0.1 +neva: 0.4.0