Skip to content

Commit

Permalink
fix: 增加一种特殊函数调用参数
Browse files Browse the repository at this point in the history
  • Loading branch information
fy0 committed Jun 15, 2024
1 parent c51045e commit 7df6d72
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions rollvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewVM() *Context {
}

// RunExpr 注: 最后不一定叫这个名字,这个函数作用是,即使当前vm被占用,也能执行语句,是为了指令hack而服务的
func (ctx *Context) RunExpr(value string) (*VMValue, error) {
func (ctx *Context) RunExpr(value string, useUpCtxLocal bool) (*VMValue, error) {
val := NewFunctionValRaw(&FunctionData{
Expr: value,
Name: "",
Expand All @@ -43,7 +43,7 @@ func (ctx *Context) RunExpr(value string) (*VMValue, error) {
codeIndex: 0,
})

v := val.FuncInvoke(ctx, nil)
v := val.FuncInvokeRaw(ctx, nil, useUpCtxLocal)
return v, ctx.Error
}

Expand Down
14 changes: 12 additions & 2 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1430,11 +1430,19 @@ func (v *VMValue) ComputedExecute(ctx *Context) *VMValue {
}

func (v *VMValue) FuncInvoke(ctx *Context, params []*VMValue) *VMValue {
return v.FuncInvokeRaw(ctx, params, false)
}

func (v *VMValue) FuncInvokeRaw(ctx *Context, params []*VMValue, useUpCtxLocal bool) *VMValue {
// TODO: 先复制computed代码修改,后续重构

vm := NewVM()
cd, _ := v.ReadFunctionData()
vm.Attrs = &ValueMap{}
if useUpCtxLocal {
vm.Attrs = ctx.Attrs
} else {
vm.Attrs = &ValueMap{}
}

// 设置参数
if len(cd.Params) != len(params) {
Expand Down Expand Up @@ -1487,7 +1495,9 @@ func (v *VMValue) FuncInvoke(ctx *Context, params []*VMValue) *VMValue {
}

ctx.NumOpCount = vm.NumOpCount
vm.Attrs = &ValueMap{} // 清空
if !useUpCtxLocal {
vm.Attrs = &ValueMap{} // 清空
}
return ret
}

Expand Down

0 comments on commit 7df6d72

Please sign in to comment.