Esempio n. 1
0
def do_make_struct_field_accessor(accessor, field, field_name):
    if field_name is values.w_false:
        return values_struct.W_StructFieldAccessor(accessor, field.value, None)
    if not isinstance(field_name, values.W_Symbol):
        raise SchemeException(
            "make-struct-field-accessor: expected symbol or #f as argument 2")
    return values_struct.W_StructFieldAccessor(accessor, field.value,
                                               field_name)
Esempio n. 2
0
def define_struct(name, super=values.w_null, fields=[]):
    immutables = range(len(fields))
    symname = values.W_Symbol.make(name)
    struct_type, struct_constr, struct_pred, struct_acc, struct_mut = \
        values_struct.W_StructType.make_simple(
                symname, super, len(fields), 0, values.w_false, values.w_null,
                values.w_false, values.w_false, immutables).make_struct_tuple()
    expose_val("struct:" + name, struct_type)
    expose_val(name, struct_constr)
    # this is almost always also provided
    expose_val("make-" + name, struct_constr)
    expose_val(name + "?", struct_pred)
    for field, field_name in enumerate(fields):
        w_num = field
        w_name = values.W_Symbol.make(field_name)
        acc = values_struct.W_StructFieldAccessor(struct_acc, w_num, w_name)
        expose_val(name + "-" + field_name, acc)
    return struct_type
Esempio n. 3
0
def define_struct(name, super=values.w_null, fields=[]):
    immutables = []
    for i in range(len(fields)):
        immutables.append(values.W_Fixnum(i))
    struct_type, struct_constr, struct_pred, struct_acc, struct_mut = \
        values_struct.W_StructType.make_simple(values.W_Symbol.make(name),
            super, values.W_Fixnum(len(fields)), values.W_Fixnum(0),
            values.w_false, values.w_null, values.w_false, values.w_false,
            values.to_list(immutables)).make_struct_tuple()
    expose_val("struct:" + name, struct_type)
    expose_val(name, struct_constr)
    # this is almost always also provided
    expose_val("make-" + name, struct_constr)
    expose_val(name + "?", struct_pred)
    for field, field_name in enumerate(fields):
        w_num = values.W_Fixnum(field)
        w_name = values.W_Symbol.make(field_name)
        acc = values_struct.W_StructFieldAccessor(struct_acc, w_num, w_name)
        expose_val(name + "-" + field_name, acc)
    return struct_type
Esempio n. 4
0
def make_accessor(acc, i):
    sym = values.W_Symbol.make("<internal-accessor>")
    return values_struct.W_StructFieldAccessor(acc, i, sym)
Esempio n. 5
0
def make_accessor(acc, i):
    idx = values.W_Fixnum(i)
    sym = values.W_Symbol.make("<internal-accessor>")
    return values_struct.W_StructFieldAccessor(acc, idx, sym)