How to use the nuitka.codegen.Indentation.indented function in Nuitka

To help you get started, we’ve selected a few Nuitka examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Nuitka / Nuitka / nuitka / codegen / ErrorCodes.py View on Github external
"ADD_EXCEPTION_CONTEXT( &%s, &%s );" % (keeper_vars[0], keeper_vars[1])
            )
        else:
            set_exception.append(
                "NORMALIZE_EXCEPTION( &%s, &%s, &%s );"
                % (exception_type, exception_value, exception_tb)
            )
            set_exception.append("CHAIN_EXCEPTION( %s );" % exception_value)

    emit(
        template_error_format_string_exception
        % {
            "condition": condition,
            "exception_exit": context.getExceptionEscape(),
            "set_exception": indented(set_exception),
            "release_temps": indented(getErrorExitReleaseCode(context)),
            "var_description_code": indented(
                getFrameVariableTypeDescriptionCode(context)
            ),
            "line_number_code": indented(getErrorLineNumberUpdateCode(context)),
        }
github Nuitka / Nuitka / nuitka / codegen / ConstantCodes.py View on Github external
)
            sys_base_exec_prefix = context.getConstantCode(
                sys.base_exec_prefix  # @UndefinedVariable
            )

    major, minor, micro = getNuitkaVersion().split(".")[:3]

    if "rc" in micro:
        micro = micro[: micro.find("rc")]
        level = "candidate"
    else:
        level = "release"

    return template_constants_reading % {
        "constant_declarations": "\n".join(constant_declarations),
        "constant_inits": indented(constant_inits),
        "constant_checks": indented(constant_checks),
        "sys_executable": sys_executable,
        "sys_prefix": sys_prefix,
        "sys_base_prefix": sys_base_prefix,
        "sys_exec_prefix": sys_exec_prefix,
        "sys_base_exec_prefix": sys_base_exec_prefix,
        "nuitka_version_major": major,
        "nuitka_version_minor": minor,
        "nuitka_version_micro": micro,
        "nuitka_version_level": level,
    }
github Nuitka / Nuitka / nuitka / codegen / GlobalsLocalsCodes.py View on Github external
context=context,
    )

    if is_dict:
        if initial:
            template = template_set_locals_dict_value
        else:
            template = template_update_locals_dict_value

        emit(
            template
            % {
                "dict_name": target_name,
                "var_name": context.getConstantCode(constant=variable.getName()),
                "test_code": test_code,
                "access_code": indented(access_code.codes),
            }
        )
    else:
        if initial:
            template = template_set_locals_mapping_value
        else:
            template = template_update_locals_mapping_value

        res_name = context.getBoolResName()

        emit(
            template
            % {
                "mapping_name": target_name,
                "var_name": context.getConstantCode(constant=variable.getName()),
                "test_code": test_code,
github Nuitka / Nuitka / nuitka / codegen / AsyncgenCodes.py View on Github external
function_locals += context.variable_storage.makeCStructInits()

    if local_type_decl:
        heap_declaration = """\
struct %(function_identifier)s_locals *asyncgen_heap = \
(struct %(function_identifier)s_locals *)asyncgen->m_heap_storage;""" % {
            "function_identifier" : function_identifier
        }
    else:
        heap_declaration = ""

    return template_asyncgen_object_body_template % {
        "function_identifier"   : function_identifier,
        "function_body"         : indented(function_codes.codes),
        "heap_declaration"      : indented(heap_declaration),
        "function_local_types"  : indented(local_type_decl),
        "function_var_inits"    : indented(function_locals),
        "function_dispatch"     : indented(getYieldReturnDispatchCode(context)),
        "asyncgen_exit"         : generator_exit,
        "asyncgen_module"       : getModuleAccessCode(context),
        "asyncgen_name_obj"     : context.getConstantCode(
            constant = asyncgen_object_body.getFunctionName()
        ),
        "asyncgen_qualname_obj" : getFunctionQualnameObj(asyncgen_object_body, context),
        "code_identifier"       : context.getCodeObjectHandle(
            code_object = asyncgen_object_body.getCodeObject(),
        ),
        "closure_count"         : len(closure_variables)
    }
github Nuitka / Nuitka / nuitka / codegen / ParameterParsing.py View on Github external
def _getParameterParsingCode(all_parameter_variables):
    all_variable_count = len(all_parameter_variables)

    # First, declare all parameter objects as variables.
    parameter_parsing_code = """
PyObject *python_pars[ %(arg_count)d ] = { %(arg_init)s };
""" % {
        "arg_count" : all_variable_count or 1, # MSVC disallows 0.
        "arg_init"  : ", ".join(["NULL"] * (all_variable_count or 1))
    }

    return indented(parameter_parsing_code)
github Nuitka / Nuitka / nuitka / codegen / ModuleCodes.py View on Github external
else:
        module_exit = template_module_noexception_exit

    module_body_template_values = {
        "module_name": module_name,
        "module_name_obj": context.getConstantCode(constant=module_name),
        "is_main_module": 1 if is_main_module else 0,
        "is_package": 1 if is_package else 0,
        "is_top": 1 if is_top else 0,
        "module_identifier": module_identifier,
        "module_functions_decl": function_decl_codes,
        "module_functions_code": function_body_codes,
        "temps_decl": indented(local_var_inits),
        "module_code": indented(module_codes.codes),
        "module_exit": module_exit,
        "module_code_objects_decl": indented(getCodeObjectsDeclCode(context), 0),
        "module_code_objects_init": indented(getCodeObjectsInitCode(context), 1),
    }

    allocateNestedConstants(context)

    # Force internal module to not need constants init, by making all its
    # constants be shared.
    if is_internal_module:
        for constant in context.getConstants():
            context.global_context.countConstantUse(constant)

    return module_body_template_values
github Nuitka / Nuitka / nuitka / codegen / GeneratorCodes.py View on Github external
if local_type_decl:
        heap_declaration = """\
struct %(function_identifier)s_locals *generator_heap = \
(struct %(function_identifier)s_locals *)generator->m_heap_storage;""" % {
            "function_identifier": function_identifier
        }
    else:
        heap_declaration = ""

    return template_genfunc_yielder_body_template % {
        "function_identifier": function_identifier,
        "function_body": indented(function_codes.codes),
        "heap_declaration": indented(heap_declaration),
        "function_local_types": indented(local_type_decl),
        "function_var_inits": indented(function_locals),
        "function_dispatch": indented(getYieldReturnDispatchCode(context)),
        "generator_exit": generator_exit,
        "generator_module": getModuleAccessCode(context),
        "generator_name_obj": context.getConstantCode(
            constant=generator_object_body.getFunctionName()
        ),
        "generator_qualname_obj": getFunctionQualnameObj(
            generator_object_body, context
        ),
        "code_identifier": context.getCodeObjectHandle(
            code_object=generator_object_body.getCodeObject()
        ),
        "closure_count": len(closure_variables),
    }
github Nuitka / Nuitka / nuitka / codegen / LoaderCodes.py View on Github external
flags = ["NUITKA_BYTECODE_FLAG"]
        if is_package:
            flags.append("NUITKA_PACKAGE_FLAG")

        metapath_loader_inittab.append(
            template_metapath_loader_bytecode_module_entry
            % {
                "module_name": uncompiled_module.getFullName(),
                "bytecode": stream_data.getStreamDataOffset(code_data),
                "size": len(code_data),
                "flags": " | ".join(flags),
            }
        )

    return template_metapath_loader_body % {
        "metapath_module_decls": indented(metapath_module_decls, 0),
        "metapath_loader_inittab": indented(metapath_loader_inittab),
    }
github Nuitka / Nuitka / nuitka / codegen / ModuleCodes.py View on Github external
def getModuleCode(module_context, template_values):
    header = template_global_copyright % {
        "name": module_context.getName(),
        "version": getNuitkaVersion(),
        "year": getNuitkaVersionYear(),
    }

    decls, inits, checks = getConstantInitCodes(module_context)

    if module_context.needsModuleFilenameObject():
        decls.append("static PyObject *module_filename_obj;")

    template_values["constant_decl_codes"] = indented(decls, 0)

    template_values["constant_init_codes"] = indented(inits, 1)

    template_values["constant_check_codes"] = indented(checks, 1)

    return header + template_module_body_template % template_values