示例#1
0
	def str(self, out_inst=None):
		'''Convert to a string.'''
		if not out_inst:
			out_inst = PyStringLL(None, self.v)
			out_inst.declare_tmp(name="_str")
		self.v.ctx.add(c.Assignment('=', c.ID(out_inst.name), c.FuncCall(c.ID('PyObject_Str'), c.ExprList(c.ID(self.name)))))
		self.fail_if_null(out_inst.name)
		return out_inst
示例#2
0
 def set_initial_string_attribute(self, name: str, s: str):
     if s is not None:
         ps = PyStringLL(None, self.v)
         ps.declare_tmp()
         ps.new(s)
     else:
         ps = PyObjectLL(None, self.v)
         ps.declare_tmp()
         ps.assign_none()
     self.set_attr_string(name, ps)
     ps.decref()
示例#3
0
	def intro(self, docstring, module_name):
		self.v.ctx.add_variable(c.Decl('__return_value__', PyObjectLL.typedecl('__return_value__')), False)

		# set the docstring
		ds = PyStringLL(None, self.v)
		ds.declare_tmp()
		if docstring:
			ds.new(docstring)
		else:
			ds.assign_none()
		self.c_namespace_dict.set_item_string('__doc__', ds)
		ds.decref()

		# set the module name
		ds = PyStringLL(None, self.v)
		ds.declare_tmp()
		if module_name:
			ds.new(module_name)
			self.c_namespace_dict.set_item_string('__module__', ds)
		ds.decref()