Exemplo n.º 1
0
 def force_box(self, op, optforce):
     if not self.is_virtual():
         return op
     optforce.forget_numberings()
     if self.mode is mode_string:
         s = self.get_constant_string_spec(optforce, mode_string)
         if s is not None:
             c_s = get_const_ptr_for_string(s)
             optforce.get_box_replacement(op).set_forwarded(c_s)
             return c_s
     else:
         s = self.get_constant_string_spec(optforce, mode_unicode)
         if s is not None:
             c_s = get_const_ptr_for_unicode(s)
             optforce.get_box_replacement(op).set_forwarded(c_s)
             return c_s
     self._is_virtual = False
     lengthbox = self.getstrlen(op, optforce.optimizer.optstring, self.mode)
     newop = ResOperation(self.mode.NEWSTR, [lengthbox])
     if not we_are_translated():
         newop.name = 'FORCE'
     optforce.emit_operation(newop)
     newop = optforce.getlastop()
     newop.set_forwarded(self)
     op = optforce.get_box_replacement(op)
     op.set_forwarded(newop)
     optstring = optforce.optimizer.optstring
     self.initialize_forced_string(op, optstring, op, CONST_0, self.mode)
     return newop
Exemplo n.º 2
0
 def opt_call_str_STR2UNICODE(self, op):
     # Constant-fold unicode("constant string").
     # More generally, supporting non-constant but virtual cases is
     # not obvious, because of the exception UnicodeDecodeError that
     # can be raised by ll_str2unicode()
     varg = self.getvalue(op.getarg(1))
     s = varg.get_constant_string_spec(mode_string)
     if s is None:
         return False
     try:
         u = unicode(s)
     except UnicodeDecodeError:
         return False
     self.make_constant(op.result, get_const_ptr_for_unicode(u))
     self.last_emitted_operation = REMOVED
     return True
Exemplo n.º 3
0
 def opt_call_str_STR2UNICODE(self, op):
     # Constant-fold unicode("constant string").
     # More generally, supporting non-constant but virtual cases is
     # not obvious, because of the exception UnicodeDecodeError that
     # can be raised by ll_str2unicode()
     varg = self.getvalue(op.getarg(1))
     s = varg.get_constant_string_spec(mode_string)
     if s is None:
         return False
     try:
         u = unicode(s)
     except UnicodeDecodeError:
         return False
     self.make_constant(op.result, get_const_ptr_for_unicode(u))
     self.last_emitted_operation = REMOVED
     return True
Exemplo n.º 4
0
 def _really_force(self, optforce):
     if self.mode is mode_string:
         s = self.get_constant_string_spec(mode_string)
         if s is not None:
             c_s = get_const_ptr_for_string(s)
             self.make_constant(c_s)
             return
     else:
         s = self.get_constant_string_spec(mode_unicode)
         if s is not None:
             c_s = get_const_ptr_for_unicode(s)
             self.make_constant(c_s)
             return
     assert self.source_op is not None
     self.box = box = self.source_op.result
     lengthbox = self.getstrlen(optforce, self.mode, None)
     op = ResOperation(self.mode.NEWSTR, [lengthbox], box)
     if not we_are_translated():
         op.name = 'FORCE'
     optforce.emit_operation(op)
     self.initialize_forced_string(optforce, box, CONST_0, self.mode)
Exemplo n.º 5
0
 def _really_force(self, optforce):
     if self.mode is mode_string:
         s = self.get_constant_string_spec(mode_string)
         if s is not None:
             c_s = get_const_ptr_for_string(s)
             self.make_constant(c_s)
             return
     else:
         s = self.get_constant_string_spec(mode_unicode)
         if s is not None:
             c_s = get_const_ptr_for_unicode(s)
             self.make_constant(c_s)
             return
     assert self.source_op is not None
     self.box = box = self.source_op.result
     lengthbox = self.getstrlen(optforce, self.mode, None)
     op = ResOperation(self.mode.NEWSTR, [lengthbox], box)
     if not we_are_translated():
         op.name = 'FORCE'
     optforce.emit_operation(op)
     self.initialize_forced_string(optforce, box, CONST_0, self.mode)