Пример #1
0
def exec_loop(
    iterable,
    settings,
    matcode,
    used_vars,
    real_vars_indexes,
    need_store_counter,
    globals_dict,
    locals_dict,
    folded,
):
    try:
        # Check whether iterable for-loop argument has type "xrange"
        range_desc = check_iterable(settings, iterable)
        try:
            # If so, retreive it's parameters
            start, step, iters_count, last = range_desc
        except TypeError:
            return None

        # Load necessary variables, check it's types and make vector
        # for further operations with matrixes appending unit row
        vector = load_vars(
            settings,
            used_vars,
            globals_dict,
            locals_dict,
        ) + [1]
    except TypeError as err:
        err.message = "Can't run optimized loop: " + err.message
        if settings['profile']:
            profiler.exc(settings, "Hook didn't allow optimization", err)
        return None

    # Define constant values in matrix code
    matcode = define_values(matcode, folded, {
        'start': start,
        'step': step,
        'iters_count': iters_count,
    })

    # Add last detail to matrix code before it's execution
    matcode.append([END])

    # Run matrix code
    vector = run.run_matcode(settings, matcode, vector)

    if settings['profile']:
        profiler.success(settings,
                         'Optimized execution of %s iterations' % iters_count)

    # Pack real variables' values to a list that will be unpacked in
    # the main function to the values that would be assigned to the
    # globals and the locals. We can't implement storing variables like
    # its' loading because locals() dictionary is read-only.
    packed = [vector[index] for index in real_vars_indexes]
    if need_store_counter:
        packed.append(last)
    return packed
Пример #2
0
def exec_loop(
    iterable,
    settings,
    matcode,
    used_vars,
    real_vars_indexes,
    need_store_counter,
    globals_dict,
    locals_dict,
    folded,
):
    try:
        # Check whether an iterable has type "xrange" and the required
        # number of iterations
        range_params = check_iterable(settings, iterable)
        if range_params is None:  # If the number of iterations is too little
            return None
        start, step, iters_count, last = range_params

        # Load necessary variables, check their types and make a vector
        # for further operations with matrixes (including a unit row)
        vector = load_vars(
            settings,
            used_vars,
            globals_dict,
            locals_dict,
        ) + [1]
    except TypeError as err:
        generic_err = TypeError("Can't run optimized loop: %s" % err)
        if settings['verbose']:
            settings['logger'].debug(generic_err)
        if settings['strict']:
            raise generic_err
        return None

    # Define constant values in matrix code
    matcode = define_values(matcode, folded, {
        'start': start,
        'step': step,
        'iters_count': iters_count,
    })

    matcode.append([END])

    # Run matrix code
    vector = run.run_matcode(settings, matcode, vector)

    if settings['verbose']:
        settings['logger'].debug('Execution of %s iterations was optimized '
                                 'successfully' % iters_count)

    # Pack values of real variables to a list. It will be unpacked in
    # a main function to values that will be assigned to the
    # globals and the locals. We can't just modify `locals_dict`
    # because locals() dictionary is read-only.
    packed = [vector[index] for index in real_vars_indexes]
    if need_store_counter:
        packed.append(last)
    return packed
Пример #3
0
def exec_loop(
    iterable, settings, matcode, used_vars, real_vars_indexes,
    need_store_counter, globals_dict, locals_dict, folded,
):
    try:
        # Check whether iterable for-loop argument has type "xrange"
        range_desc = check_iterable(settings, iterable)
        try:
            # If so, retreive it's parameters
            start, step, iters_count, last = range_desc
        except TypeError:
            return None
        
        # Load necessary variables, check it's types and make vector
        # for further operations with matrixes appending unit row
        vector = load_vars(
            settings, used_vars, globals_dict, locals_dict,
        ) + [1]
    except TypeError as err:
        err.message = "Can't run optimized loop: " + err.message
        if settings['profile']:
            profiler.exc(settings, "Hook didn't allow optimization", err)
        return None
        
    # Define constant values in matrix code
    matcode = define_values(matcode, folded, {
        'start': start, 'step': step, 'iters_count': iters_count,
    })
    
    # Add last detail to matrix code before it's execution
    matcode.append([END])
    
    # Run matrix code
    vector = run.run_matcode(settings, matcode, vector)
    
    if settings['profile']:
        profiler.success(settings,
                'Optimized execution of %s iterations' % iters_count)
    
    # Pack real variables' values to a list that will be unpacked in
    # the main function to the values that would be assigned to the
    # globals and the locals. We can't implement storing variables like
    # its' loading because locals() dictionary is read-only.
    packed = [vector[index] for index in real_vars_indexes]
    if need_store_counter:
        packed.append(last)
    return packed
Пример #4
0
def exec_loop(iterable, settings, matcode, used_vars, real_vars_indexes,
              need_store_counter, globals_dict, locals_dict, folded):
    try:
        # Check whether an iterable has type "xrange" and the required
        # number of iterations
        range_params = check_iterable(settings, iterable)
        if range_params is None:  # If the number of iterations is too little
            return None
        start, step, iters_count, last = range_params

        # Load necessary variables, check their types and make a vector
        # for further operations with matrixes (including a unit row)
        vector = load_vars(
            settings, used_vars, globals_dict, locals_dict,
        ) + [1]
    except TypeError as err:
        generic_err = TypeError("Can't run optimized loop: %s" % err)
        if settings['verbose']:
            settings['logger'].debug(generic_err)
        if settings['strict']:
            raise generic_err
        return None

    # Define constant values in matrix code
    matcode = define_values(matcode, folded, {
        'start': start, 'step': step, 'iters_count': iters_count,
    })

    matcode.append([END])

    # Run matrix code
    vector = run.run_matcode(settings, matcode, vector)

    if settings['verbose']:
        settings['logger'].debug('Execution of %s iterations was optimized '
                                 'successfully' % iters_count)

    # Pack values of real variables to a list. It will be unpacked in
    # a main function to values that will be assigned to the
    # globals and the locals. We can't just modify `locals_dict`
    # because locals() dictionary is read-only.
    packed = [vector[index] for index in real_vars_indexes]
    if need_store_counter:
        packed.append(last)
    return packed