Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # |
| 2 | # Copyright (C) 2006 Holger Hans Peter Freyther |
| 3 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 4 | # SPDX-License-Identifier: GPL-2.0-only |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6 | |
| 7 | from bb.utils import better_compile, better_exec |
| 8 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 9 | def insert_method(modulename, code, fn, lineno): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10 | """ |
| 11 | Add code of a module should be added. The methods |
| 12 | will be simply added, no checking will be done |
| 13 | """ |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 14 | comp = better_compile(code, modulename, fn, lineno=lineno) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 15 | better_exec(comp, None, code, fn) |
| 16 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 17 | compilecache = {} |
| 18 | |
| 19 | def compile_cache(code): |
| 20 | h = hash(code) |
| 21 | if h in compilecache: |
| 22 | return compilecache[h] |
| 23 | return None |
| 24 | |
| 25 | def compile_cache_add(code, compileobj): |
| 26 | h = hash(code) |
| 27 | compilecache[h] = compileobj |