Esempio n. 1
0
 def make_tvar_init_expression(self, info, slot):
     """Return the initializer for the given slot in the given type.
     
     This is the type expression that initializes the given slot
     using the type arguments given to the constructor.
     
     Examples:
       - In 'class C<T> ...', the initializer for the slot 0 is
         TypeExpr(RuntimeTypeVar(NameExpr('__tv'))).
       - In 'class D(C<int>) ...', the initializer for the slot 0 is
         TypeExpr(<int instance>).
     """
     # Figure out the superclass which defines the slot; also figure out
     # the tvar index that maps to the slot.
     origin, tv = find_slot_origin(info, slot)
     
     # Map self type to the superclass -> extract tvar with target index
     # (only contains subclass tvars?? PROBABLY NOT).
     selftype = self_type(info)
     selftype = map_instance_to_supertype(selftype, origin)
     tvar = selftype.args[tv - 1]
     
     # Map tvar to an expression; refer to local vars instead of member
     # vars always.
     tvar = translate_runtime_type_vars_locally(tvar)
     
     # Build the rvalue (initializer) expression
     return TypeExpr(tvar)
Esempio n. 2
0
 def make_tvar_init_expression(self, info: TypeInfo, slot: int) -> TypeExpr:
     """Return the initializer for the given slot in the given type.
     
     This is the type expression that initializes the given slot
     using the type arguments given to the constructor.
     
     Examples:
       - In 'class C(Generic[T]) ...', the initializer for the slot 0 is
         TypeExpr(RuntimeTypeVar(NameExpr('__tv'))).
       - In 'class D(C[int]) ...', the initializer for the slot 0 is
         TypeExpr(<int instance>).
     """
     # Figure out the superclass which defines the slot; also figure out
     # the tvar index that maps to the slot.
     origin, tv = find_slot_origin(info, slot)
     
     # Map self type to the superclass -> extract tvar with target index
     # (only contains subclass tvars?? PROBABLY NOT).
     selftype = self_type(info)
     selftype = map_instance_to_supertype(selftype, origin)
     tvar = selftype.args[tv - 1]
     
     # Map tvar to an expression; refer to local vars instead of member
     # vars always.
     tvar = translate_runtime_type_vars_locally(tvar)
     
     # Build the rvalue (initializer) expression
     return TypeExpr(tvar)
Esempio n. 3
0
          - In 'class D(C<int>) ...', the initializer for the slot 0 is
            TypeExpr(<int instance>).
        """
        # Figure out the superclass which defines the slot; also figure out
        # the tvar index that maps to the slot.
        origin, tv = find_slot_origin(info, slot)
        
        # Map self type to the superclass -> extract tvar with target index
        # (only contains subclass tvars?? PROBABLY NOT).
        selftype = self_type(info)
        selftype = map_instance_to_supertype(selftype, origin)
        tvar = selftype.args[tv - 1]
        
        # Map tvar to an expression; refer to local vars instead of member
        # vars always.
        tvar = translate_runtime_type_vars_locally(tvar)
        
        # Build the rvalue (initializer) expression
        return TypeExpr(tvar)

    FuncDef make_type_object_wrapper(self, TypeDef tdef):
        """Construct dynamically typed wrapper function for a class.

        It simple calls the type object and returns the result.
        """
        
        # TODO keyword args, default args and varargs
        # TODO overloads

        type_sig = (Callable)type_object_type(tdef.info, None)
        type_sig = (Callable)erasetype.erase_typevars(type_sig)