Skip to content

Commit

Permalink
fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
harry-hov committed Mar 12, 2024
1 parent b7c36c4 commit 1286a4a
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 23 deletions.
4 changes: 2 additions & 2 deletions examples/gno.land/r/demo/tests/tests_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func TestAssertOriginCall(t *testing.T) {

func TestPrevRealm(t *testing.T) {
var (
user1Addr = std.DerivePkgAddr("user1.gno")
rTestsAddr = std.DerivePkgAddr("gno.land/r/demo/tests")
user1Addr = std.DerivePkgAddr("user1.gno", "")
rTestsAddr = std.DerivePkgAddr("gno.land/r/demo/tests", "v0.0.1")
)
// When a single realm in the frames, PrevRealm returns the user
if addr := GetPrevRealm().Addr(); addr != user1Addr {
Expand Down
1 change: 1 addition & 0 deletions gnovm/cmd/gno/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func execLint(cfg *lintCfg, args []string, io commands.IO) error {
}
}

// TODO(hariom): gno lint is failing because of this?
tm.RunFiles(testfiles.Files...)
})

Expand Down
8 changes: 4 additions & 4 deletions gnovm/pkg/gnolang/gno_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
func TestRunEmptyMain(t *testing.T) {
t.Parallel()

m := NewMachine("test", nil)
m := NewMachine("test", "", nil)
// []Stmt{} != nil, as nil means that in the source code not even the
// brackets are present and is reserved for external (ie. native) functions.
main := FuncD("main", nil, nil, []Stmt{})
Expand All @@ -33,7 +33,7 @@ func TestRunEmptyMain(t *testing.T) {
func TestRunLoopyMain(t *testing.T) {
t.Parallel()

m := NewMachine("test", nil)
m := NewMachine("test", "", nil)
c := `package test
func main() {
for i:=0; i<1000; i++ {
Expand All @@ -48,7 +48,7 @@ func main() {
}

func TestDoOpEvalBaseConversion(t *testing.T) {
m := NewMachine("test", nil)
m := NewMachine("test", "", nil)

type testCase struct {
input string
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestDoOpEvalBaseConversion(t *testing.T) {
func TestEval(t *testing.T) {
t.Parallel()

m := NewMachine("test", nil)
m := NewMachine("test", "", nil)
c := `package test
func next(i int) int {
return i+1
Expand Down
13 changes: 8 additions & 5 deletions gnovm/pkg/gnolang/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ type Machine struct {
//
// Like for [NewMachineWithOptions], Machines initialized through this
// constructor must be finalized with [Machine.Release].
func NewMachine(pkgPath string, store Store) *Machine {
func NewMachine(pkgPath, pkgVersion string, store Store) *Machine {
return NewMachineWithOptions(
MachineOptions{
PkgPath: pkgPath,
Store: store,
PkgPath: pkgPath,
PkgVersion: pkgVersion,
Store: store,
})
}

Expand Down Expand Up @@ -251,9 +252,11 @@ func (m *Machine) runMemPackage(memPkg *std.MemPackage, save, overrides bool) (*
// make and set package if doesn't exist.
pn := (*PackageNode)(nil)
pv := (*PackageValue)(nil)
// panic("stop: " + memPkg.ModFile.ImportPath + " " + memPkg.ModFile.Version)
if m.Package != nil &&
m.Package.ModFile.Path == memPkg.ModFile.ImportPath &&
m.Package.ModFile.Version == memPkg.ModFile.Version {
m.Package.ModFile.Path == memPkg.ModFile.ImportPath {
// m.Package.ModFile.Version == memPkg.ModFile.Version {
fmt.Println()
pv = m.Package
loc := PackageNodeLocation(memPkg.ModFile.ImportPath, memPkg.ModFile.Version)
pn = m.Store.GetBlockNode(loc).(*PackageNode)
Expand Down
2 changes: 1 addition & 1 deletion gnovm/pkg/gnolang/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestRunMemPackageWithOverrides_revertToOld(t *testing.T) {
baseStore := dbadapter.StoreConstructor(db, stypes.StoreOptions{})
iavlStore := iavl.StoreConstructor(db, stypes.StoreOptions{})
store := NewStore(nil, baseStore, iavlStore)
m := NewMachine("std", store)
m := NewMachine("std", "", store)
m.RunMemPackageWithOverrides(&std.MemPackage{
Name: "std",
ModFile: &std.MemMod{
Expand Down
2 changes: 1 addition & 1 deletion gnovm/pkg/gnolang/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,7 @@ func (x *PackageNode) NewPackage() *PackageValue {
Source: x,
},
PkgName: x.PkgName,
ModFile: x.ModFile,
ModFile: x.ModFile.Copy(),
FNames: nil,
FBlocks: nil,
fBlocksMap: make(map[Name]*Block),
Expand Down
20 changes: 12 additions & 8 deletions gnovm/pkg/gnolang/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -2028,7 +2028,7 @@ func evalStaticType(store Store, last BlockNode, x Expr) Type {
store = store.Fork()
store.SetCachePackage(pv)
}
m := NewMachine(pn.ModFile.Path, store)
m := NewMachine(pn.ModFile.Path, pn.ModFile.Version, store)
tv := m.EvalStatic(last, x)
m.Release()
if _, ok := tv.V.(TypeValue); !ok {
Expand Down Expand Up @@ -2102,7 +2102,7 @@ func evalStaticTypeOfRaw(store Store, last BlockNode, x Expr) (t Type) {
store = store.Fork()
store.SetCachePackage(pv)
}
m := NewMachine(pn.ModFile.Path, store)
m := NewMachine(pn.ModFile.Path, pn.ModFile.Version, store)
t = m.EvalStaticTypeOf(last, x)
m.Release()
x.SetAttribute(ATTR_TYPEOF_VALUE, t)
Expand Down Expand Up @@ -2198,7 +2198,7 @@ func getResultTypedValues(cx *CallExpr) []TypedValue {
func evalConst(store Store, last BlockNode, x Expr) *ConstExpr {
// TODO: some check or verification for ensuring x
// is constant? From the machine?
cv := NewMachine(".dontcare", store)
cv := NewMachine(".dontcare", "", store)
tv := cv.EvalStatic(last, x)
cv.Release()
cx := &ConstExpr{
Expand Down Expand Up @@ -3044,11 +3044,15 @@ func tryPredefine(store Store, last BlockNode, d Decl) (un Name) {
break
}
}
if version == "" {
panic(fmt.Sprintf(
"cannot get version for package %s",
d.PkgPath))
}
// TODO(hariom): uncomment?
// It may cause problems in few cases
// - If package doen't contain gno.mod
// - Testing _filetest. Currently imports are covered by gno.mod
// if version == "" {
// panic(fmt.Sprintf(
// "cannot get version for package %s",
// d.PkgPath))
// }
}

// TODO(hariom): create helper
Expand Down
2 changes: 1 addition & 1 deletion gnovm/pkg/gnolang/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2530,7 +2530,7 @@ func applySpecifics(lookup map[Name]Type, tmpl Type) (Type, bool) {
gx := MustParseExpr(string(generic))
gx = Preprocess(nil, bs, gx).(Expr)
// Evaluate type from generic expression.
m := NewMachine("", nil)
m := NewMachine("", "", nil)
tv := m.EvalStatic(bs, gx)
m.Release()
if isElem {
Expand Down
2 changes: 1 addition & 1 deletion gnovm/pkg/gnolang/uverse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func TestIssue1337PrintNilSliceAsUndefined(t *testing.T) {

for _, tc := range test {
t.Run(tc.name, func(t *testing.T) {
m := NewMachine("test", nil)
m := NewMachine("test", "", nil)
n := MustParseFile("main.go", tc.code)
m.RunFiles(n)
m.RunMain()
Expand Down
1 change: 1 addition & 0 deletions gnovm/tests/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ func RunFileTest(rootDir string, path string, opts ...RunFileTestOption) error {
Name: string(pkgName),
ModFile: &std.MemMod{
ImportPath: pkgPath,
Version: pkgVersion,
},
Files: []*std.MemFile{
{
Expand Down

0 comments on commit 1286a4a

Please sign in to comment.