當前位置: 首頁>>代碼示例>>Python>>正文


Python Memory.set_obj方法代碼示例

本文整理匯總了Python中Memory.set_obj方法的典型用法代碼示例。如果您正苦於以下問題:Python Memory.set_obj方法的具體用法?Python Memory.set_obj怎麽用?Python Memory.set_obj使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Memory的用法示例。


在下文中一共展示了Memory.set_obj方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: exec_mul

# 需要導入模塊: import Memory [as 別名]
# 或者: from Memory import set_obj [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)
開發者ID:SundongCandy,項目名稱:lift-js,代碼行數:12,代碼來源:Processor.py

示例2: exec_add

# 需要導入模塊: import Memory [as 別名]
# 或者: from Memory import set_obj [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)
開發者ID:SundongCandy,項目名稱:lift-js,代碼行數:17,代碼來源:Processor.py

示例3: init

# 需要導入模塊: import Memory [as 別名]
# 或者: from Memory import set_obj [as 別名]
def init():
    for name in ['constructor', 'prototype', 'this', 'address', 'scope', 'outer', 'null', 'undefined',
                 'panel', 'readStr', 'readInt', 'integer', 'object', 'function', 'arguments']:
        Constants.get_str(name)

    for value in [1, 4]:
        Constants.get_int(value)

    addr = Memory.alloc(8)
    Memory.write(addr, {'type': 1, 'content': 5, 'object': {'type': 5}})  # null
    Constants.set_special('null', addr)

    addr = Memory.alloc(8)
    Memory.write(addr, {'type': 1, 'content': 6, 'object': {'type': 6}})  # undefined
    Constants.set_special('undefined', addr)

    Registers.set_sp(Memory.new_int(0x2FFFFFFC))  # sp
    Registers.set_fp(Memory.new_int(0x2FFFFFFC))  # fp

    # initialize runtime stack
    init_func = Memory.new_func()  # function 'init
    state['init_func'] = init_func
    fp_addr = Memory.get_int(Registers.get_fp())
    Memory.write_plain(fp_addr, 0)  # return address
    Memory.write_plain(fp_addr - 4, init_func)  # current function
    Memory.write_plain(fp_addr - 8, Memory.new_obj())  # this pointer
    Memory.write_plain(fp_addr - 12, 0)  # return value
    Memory.set_int(Registers.get_sp(), fp_addr - 16)

    # add function 'Object' into 'init'
    scope_field = Memory.get_field(init_func, Constants.get_str('scope'))
    scope_addr = Memory.get_prop(scope_field)['value']
    object_field = Memory.new_field(scope_addr, Constants.get_str('Object'))
    object_addr = Memory.new_obj()
    Memory.set_prop(object_field, value=object_addr)
    state['obj_func'] = object_addr

    # add object 'panel' into 'init'
    panel_field = Memory.new_field(scope_addr, Constants.get_str('panel'))
    panel_addr = Memory.new_obj()
    Memory.set_prop(panel_field, value=panel_addr)

    # add property 'readInt' into 'panel'
    read_int_prop = Memory.new_field(panel_addr, Constants.get_str('readInt'))
    read_int_func = Memory.new_func()
    Memory.set_prop(read_int_prop, value=read_int_func)
    read_int_obj = Memory.get_obj(read_int_func)
    read_int_obj['type'] = 7  # special type value
    Memory.set_obj(read_int_func, read_int_obj)

    # add property 'readStr' into 'panel'
    read_str_prop = Memory.new_field(panel_addr, Constants.get_str('readStr'))
    read_str_func = Memory.new_func()
    Memory.set_prop(read_str_prop, value=read_str_func)
    read_str_obj = Memory.get_obj(read_str_func)
    read_str_obj['type'] = 8
    Memory.set_obj(read_str_func, read_str_obj)

    # add property 'show' into 'panel'
    show_prop = Memory.new_field(panel_addr, Constants.get_str('show'))
    show_func = Memory.new_func()
    Memory.set_prop(show_prop, value=show_func)
    show_obj = Memory.get_obj(show_func)
    show_obj['type'] = 9
    Memory.set_obj(show_func, show_obj)
開發者ID:SundongCandy,項目名稱:lift-js,代碼行數:67,代碼來源:Processor.py

示例4: exec_move

# 需要導入模塊: import Memory [as 別名]
# 或者: from Memory import set_obj [as 別名]
def exec_move(inst):
    rd_val = Registers.get_reg(inst['rd'])
    rs_val = Registers.get_reg(inst['rs'])
    Memory.set_obj(rd_val, Memory.get_obj(rs_val))
    inc_pc(4)
開發者ID:SundongCandy,項目名稱:lift-js,代碼行數:7,代碼來源:Processor.py


注:本文中的Memory.set_obj方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。