Skip to content

Commit

Permalink
fix: 修正IsComputedLoaded标记不准确问题
Browse files Browse the repository at this point in the history
  • Loading branch information
fy0 committed Jun 22, 2024
1 parent d8f4e4a commit 4708cf7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
39 changes: 39 additions & 0 deletions rollvm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,45 @@ func TestIsDiceCalculateExists(t *testing.T) {
if assert.NoError(t, err) {
assert.False(t, vm.IsCalculateExists())
}

err = vm.Parse("1+2")
if assert.NoError(t, err) {
assert.True(t, vm.IsCalculateExists())
}

err = vm.Parse("f()")
if assert.NoError(t, err) {
assert.True(t, vm.IsCalculateExists())
}
}

func TestIsDiceCalculateExists2(t *testing.T) {
vm := NewVM()
assert.Equal(t, vm.IsComputedLoaded, false)
err := vm.Run("&a=4d1; a")
if assert.NoError(t, err) {
assert.Equal(t, vm.IsComputedLoaded, true)
}

err = vm.Run("1+1")
if assert.NoError(t, err) {
assert.Equal(t, vm.IsComputedLoaded, false)
}
}

func TestIsDiceCalculateExists3(t *testing.T) {
vm := NewVM()
vm.GlobalValueLoadFunc = func(name string) *VMValue {
if name == "a" {
return NewComputedVal("4d1")
}
return nil
}
err := vm.Run("a")
if assert.NoError(t, err) {
assert.True(t, valueEqual(ni(4), vm.Ret))
assert.Equal(t, vm.IsComputedLoaded, true)
}
}

func TestDiceExprIndexBug(t *testing.T) {
Expand Down
9 changes: 2 additions & 7 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ func (ctx *Context) LoadNameLocal(name string, isRaw bool) *VMValue {
}
if !isRaw && ret.TypeId == VMTypeComputedValue {
ret = ret.ComputedExecute(ctx)
ctx.IsComputedLoaded = true
if ctx.Error != nil {
return nil
}
Expand Down Expand Up @@ -1444,9 +1443,7 @@ func (v *VMValue) ComputedExecute(ctx *Context) *VMValue {
}

ctx.NumOpCount = vm.NumOpCount
if vm.IsComputedLoaded {
ctx.IsComputedLoaded = true
}
ctx.IsComputedLoaded = true
return ret
}

Expand Down Expand Up @@ -1519,9 +1516,7 @@ func (v *VMValue) FuncInvokeRaw(ctx *Context, params []*VMValue, useUpCtxLocal b
if !useUpCtxLocal {
vm.Attrs = &ValueMap{} // 清空
}
if vm.IsComputedLoaded {
ctx.IsComputedLoaded = true
}
ctx.IsComputedLoaded = true
return ret
}

Expand Down

0 comments on commit 4708cf7

Please sign in to comment.