当前位置: 首页>>代码示例>>Python>>正文


Python Constants.get_str方法代码示例

本文整理汇总了Python中Constants.get_str方法的典型用法代码示例。如果您正苦于以下问题:Python Constants.get_str方法的具体用法?Python Constants.get_str怎么用?Python Constants.get_str使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Constants的用法示例。


在下文中一共展示了Constants.get_str方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: exec_getfield

# 需要导入模块: import Constants [as 别名]
# 或者: from Constants import get_str [as 别名]
def exec_getfield(inst):
    name_addr = Registers.get_reg(inst['rt'])
    obj_addr = Registers.get_reg(inst['rs'])
    while True:
        try:
            field = Memory.get_field(obj_addr, name_addr)
        except Exception as e:
            Memory.print_obj(obj_addr)
            Memory.print_obj(name_addr)
            raise e
        if not field:  # The field cannot be found.
            ctor_addr = Memory.get_field(obj_addr, Constants.get_str('constructor'))
            if not ctor_addr:  # There is no constructor field
                new_field = Memory.new_field(Registers.get_reg(inst['rs']), name_addr)
                Memory.set_prop(new_field, value=Memory.new_obj())
                res = Memory.get_prop(new_field)
                break
            ctor_obj = Memory.get_prop(ctor_addr)['value']
            proto_addr = Memory.get_field(ctor_obj, Constants.get_str('prototype'))
            if not proto_addr:  # There is no prototype field
                new_field = Memory.new_field(Registers.get_reg(inst['rs']), name_addr)
                Memory.set_prop(new_field, value=Memory.new_obj())
                res = Memory.get_prop(new_field)
                break
            obj_addr = Memory.get_prop(proto_addr)['value']  # Find field in the prototype
        else:
            res = Memory.get_prop(field)
            break
    Registers.set_reg(inst['rd'], res['value'])
    inc_pc(4)
    """
开发者ID:SundongCandy,项目名称:lift-js,代码行数:33,代码来源:Processor.py

示例2: exec_getvar

# 需要导入模块: import Constants [as 别名]
# 或者: from Constants import get_str [as 别名]
def exec_getvar(inst):
    func_addr = Memory.read_plain(Registers.read_fp() - 4)
    rs_val = Registers.get_reg(inst['rs'])
    while True:
        arg_field = Memory.get_field(func_addr, Constants.get_str('arguments'))
        arg_obj = Memory.get_prop(arg_field)['value']
        var_field = Memory.get_field(arg_obj, rs_val)
        if var_field:  # The field is found in arguments.
            offset_addr = Memory.get_prop(var_field)['value']
            offset = Memory.get_int(offset_addr)
            Registers.set_reg(inst['rd'], Memory.read_plain(Registers.read_fp() + offset))
            break
        scope_field = Memory.get_field(func_addr, Constants.get_str('scope'))
        scope_obj = Memory.get_prop(scope_field)['value']
        var_field = Memory.get_field(scope_obj, rs_val)
        if var_field:  # The field is found in scope.
            var_obj = Memory.get_prop(var_field)['value']
            Registers.set_reg(inst['rd'], var_obj)
            break
        outer_field = Memory.get_field(func_addr, Constants.get_str('outer'))
        outer_obj = Memory.get_prop(outer_field)['value']
        if not outer_obj:  # The field 'outer' is empty.
            func_addr = Memory.read_plain(Registers.read_fp() - 4)
            scope_field = Memory.get_field(func_addr, Constants.get_str('scope'))
            scope_obj = Memory.get_prop(scope_field)['value']
            prop_addr = Memory.new_field(scope_obj, rs_val)
            obj_addr = Memory.new_obj()
            Memory.set_prop(prop_addr, value=obj_addr)
            Registers.set_reg(inst['rd'], obj_addr)
            break
        else:
            func_addr = outer_obj
    inc_pc(4)
开发者ID:SundongCandy,项目名称:lift-js,代码行数:35,代码来源:Processor.py

示例3: exec_newfunc

# 需要导入模块: import Constants [as 别名]
# 或者: from Constants import get_str [as 别名]
def exec_newfunc(inst):
    func_addr = Memory.new_func()
    address_prop = Memory.get_field(func_addr, Constants.get_str('address'))
    Memory.set_prop(address_prop, value=Memory.new_int(Labels.query(inst['label'])))
    outer_func = Memory.read_plain(Registers.read_fp() - 4)
    outer_prop = Memory.get_field(func_addr, Constants.get_str('outer'))
    Memory.set_prop(outer_prop, value=outer_func)
    Registers.set_reg(inst['rd'], func_addr)
    inc_pc(4)
开发者ID:SundongCandy,项目名称:lift-js,代码行数:11,代码来源:Processor.py

示例4: exec_jalr

# 需要导入模块: import Constants [as 别名]
# 或者: from Constants import get_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)
开发者ID:SundongCandy,项目名称:lift-js,代码行数:27,代码来源:Processor.py

示例5: exec_typeof

# 需要导入模块: import Constants [as 别名]
# 或者: from Constants import get_str [as 别名]
def exec_typeof(inst):
    obj = Memory.get_obj(Registers.get_reg(inst['rs']))
    types = {
        0: 'integer',
        2: 'string',
        3: 'object',
        4: 'function',
        5: 'null',
        6: 'undefined',
        7: 'function',
        8: 'function',
        9: 'function'
    }
    res = types[obj['type']]
    Registers.set_reg(inst['rd'], Constants.get_str(res))
    inc_pc(4)
开发者ID:SundongCandy,项目名称:lift-js,代码行数:18,代码来源:Processor.py

示例6: init

# 需要导入模块: import Constants [as 别名]
# 或者: from Constants import get_str [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


注:本文中的Constants.get_str方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。