blob: 49aed3338b9b2f300901e87fdf4c90c96f033858 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# 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
20from bb.utils import better_compile, better_exec
21
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050022def insert_method(modulename, code, fn, lineno):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050023 """
24 Add code of a module should be added. The methods
25 will be simply added, no checking will be done
26 """
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050027 comp = better_compile(code, modulename, fn, lineno=lineno)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050028 better_exec(comp, None, code, fn)
29
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050030compilecache = {}
31
32def compile_cache(code):
33 h = hash(code)
34 if h in compilecache:
35 return compilecache[h]
36 return None
37
38def compile_cache_add(code, compileobj):
39 h = hash(code)
40 compilecache[h] = compileobj