예제 #1
0
파일: struct.py 프로젝트: yws/pycket-1
def impersonator_args(struct, overrides, handlers, prop_keys, prop_vals):
    from pycket.prims.struct_structinfo import struct_info
    assert len(overrides) == len(handlers)

    _handlers = None
    struct_props = None
    struct_prop_keys = None
    struct_prop_vals = None

    handler_map = W_InterposeStructBase.EMPTY_HANDLER_MAP

    struct_type = jit.promote(struct.struct_type())
    for i, op in enumerate(overrides):
        base = get_base_object(op)
        if isinstance(base, values_struct.W_StructFieldAccessor):
            if handlers[i] is not values.w_false:
                field = base.get_absolute_index(struct_type)
                idx = tag_handler_accessor(field)
                _handlers, handler_map = add_handler_field(
                    handler_map, _handlers, idx, handlers[i])
            if type(op) is not values_struct.W_StructFieldAccessor:
                field = base.get_absolute_index(struct_type)
                idx = tag_override_accessor(field)
                _handlers, handler_map = add_handler_field(
                    handler_map, _handlers, idx, op)
        elif isinstance(base, values_struct.W_StructFieldMutator):
            if handlers[i] is not values.w_false:
                field = base.get_absolute_index(struct_type)
                idx = tag_handler_mutator(field)
                _handlers, handler_map = add_handler_field(
                    handler_map, _handlers, idx, handlers[i])
            if type(op) is not values_struct.W_StructFieldAccessor:
                field = base.get_absolute_index(struct_type)
                idx = tag_override_mutator(field)
                _handlers, handler_map = add_handler_field(
                    handler_map, _handlers, idx, op)
        elif base is struct_info and handlers[i] is not values.w_false:
            idx = INFO_HANDLER_IDX
            _handlers, handler_map = add_handler_field(handler_map, _handlers,
                                                       idx, handlers[i])
        elif isinstance(base, values_struct.W_StructPropertyAccessor):
            if struct_prop_keys is None:
                struct_prop_keys = []
                struct_prop_vals = []
            struct_prop_keys.append(base)
            struct_prop_vals.append(Pair(op, handlers[i]))
        else:
            assert False

    EMPTY = W_InterposeStructBase.EMPTY_PROPERTY_MAP
    property_map = make_property_map(struct_prop_keys,
                                     make_property_map(prop_keys, EMPTY))
    vals = concat(_handlers, concat(prop_vals, struct_prop_vals))
    storage = vals[:] if vals is not None else None

    map = CompositeMap.instantiate(handler_map, property_map)

    return map, storage
예제 #2
0
파일: struct.py 프로젝트: rjnw/pycket
def impersonator_args(struct, overrides, handlers, prop_keys, prop_vals):
    from pycket.prims.struct_structinfo import struct_info
    assert len(overrides) == len(handlers)

    _handlers = None
    struct_props = None
    struct_prop_keys = None
    struct_prop_vals = None

    handler_map = W_InterposeStructBase.EMPTY_HANDLER_MAP

    struct_type = jit.promote(struct.struct_type())
    for i, op in enumerate(overrides):
        base = get_base_object(op)
        if isinstance(base, values_struct.W_StructFieldAccessor):
            if handlers[i] is not values.w_false:
                field = base.get_absolute_index(struct_type)
                idx = tag_handler_accessor(field)
                _handlers, handler_map = add_handler_field(handler_map, _handlers, idx, handlers[i])
            if type(op) is not values_struct.W_StructFieldAccessor:
                field = base.get_absolute_index(struct_type)
                idx = tag_override_accessor(field)
                _handlers, handler_map = add_handler_field(handler_map, _handlers, idx, op)
        elif isinstance(base, values_struct.W_StructFieldMutator):
            if handlers[i] is not values.w_false:
                field = base.get_absolute_index(struct_type)
                idx = tag_handler_mutator(field)
                _handlers, handler_map = add_handler_field(handler_map, _handlers, idx, handlers[i])
            if type(op) is not values_struct.W_StructFieldAccessor:
                field = base.get_absolute_index(struct_type)
                idx = tag_override_mutator(field)
                _handlers, handler_map = add_handler_field(handler_map, _handlers, idx, op)
        elif base is struct_info and handlers[i] is not values.w_false:
            idx = INFO_HANDLER_IDX
            _handlers, handler_map = add_handler_field(handler_map, _handlers, idx, handlers[i])
        elif isinstance(base, values_struct.W_StructPropertyAccessor):
            if struct_prop_keys is None:
                struct_prop_keys = []
                struct_prop_vals = []
            struct_prop_keys.append(base)
            struct_prop_vals.append(Pair(op, handlers[i]))
        else:
            assert False

    EMPTY = W_InterposeStructBase.EMPTY_PROPERTY_MAP
    property_map = make_property_map(struct_prop_keys, make_property_map(prop_keys, EMPTY))
    vals = concat(_handlers, concat(prop_vals, struct_prop_vals))
    storage = vals[:] if vals is not None else None

    map = CompositeMap.instantiate(handler_map, property_map)

    return map, storage
예제 #3
0
파일: struct.py 프로젝트: rjnw/pycket
def valid_struct_proc(x):
    v = get_base_object(x)
    return (isinstance(v, values_struct.W_StructFieldAccessor) or
            isinstance(v, values_struct.W_StructFieldMutator) or
            isinstance(v, values_struct.W_StructPropertyAccessor))
예제 #4
0
파일: struct.py 프로젝트: rjnw/pycket
 def get_arity(self):
     return get_base_object(self.base).get_arity()
예제 #5
0
파일: struct.py 프로젝트: rjnw/pycket
 def vals(self):
     base = get_base_object(self.base)
     assert isinstance(base, values_struct.W_RootStruct)
     return base.vals()
예제 #6
0
파일: struct.py 프로젝트: rjnw/pycket
 def struct_type(self):
     return get_base_object(self.base).struct_type()
예제 #7
0
파일: struct.py 프로젝트: rjnw/pycket
 def tostring(self):
     return get_base_object(self.base).tostring()
예제 #8
0
파일: struct.py 프로젝트: rjnw/pycket
 def immutable(self):
     return get_base_object(self.base).immutable()
예제 #9
0
 def get_arity(self, promote=False):
     return get_base_object(self.base).get_arity(promote)
예제 #10
0
파일: struct.py 프로젝트: yws/pycket-1
def valid_struct_proc(x):
    v = get_base_object(x)
    return (isinstance(v, values_struct.W_StructFieldAccessor)
            or isinstance(v, values_struct.W_StructFieldMutator)
            or isinstance(v, values_struct.W_StructPropertyAccessor))
예제 #11
0
파일: struct.py 프로젝트: yws/pycket-1
 def vals(self):
     base = get_base_object(self.base)
     assert isinstance(base, values_struct.W_RootStruct)
     return base.vals()
예제 #12
0
파일: struct.py 프로젝트: yws/pycket-1
 def get_arity(self, promote=False):
     return get_base_object(self.base).get_arity(promote)
예제 #13
0
파일: struct.py 프로젝트: yws/pycket-1
 def struct_type(self):
     return get_base_object(self.base).struct_type()
예제 #14
0
파일: struct.py 프로젝트: yws/pycket-1
 def tostring(self):
     return get_base_object(self.base).tostring()
예제 #15
0
파일: struct.py 프로젝트: yws/pycket-1
 def immutable(self):
     return get_base_object(self.base).immutable()