context.go: setVar() renamed as UnsafeSetVar()

This commit is contained in:
Celestino Amoroso 2024-05-19 01:27:44 +02:00
parent 9bd4a0ba23
commit 4d43ab2c2f
7 changed files with 11 additions and 11 deletions

4
ast.go
View File

@ -119,7 +119,7 @@ func (self *ast) eval(ctx ExprContext, preset bool) (result any, err error) {
if self.forest != nil {
for _, root := range self.forest {
if result, err = root.compute(ctx); err == nil {
ctx.setVar(ControlLastResult, result)
ctx.UnsafeSetVar(ControlLastResult, result)
} else {
//err = fmt.Errorf("error in expression nr %d: %v", i+1, err)
break
@ -128,7 +128,7 @@ func (self *ast) eval(ctx ExprContext, preset bool) (result any, err error) {
}
if err == nil {
result, err = self.root.compute(ctx)
ctx.setVar(ControlLastResult, result)
ctx.UnsafeSetVar(ControlLastResult, result)
}
// } else {
// err = errors.New("empty expression")

View File

@ -15,7 +15,7 @@ func exportVar(ctx ExprContext, name string, value any) {
if name[0] == '@' {
name = name[1:]
}
ctx.setVar(name, value)
ctx.UnsafeSetVar(name, value)
}
func exportFunc(ctx ExprContext, name string, info ExprFunc) {

View File

@ -33,7 +33,7 @@ type ExprContext interface {
Clone() ExprContext
GetVar(varName string) (value any, exists bool)
SetVar(varName string, value any)
setVar(varName string, value any)
UnsafeSetVar(varName string, value any)
EnumVars(func(name string) (accept bool)) (varNames []string)
EnumFuncs(func(name string) (accept bool)) (funcNames []string)
GetFuncInfo(name string) (item ExprFunc, exists bool)

View File

@ -87,10 +87,10 @@ func (functor *funcDefFunctor) Invoke(ctx ExprContext, name string, args []any)
if functor, ok := arg.(Functor); ok {
ctx.RegisterFunc(p, functor, 0, -1)
} else {
ctx.setVar(p, arg)
ctx.UnsafeSetVar(p, arg)
}
} else {
ctx.setVar(p, nil)
ctx.UnsafeSetVar(p, nil)
}
}
result, err = functor.expr.eval(ctx, false)

View File

@ -44,7 +44,7 @@ func evalAssign(ctx ExprContext, self *term) (v any, err error) {
}
ctx.RegisterFunc(leftTerm.source(), functor, minArgs, maxArgs)
} else {
ctx.setVar(leftTerm.source(), v)
ctx.UnsafeSetVar(leftTerm.source(), v)
}
}
return

View File

@ -75,7 +75,7 @@ func evalAssignCoalesce(ctx ExprContext, self *term) (v any, err error) {
ctx.RegisterFunc(leftTerm.source(), functor, 0, -1)
} else {
v = rightValue
ctx.setVar(leftTerm.source(), rightValue)
ctx.UnsafeSetVar(leftTerm.source(), rightValue)
}
}
return

View File

@ -36,7 +36,7 @@ func (ctx *SimpleVarStore) GetVar(varName string) (v any, exists bool) {
return
}
func (ctx *SimpleVarStore) setVar(varName string, value any) {
func (ctx *SimpleVarStore) UnsafeSetVar(varName string, value any) {
// fmt.Printf("[%p] setVar(%v, %v)\n", ctx, varName, value)
ctx.varStore[varName] = value
}
@ -98,8 +98,8 @@ func varsCtxToBuilder(sb *strings.Builder, ctx ExprContext, indent int) {
sb.WriteString(f.ToString(0))
} else if _, ok = value.(Functor); ok {
sb.WriteString("func(){}")
} else if _, ok = value.(map[any]any); ok {
sb.WriteString("dict{}")
// } else if _, ok = value.(map[any]any); ok {
// sb.WriteString("dict{}")
} else {
sb.WriteString(fmt.Sprintf("%v", value))
}