addFunction adds builtin.Function.Func to the program.functions and returns its index.
(name string, fn Function)
| 191 | |
| 192 | // addFunction adds builtin.Function.Func to the program.functions and returns its index. |
| 193 | func (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 | |
| 207 | func (c *compiler) patchJump(placeholder int) { |
| 208 | offset := len(c.bytecode) - placeholder |