Exemplo n.º 1
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))
     return True
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 _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)
     op = ResOperation(self.mode.NEWSTR, [lengthbox], box)
     if not we_are_translated():
         op.name = 'FORCE'
     optforce.emit_operation(op)
     self.string_copy_parts(optforce, box, CONST_0, self.mode)
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)