Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # ex:ts=4:sw=4:sts=4:et |
| 2 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- |
| 3 | # |
| 4 | # |
| 5 | # Copyright (C) 2006 Holger Hans Peter Freyther |
| 6 | # |
| 7 | # This program is free software; you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License version 2 as |
| 9 | # published by the Free Software Foundation. |
| 10 | # |
| 11 | # This program is distributed in the hope that it will be useful, |
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | # GNU General Public License for more details. |
| 15 | # |
| 16 | # You should have received a copy of the GNU General Public License along |
| 17 | # with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | |
| 20 | from bb.utils import better_compile, better_exec |
| 21 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame^] | 22 | def insert_method(modulename, code, fn, lineno): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 23 | """ |
| 24 | Add code of a module should be added. The methods |
| 25 | will be simply added, no checking will be done |
| 26 | """ |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame^] | 27 | comp = better_compile(code, modulename, fn, lineno=lineno) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 28 | better_exec(comp, None, code, fn) |
| 29 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame^] | 30 | compilecache = {} |
| 31 | |
| 32 | def compile_cache(code): |
| 33 | h = hash(code) |
| 34 | if h in compilecache: |
| 35 | return compilecache[h] |
| 36 | return None |
| 37 | |
| 38 | def compile_cache_add(code, compileobj): |
| 39 | h = hash(code) |
| 40 | compilecache[h] = compileobj |