def do_make_struct_type(name, super_type, w_init_field_cnt, w_auto_field_cnt, auto_v, props, inspector, proc_spec, w_immutables, guard, constr_name, env, cont): if inspector is None: inspector = values_struct.current_inspector_param.get(cont) if constr_name is not values.w_false and not isinstance( constr_name, values.W_Symbol): raise SchemeException( "make-struct-type: constructor name mustbe be symbol? or #f") if not isinstance( super_type, values_struct.W_StructType) and super_type is not values.w_false: raise SchemeException( "make-struct-type: expected a struct-type? or #f") init_field_cnt = w_init_field_cnt.value auto_field_cnt = w_auto_field_cnt.value immutables = [] for i in values.from_list_iter(w_immutables): if not isinstance(i, values.W_Fixnum) or i.value < 0: raise SchemeException( "make-struct-type: expected list of positive integers for immutable fields" ) immutables.append(i.value) return values_struct.W_StructType.make(name, super_type, init_field_cnt, auto_field_cnt, auto_v, props, inspector, proc_spec, immutables, guard, constr_name, env, cont)
def make_cstruct_type(types, abi, _alignment): alignment = validate_alignment("make-cstruct-type", 2, _alignment) if types.is_proper_list(): types_list = [] for ctype in values.from_list_iter(types): if not isinstance(ctype, W_CType): break types_list.append(ctype) else: return W_CStructType(types_list[:], abi, alignment) msg = "make-cstruct-type: expected (listof ctype?) in argument 0 got %s" % types.tostring() raise SchemeException(msg)
def make_cstruct_type(types, abi, _alignment): alignment = validate_alignment("make-cstruct-type", 2, _alignment) if types.is_proper_list(): types_list = [] for ctype in values.from_list_iter(types): if not isinstance(ctype, W_CType): break types_list.append(ctype) else: return W_CStructType(types_list[:], abi, alignment) msg = "make-cstruct-type: expected (listof ctype?) in argument 0 got %s" % types.tostring( ) raise SchemeException(msg)
def do_make_struct_type(w_name, w_super_type, w_init_field_count, w_auto_field_count, w_auto_value, w_properties, w_inspector, w_proc_spec, w_immutables, w_guard, w_constructor_name, env, cont): if w_inspector is None: w_inspector = values_struct.current_inspector_param.get(cont) if (w_constructor_name is not values.w_false and not isinstance(w_constructor_name, values.W_Symbol)): raise SchemeException( "make-struct-type: constructor name mustbe be symbol? or #f") if not (isinstance(w_super_type, values_struct.W_StructType) or w_super_type is values.w_false): raise SchemeException( "make-struct-type: expected a struct-type? or #f for the super type , but got %s : %s" % (w_super_type, w_super_type.tostring())) if (isinstance(w_super_type, values_struct.W_StructType) and w_super_type.prop_sealed): raise SchemeException( "make-struct-type: cannot make a subtype of a sealed type") init_field_count = w_init_field_count.value auto_field_count = w_auto_field_count.value immutables = [] for i in values.from_list_iter(w_immutables): if not isinstance(i, values.W_Fixnum) or i.value < 0: raise SchemeException( "make-struct-type: expected list of positive integers for immutable fields" ) immutables.append(i.value) return values_struct.W_StructType.make( w_name=w_name, w_super_type=w_super_type, init_field_count=init_field_count, auto_field_count=auto_field_count, w_auto_value=w_auto_value, w_properties=w_properties, w_inspector=w_inspector, w_proc_spec=w_proc_spec, immutables=immutables, w_guard=w_guard, w_constructor_name=w_constructor_name, env=env, cont=cont)
def do_is_procedure_arity(n): if isinstance(n, values.W_Fixnum): return values.W_Bool.make(n.value >= 0) elif (isinstance(n, values_struct.W_RootStruct) and n.struct_type() is arity_at_least): return values.w_true elif isinstance(n, values.W_List) and n.is_proper_list(): for item in values.from_list_iter(n): if not (isinstance(item, values.W_Fixnum) or (isinstance(item, values_struct.W_RootStruct) and item.struct_type() is arity_at_least)): return values.w_false return values.w_true return values.w_false
def _compiler_sizeof(ctype): if ctype.is_proper_list(): acc = 0 for type in values.from_list_iter(ctype): if not isinstance(type, values.W_Symbol): break size = _compiler_sizeof(type) acc = max(size, acc) else: return acc if not isinstance(ctype, values.W_Symbol): msg = ("compiler-sizeof: expected (or/c symbol? (listof symbol?)) in argument 0 got %s" % ctype.tostring()) raise SchemeException(msg) for sym, size in COMPILER_SIZEOF: if ctype is sym: return size raise SchemeException("compiler-sizeof: %s is not a valid C type" % ctype.tostring())
def do_make_struct_type(name, super_type, w_init_field_cnt, w_auto_field_cnt, auto_v, props, inspector, proc_spec, w_immutables, guard, constr_name, env, cont): if inspector is None: inspector = values_struct.current_inspector_param.get(cont) if not isinstance(super_type, values_struct.W_StructType) and super_type is not values.w_false: raise SchemeException("make-struct-type: expected a struct-type? or #f") init_field_cnt = w_init_field_cnt.value auto_field_cnt = w_auto_field_cnt.value immutables = [] for i in values.from_list_iter(w_immutables): if not isinstance(i, values.W_Fixnum) or i.value < 0: raise SchemeException("make-struct-type: expected list of positive integers for immutable fields") immutables.append(i.value) return values_struct.W_StructType.make(name, super_type, init_field_cnt, auto_field_cnt, auto_v, props, inspector, proc_spec, immutables, guard, constr_name, env, cont)
def _compiler_sizeof(ctype): if ctype.is_proper_list(): acc = 0 for type in values.from_list_iter(ctype): if not isinstance(type, values.W_Symbol): break size = _compiler_sizeof(type) acc = max(size, acc) else: return acc if not isinstance(ctype, values.W_Symbol): msg = ( "compiler-sizeof: expected (or/c symbol? (listof symbol?)) in argument 0 got %s" % ctype.tostring()) raise SchemeException(msg) for sym, size in COMPILER_SIZEOF: if ctype is sym: return size raise SchemeException("compiler-sizeof: %s is not a valid C type" % ctype.tostring())