def record_const(self, value, type_ = None, retval='name'): if type_ is None: type_ = typeOf(value) if self.is_primitive(type_): return None const = AbstractConst.make(self, value) if not const: return None try: if retval == 'name': return self.consts[const] else: self.consts[const] return self.reverse_consts[self.consts[const]] except KeyError: if self.genoo.config.translation.verbose: log("New const:%r"%value) if isinstance(value, ootype._string): log(value._str) else: log.dot() name = const.get_name() if name in self.const_names: name += '__%d' % len(self.consts) self.consts[const] = name self.reverse_consts[name] = const self.const_names.add(name) self.pending_consts.append((const,name)) if retval == 'name': return name else: return const
def record_const(self, value, type_=None, retval='name'): if type_ is None: type_ = typeOf(value) if self.is_primitive(type_): return None const = AbstractConst.make(self, value) if not const: return None try: if retval == 'name': return self.consts[const] else: self.consts[const] return self.reverse_consts[self.consts[const]] except KeyError: if self.genoo.config.translation.verbose: log("New const:%r" % value) if isinstance(value, ootype._string): log(value._str) else: log.dot() name = const.get_name() if name in self.const_names: name += '__%d' % len(self.consts) self.consts[const] = name self.reverse_consts[name] = const self.const_names.add(name) self.pending_consts.append((const, name)) if retval == 'name': return name else: return const
def do_GET(self): global do_status if self.path != "/test.html": self.send_error(404, "File /test.html not found") return jsfilename = jstest.jsfilename jstestcase = jstest.jstestcase jscode = jstest.jscode if self.server.html_page: if self.server.is_interactive: isinteractive = '' else: isinteractive = 'resultform.submit();' try: html_page = open(self.server.html_page).read() % locals() except IOError: log("HTML FILE WAS NOT FOUND!!!!") self.send_error(404, "File %s not found" % self.server.html_page) return else: html_page = config.html_page % locals() open("html_page.html", "w").write(html_page) self.serve_data('text/html', html_page) do_status = 'do_GET'
def gen_constants(self, ilasm, pending): try: while True: const, name = self.pending_consts.pop() const.record_fields() except IndexError: pass if pending: return if not self.rendered: ilasm.begin_consts(self.const_var.name) def generate_constants(consts): all_c = [const for const, name in consts.iteritems()] dep_ok = set() while len(all_c) > 0: const = all_c.pop() if const not in self.rendered: to_render = True if hasattr(const, 'depends_on') and const.depends_on: for i in const.depends_on: if i not in self.rendered and i not in dep_ok: assert i.depends is None or const in i.depends to_render = False continue if to_render and (not hasattr(const, 'depends')) or ( not const.depends) or const in dep_ok: yield const, consts[const] self.rendered.add(const) else: all_c.append(const) for i in const.depends: all_c.append(i) dep_ok.add(const) # We need to keep track of fields to make sure # our items appear earlier than us to_init = [] for const, name in generate_constants(self.consts): if self.genoo.config.translation.verbose: log("Recording %r %r" % (const, name)) else: log.dot() ilasm.load_local(self.const_var) const.init(ilasm) ilasm.set_field(None, name) ilasm.store_void() to_init.append((const, name)) #ilasm.field(name, const.get_type(), static=True) for const, name in to_init: const.init_fields(ilasm, self.const_var, name)
def gen_constants(self, ilasm, pending): try: while True: const,name = self.pending_consts.pop() const.record_fields() except IndexError: pass if pending: return if not self.rendered: ilasm.begin_consts(self.const_var.name) def generate_constants(consts): all_c = [const for const,name in consts.iteritems()] dep_ok = set() while len(all_c) > 0: const = all_c.pop() if const not in self.rendered: to_render = True if hasattr(const, 'depends_on') and const.depends_on: for i in const.depends_on: if i not in self.rendered and i not in dep_ok: assert i.depends is None or const in i.depends to_render = False continue if to_render and (not hasattr(const, 'depends')) or (not const.depends) or const in dep_ok: yield const,consts[const] self.rendered.add(const) else: all_c.append(const) for i in const.depends: all_c.append(i) dep_ok.add(const) # We need to keep track of fields to make sure # our items appear earlier than us to_init = [] for const, name in generate_constants(self.consts): if self.genoo.config.translation.verbose: log("Recording %r %r"%(const,name)) else: log.dot() ilasm.load_local(self.const_var) const.init(ilasm) ilasm.set_field(None, name) ilasm.store_void() to_init.append((const, name)) #ilasm.field(name, const.get_type(), static=True) for const, name in to_init: const.init_fields(ilasm, self.const_var, name)
def call(self, entry_function, kwds): args = ', '.join([self._conv(kw) for kw in kwds ]) #lowerstr for (py)False->(js)false, etc. if entry_function is None: entry_function = self.js.translator.graphs[0].name else: entry_function = self.js.translator.annotator.bookkeeper.getdesc( entry_function).cached_graph(None) function_call = "%s(%s)" % (entry_function, args) self.function_calls.append(function_call) #if self.js.stackless: # function_call = "slp_entry_point('%s')" % function_call if use_browsertest: if not use_tg: log("Used html: %r" % self.html) output = jstest(self.js.filename, function_call, use_browsertest, self.html, self.is_interactive) else: global port from pypy.translator.js.test.tgtest import run_tgtest out = run_tgtest(self, tg_root=self.root, port=port, run_browser=self.run_browser).results assert out[1] == 'undefined' or out[1] == "" output = out[0] port += 1 return self.reinterpret(output) else: # cmd = 'echo "load(\'%s\'); print(%s)" | js 2>&1' % (self.js.filename, function_call) # log(cmd) # output = os.popen(cmd).read().strip() js = subprocess.Popen(["js"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) input = "load(%r);\n" % self.js.filename.strpath for call in self.function_calls[:-1]: input += "%s;\n" % call input += "print(\"'\" + %s + \"'\");\n" % self.function_calls[-1] js.stdin.write(input) stdout, stderr = js.communicate() output = (stderr + stdout).strip() for s in output.split('\n'): log(s) m = re.match("'(.*)'", output, re.DOTALL) if not m: log("Error: %s" % output) raise JSException(output) return self.reinterpret(m.group(1))
def call(self, entry_function, kwds): args = ', '.join([self._conv(kw) for kw in kwds]) #lowerstr for (py)False->(js)false, etc. if entry_function is None: entry_function = self.js.translator.graphs[0].name else: entry_function = self.js.translator.annotator.bookkeeper.getdesc(entry_function).cached_graph(None) function_call = "%s(%s)" % (entry_function, args) self.function_calls.append(function_call) #if self.js.stackless: # function_call = "slp_entry_point('%s')" % function_call if use_browsertest: if not use_tg: log("Used html: %r" % self.html) output = jstest(self.js.filename, function_call, use_browsertest, self.html, self.is_interactive) else: global port from pypy.translator.js.test.tgtest import run_tgtest out = run_tgtest(self, tg_root = self.root, port=port, run_browser=self.run_browser).results assert out[1] == 'undefined' or out[1] == "" output = out[0] port += 1 return self.reinterpret(output) else: # cmd = 'echo "load(\'%s\'); print(%s)" | js 2>&1' % (self.js.filename, function_call) # log(cmd) # output = os.popen(cmd).read().strip() js = subprocess.Popen(["js"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) input = "load(%r);\n" % self.js.filename.strpath for call in self.function_calls[:-1]: input += "%s;\n" % call input += "print(\"'\" + %s + \"'\");\n" % self.function_calls[-1] js.stdin.write(input) stdout, stderr = js.communicate() output = (stderr + stdout).strip() for s in output.split('\n'): log(s) m = re.match("'(.*)'", output, re.DOTALL) if not m: log("Error: %s" % output) raise JSException(output) return self.reinterpret(m.group(1))
def render(self, generator, op): log("Args: %r"%op.args) generator.cast_function(self.name, self.num)