MCPcopy
hub / github.com/expr-lang/expr / addFunction

Method addFunction

compiler/compiler.go:193–205  ·  view source on GitHub ↗

addFunction adds builtin.Function.Func to the program.functions and returns its index.

(name string, fn Function)

Source from the content-addressed store, hash-verified

191
192// addFunction adds builtin.Function.Func to the program.functions and returns its index.
193func (c *compiler) addFunction(name string, fn Function) int {
194 if fn == nil {
195 panic("function is nil")
196 }
197 if p, ok := c.functionsIndex[name]; ok {
198 return p
199 }
200 p := len(c.functions)
201 c.functions = append(c.functions, fn)
202 c.functionsIndex[name] = p
203 c.debugInfo[fmt.Sprintf("func_%d", p)] = name
204 return p
205}
206
207func (c *compiler) patchJump(placeholder int) {
208 offset := len(c.bytecode) - placeholder

Callers 1

emitFunctionMethod · 0.95

Calls 1

SprintfMethod · 0.80

Tested by

no test coverage detected