本文整理汇总了Python中Memory.new_str方法的典型用法代码示例。如果您正苦于以下问题:Python Memory.new_str方法的具体用法?Python Memory.new_str怎么用?Python Memory.new_str使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Memory
的用法示例。
在下文中一共展示了Memory.new_str方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_str
# 需要导入模块: import Memory [as 别名]
# 或者: from Memory import new_str [as 别名]
def get_str(string):
if string in string_pool:
return string_pool[string]
else:
addr = Memory.new_str(string)
string_pool[string] = addr
return addr
示例2: exec_jalr
# 需要导入模块: import Memory [as 别名]
# 或者: from Memory import new_str [as 别名]
def exec_jalr(inst):
Memory.write_plain(Registers.read_fp(), read_pc()) # set return address
func_obj = Memory.get_obj(Registers.get_reg(inst['rd']))
if func_obj['type'] == 7: # panel.readInt()
num = int(raw_input('Please enter an integer.\n'))
num_addr = Memory.new_int(num)
Memory.write_plain(Registers.read_fp() - 12, num_addr)
inc_pc(4)
elif func_obj['type'] == 8: # panel.readStr()
string = raw_input('Please enter an string.\n')
str_addr = Memory.new_str(string)
Memory.write_plain(Registers.read_fp() - 12, str_addr)
inc_pc(4)
elif func_obj['type'] == 9: # panel.show()
arg = Memory.read_plain(Registers.read_fp() - 16)
Memory.print_obj(arg)
inc_pc(4)
else:
assert func_obj['type'] == 4
func_addr = Registers.get_reg(inst['rd'])
address_field = Memory.get_field(func_addr, Constants.get_str('address'))
address_addr = Memory.get_prop(address_field)['value']
address = Memory.get_int(address_addr)
Memory.write_plain(Registers.read_fp(), read_pc() + 4)
write_pc(address)
示例3: exec_mul
# 需要导入模块: import Memory [as 别名]
# 或者: from Memory import new_str [as 别名]
def exec_mul(inst):
rs_obj = Memory.get_obj(Registers.get_reg(inst['rs']))
rt_obj = Memory.get_obj(Registers.get_reg(inst['rt']))
rd_val = Registers.get_reg(inst['rd'])
if rs_obj['type'] == 0 and rt_obj['type'] == 0: # both are integers
Memory.set_int(rd_val, rs_obj['data'] * rt_obj['data'])
elif {rs_obj['type'], rt_obj['type']} == {0, 2}: # an integer and a string
str_addr = Memory.new_str(rs_obj['data'] * rt_obj['data'])
Memory.set_obj(rd_val, Memory.get_obj(str_addr))
inc_pc(4)
示例4: exec_add
# 需要导入模块: import Memory [as 别名]
# 或者: from Memory import new_str [as 别名]
def exec_add(inst):
rs_obj = Memory.get_obj(Registers.get_reg(inst['rs']))
rt_obj = Memory.get_obj(Registers.get_reg(inst['rt']))
rd_val = Registers.get_reg(inst['rd'])
if rs_obj['type'] == 0 and rt_obj['type'] == 0: # both are integers
Memory.set_int(rd_val, rs_obj['data'] + rt_obj['data'])
elif rs_obj['type'] == 3 and rs_obj['data'] == 0: # rs references an empty object
Memory.set_obj(rd_val, rt_obj)
elif rt_obj['type'] == 3 and rt_obj['data'] == 0: # rt references an empty object
Memory.set_obj(rd_val, rs_obj)
elif rs_obj['type'] == 2 and rt_obj['type'] == 2: # both are strings
str_addr = Memory.new_str(rs_obj['data'] + rt_obj['data'])
Memory.set_obj(rd_val, Memory.get_obj(str_addr))
# TODO: more cases in addition
inc_pc(4)