From 9266aa99eb57a5f316d67be5a74266927c34a998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Wed, 29 Jan 2025 14:34:23 +0100 Subject: [PATCH 01/17] Fix FLINT version to 3.1.3 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 69722ccf0..219156912 100644 --- a/Project.toml +++ b/Project.toml @@ -14,7 +14,7 @@ TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76" [compat] AbstractAlgebra = "0.44.2" -FLINT_jll = "^300.100.100" +FLINT_jll = "~300.100.300" Libdl = "1.6" LinearAlgebra = "1.6" Random = "1.6" From d6f57dbdc7929ad742576c5ff29435a25c4a346e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Wed, 29 Jan 2025 18:04:06 +0100 Subject: [PATCH 02/17] Add a script that converts FLINT headers to julia types --- etc/generate_FLINT_structs.jl | 153 +++++ src/flint/FlintCTypes.jl | 901 ++++++++++++++++++++++++++++++ src/flint/FlintCTypes_template.jl | 78 +++ 3 files changed, 1132 insertions(+) create mode 100644 etc/generate_FLINT_structs.jl create mode 100644 src/flint/FlintCTypes.jl create mode 100644 src/flint/FlintCTypes_template.jl diff --git a/etc/generate_FLINT_structs.jl b/etc/generate_FLINT_structs.jl new file mode 100644 index 000000000..ae30c5437 --- /dev/null +++ b/etc/generate_FLINT_structs.jl @@ -0,0 +1,153 @@ +VERSION >= v"1.9" || error("This script requires Julia 1.7 or later") + +const headerfile_begin_regex = r"#ifdef __cplusplus\s*extern \"C\"\s*\{\s*#endif" +const headerfile_end_regex = r"#ifdef __cplusplus\s*\}\s*#endif" + +function expand_templates(input, flintdir) + matches = eachmatch(r"^@include_c_header\(\"([A-Za-z_.]+)\"\)$"m, input) + substitutions = Pair{String,String}[] + for m in matches + filename = m.captures[1] + @info "Including header \"$filename\"" + template_key = "@include_c_header(\"$filename\")" + + # Read the file + content = open(joinpath(flintdir, filename)) do headerfile + read(headerfile, String) + end + # Restrict to the relevant part (ignore include guards etc.) + begin_match = match(headerfile_begin_regex, content) + @assert !isnothing(begin_match) + end_match = match(headerfile_end_regex, content) + @assert !isnothing(end_match) + relevant_content = content[(begin_match.offset + length(begin_match.match)):(end_match.offset - 1)] + # Convert to julia + translated_content = c2julia(relevant_content) + # Build the substitution value + template_val = + "###############################################################################\n" * + "# begin $filename\n\n" * + strip(translated_content) * + "\n\n# end $filename\n" * + "###############################################################################\n" + push!(substitutions, template_key => template_val) + end + return replace(input, substitutions...) +end + +const regex_typedef_struct_fields_name = r"typedef struct\s*\{([^{}]+)\}\s*([a-z_]+);" +const regex_typedef_struct_fields_ptrname = r"typedef struct\s*\{([^{}]+)\}\s*([a-z_]+)\[1\];" +const regex_struct_structname_fields = r"struct *([a-z_]+)\s*\{([^{}]+)\}\s*;" +const regex_typedef_struct_structname_fields_name = r"typedef struct *([a-z_]+)\s*\{([^{}]+)\}\s*([a-z_]+);" + +const regex_typedef_enum_values_name = r"typedef enum\s*\{([^{}]+)\}\s*([a-z_]+);" +const regex_enum_enumname_values = r"enum *([a-z_]+)\s*\{([^{}]+)\}\s*;" +const regex_typedef_enum_enumname_values_name = r"typedef enum *([a-z_]+)\s*\{([^{}]+)\}\s*([a-z_]+);" + +function convert_struct(str) + substitutions = Pair{Regex,Union{SubstitutionString, Function}}[ + regex_typedef_struct_fields_name => s"struct \2\1end", # whole typedef struct construct + regex_struct_structname_fields => s"struct struct_\1\2end", # whole struct construct + regex_typedef_struct_fields_ptrname => s"struct struct_\2\1end\nconst \2 = Ptr{struct_\2}", # whole typedef struct construct with [1] + regex_typedef_struct_structname_fields_name => s"struct \3\2end\nconst struct_\1 = \3", # whole typedef struct construct with two names + r"^( +)const "m => s"\1", # remove `const` from fields + r"^ +([a-z_]+) +([A-Za-z0-9_]+);"m => s" \2::\1", # simple fields (one to five declared on one line) + r"^ +([a-z_]+) +([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+);"m => s" \2::\1\n \3::\1", + r"^ +([a-z_]+) +([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+);"m => s" \2::\1\n \3::\1\n \4::\1", + r"^ +([a-z_]+) +([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+);"m => s" \2::\1\n \3::\1\n \4::\1\n \5::\1", + r"^ +([a-z_]+) +([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+);"m => s" \2::\1\n \3::\1\n \4::\1\n \5::\1\n \6::\1", + r"^ +([a-z_]+) *\* *([A-Za-z0-9_]+);"m => s" \2::Ptr{\1}", # pointer field (one to five declared on one line) + r"^ +([a-z_]+) *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+);"m => s" \2::Ptr{\1}\n \3::Ptr{\1}", + r"^ +([a-z_]+) *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+);"m => s" \2::Ptr{\1}\n \3::Ptr{\1}\n \4::Ptr{\1}", + r"^ +([a-z_]+) *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+);"m => s" \2::Ptr{\1}\n \3::Ptr{\1}\n \4::Ptr{\1}\n \5::Ptr{\1}", + r"^ +([a-z_]+) *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+);"m => s" \2::Ptr{\1}\n \3::Ptr{\1}\n \4::Ptr{\1}\n \5::Ptr{\1}\n \6::Ptr{\1}", + r"^ +([a-z_]+) *\* *\* *([A-Za-z0-9_]+);"m => s" \2::Ptr{Ptr{\1}}", # double pointer field + r"^ +([a-z_]+) +([A-Za-z0-9_]+)\[([A-Za-z0-9_]+)\];"m => s" \2::NTuple{\3, \1}", # fixed len array field + r"^ +[a-z_]+ *\( *\* *([A-Za-z0-9_]+) *\) *\([a-z_, *]+\);"m => s" \1::Ptr{Nothing}", # function pointer field + r"^ +struct *([a-z_]+) +([A-Za-z0-9_]+);"m => s" \2::struct_\1", # struct field (without typedef) + r"^ +enum *([a-z_]+) +([A-Za-z0-9_]+);"m => s" \2::enum_\1", # enum field (without typedef) + ] + for substitution in substitutions + str = replace(str, substitution) + end + return str +end + +function convert_enum(str) + substitutions = Pair{Regex,Union{SubstitutionString, Function}}[ + regex_typedef_enum_values_name => s"@enum \2 begin\1end", # whole typedef enum construct + regex_enum_enumname_values => s"@enum enum_\1 begin\2end", # whole enum construct + regex_typedef_enum_enumname_values_name => s"@enum \3 begin\2end\nconst enum_\1 = \3", # whole typedef enum construct with two names + r"^ +([A-Za-z0-9_]+),?"m => s" \1", # simple enum values + ] + for substitution in substitutions + str = replace(str, substitution) + end + return str +end + +function c2julia(str::String) + substitutions = Pair{Regex,Union{SubstitutionString, Function}}[ + r"unsigned int" => s"unsigned_int", # convert `unsigned int` to a single token + r"unsigned char" => s"unsigned_char", # convert `unsigned char` to a single token + regex_typedef_struct_fields_name => convert_struct, # whole typedef struct construct + regex_typedef_struct_fields_ptrname => convert_struct, # whole typedef struct construct with [1] + regex_struct_structname_fields => convert_struct, # whole struct construct + regex_typedef_struct_structname_fields_name => convert_struct, # whole typedef struct construct with two names + regex_typedef_enum_values_name => convert_enum, # whole typedef enum construct + regex_enum_enumname_values => convert_enum, # whole enum construct + regex_typedef_enum_enumname_values_name => convert_enum, # whole typedef enum construct with two names + r"^typedef ([A-Za-z_]+) ([A-Za-z_]+);"m => s"const \2 = \1", # simple typedef + r"^typedef ([A-Za-z_]+) ([A-Za-z_]+)\[1\];"m => s"const \2 = Ptr{\1}", # pointer typedef + r"^#define ([A-Za-z_]+) ([A-Za-z0-9_]+)"m => s"const \1 = \2", # defines used as typedef + r"^//(.*)$"m => s"#\1", # line comment + r"/\*(.*?)\*/"s => s"#=\1=#", # block comment + ] + for substitution in substitutions + str = replace(str, substitution) + end + return str +end + +file_header_notice(FLINT_jll_version) = """ +# Most of this file is generated from FLINT's header files. +# Do not edit manually, only the corresponding `*_template.jl` should be edited. + +# This file was generated using FLINT_jll v$(FLINT_jll_version). + +""" + +################################################################################ +# +# Main script +# +################################################################################ + +function expand_template_file(infile::String, outfile::String, flintpath::String, file_header::String) + @info "Expanding file" infile outfile + open(outfile, "w") do io + write(io, file_header) + write(io, expand_templates(read(infile, String), joinpath(flintpath, "include", "flint"))) + end +end + +function main() + flintpath = FLINT_jll.find_artifact_dir() + flintversion = pkgversion(FLINT_jll) + @info "Found FLINT" flintpath flintversion + + infile = joinpath(nemopath, "src", "flint", "FlintCTypes_template.jl") + outfile = joinpath(nemopath, "src", "flint", "FlintCTypes.jl") + expand_template_file(infile, outfile, flintpath, file_header_notice(flintversion)) +end + +const nemopath = dirname(dirname(@__FILE__)) + +@info "Setting up environment" +using Pkg +Pkg.activate(; temp=true) +Pkg.develop(PackageSpec(; path=nemopath)) +Pkg.add("FLINT_jll") # version is fixed by Nemo.jl in the line above +using FLINT_jll + +main() diff --git a/src/flint/FlintCTypes.jl b/src/flint/FlintCTypes.jl new file mode 100644 index 000000000..84ff82bb3 --- /dev/null +++ b/src/flint/FlintCTypes.jl @@ -0,0 +1,901 @@ +# Most of this file is generated from FLINT's header files. +# Do not edit manually, only the corresponding `*_template.jl` should be edited. + +# This file was generated using FLINT_jll v300.100.301+0. + +############################################################################### +# +# Flint C types +# +############################################################################### + +module FlintC + +# +# C types (names provided to ease automatic conversion of struct definitions) +# +const void = Cvoid +const int = Cint +const unsigned_int = Cuint +const char = Cchar +const unsigned_char = Cuchar +const double = Cdouble + +# +# from gmp.h +# + +const mp_limb_t = Base.GMP.Limb +const mp_limb_signed_t = signed(Base.GMP.Limb) +const mp_bitcnt_t = Base.GMP.MPZ.bitcnt_t + +const mp_ptr = Ptr{mp_limb_t} +const mp_srcptr = Ptr{mp_limb_t} + +# +# from flint.h +# + +const ulong = mp_limb_t +const slong = mp_limb_signed_t +const flint_bitcnt_t = ulong +const FLINT_BITS = Base.GMP.BITS_PER_LIMB + +struct nmod_t + n::mp_limb_t + ninv::mp_limb_t + norm::flint_bitcnt_t +end + +const fmpz = slong +const fmpz_t = Ptr{fmpz} + +struct fmpq + num::fmpz + den::fmpz +end + +const fmpq_t = Ptr{fmpq} + + +############################################################################### +# begin limb_types.h + +const FLINT_MAX_FACTORS_IN_LIMB = 15 + +struct n_factor_t + num::int + exp::NTuple{FLINT_MAX_FACTORS_IN_LIMB, int} + p::NTuple{FLINT_MAX_FACTORS_IN_LIMB, ulong} +end + +struct n_primes_struct + small_i::slong + small_num::slong + small_primes::Ptr{unsigned_int} + + sieve_a::ulong + sieve_b::ulong + sieve_i::slong + sieve_num::slong + sieve::Ptr{char} +end + +const n_primes_t = Ptr{n_primes_struct} + +# end limb_types.h +############################################################################### + + +############################################################################### +# begin nmod_types.h + +struct nmod_mat_struct + entries::Ptr{mp_limb_t} + r::slong + c::slong + rows::Ptr{Ptr{mp_limb_t}} + mod::nmod_t +end + +const nmod_mat_t = Ptr{nmod_mat_struct} + +struct nmod_poly_struct + coeffs::mp_ptr + alloc::slong + length::slong + mod::nmod_t +end + +const nmod_poly_t = Ptr{nmod_poly_struct} + +struct nmod_poly_factor_struct + p::Ptr{nmod_poly_struct} + exp::Ptr{slong} + num::slong + alloc::slong +end + +const nmod_poly_factor_t = Ptr{nmod_poly_factor_struct} + +struct nmod_poly_mat_struct + entries::Ptr{nmod_poly_struct} + r::slong + c::slong + rows::Ptr{Ptr{nmod_poly_struct}} + modulus::mp_limb_t +end + +const nmod_poly_mat_t = Ptr{nmod_poly_mat_struct} + +struct nmod_mpoly_struct + coeffs::Ptr{mp_limb_t} + exps::Ptr{ulong} + length::slong + bits::flint_bitcnt_t #= number of bits per exponent =# + coeffs_alloc::slong #= abs size in mp_limb_t units =# + exps_alloc::slong #= abs size in ulong units =# +end + +const nmod_mpoly_t = Ptr{nmod_mpoly_struct} + +struct nmod_mpoly_factor_struct + constant::mp_limb_t + poly::Ptr{nmod_mpoly_struct} + exp::Ptr{fmpz} + num::slong + alloc::slong +end + +const nmod_mpoly_factor_t = Ptr{nmod_mpoly_factor_struct} + +# end nmod_types.h +############################################################################### + + +############################################################################### +# begin fmpz_types.h + +struct fmpz_factor_struct + sign::int + p::Ptr{fmpz} + exp::Ptr{ulong} + alloc::slong + num::slong +end + +const fmpz_factor_t = Ptr{fmpz_factor_struct} + +struct fmpz_preinvn_struct + dinv::mp_ptr + n::slong + norm::flint_bitcnt_t +end + +const fmpz_preinvn_t = Ptr{fmpz_preinvn_struct} + +struct fmpz_poly_struct + coeffs::Ptr{fmpz} + alloc::slong + length::slong +end + +const fmpz_poly_t = Ptr{fmpz_poly_struct} + +struct fmpz_poly_factor_struct + c::fmpz + p::Ptr{fmpz_poly_struct} + exp::Ptr{slong} + num::slong + alloc::slong +end + +const fmpz_poly_factor_t = Ptr{fmpz_poly_factor_struct} + +struct fmpz_mat_struct + entries::Ptr{fmpz} + r::slong + c::slong + rows::Ptr{Ptr{fmpz}} +end + +const fmpz_mat_t = Ptr{fmpz_mat_struct} + +struct fmpz_poly_mat_struct + entries::Ptr{fmpz_poly_struct} + r::slong + c::slong + rows::Ptr{Ptr{fmpz_poly_struct}} +end + +const fmpz_poly_mat_t = Ptr{fmpz_poly_mat_struct} + +struct fmpz_mpoly_struct + coeffs::Ptr{fmpz} #= alloc fmpzs =# + exps::Ptr{ulong} + alloc::slong + length::slong + bits::flint_bitcnt_t #= number of bits per exponent =# +end + +const fmpz_mpoly_t = Ptr{fmpz_mpoly_struct} + +struct fmpz_mpoly_factor_struct + constant::fmpz_t + constant_den::fmpz_t #= should be one after normal operations =# + poly::Ptr{fmpz_mpoly_struct} + exp::Ptr{fmpz} + num::slong + alloc::slong +end + +const fmpz_mpoly_factor_t = Ptr{fmpz_mpoly_factor_struct} + +struct fmpz_poly_q_struct + num::Ptr{fmpz_poly_struct} + den::Ptr{fmpz_poly_struct} +end + +const fmpz_poly_q_t = Ptr{fmpz_poly_q_struct} + +struct fmpz_mpoly_q_struct + num::fmpz_mpoly_struct + den::fmpz_mpoly_struct +end + +const fmpz_mpoly_q_t = Ptr{fmpz_mpoly_q_struct} + +struct fmpzi_struct + a::fmpz + b::fmpz +end + +const fmpzi_t = Ptr{fmpzi_struct} + +# end fmpz_types.h +############################################################################### + + +############################################################################### +# begin fmpq_types.h + +struct fmpq_mat_struct + entries::Ptr{fmpq} + r::slong + c::slong + rows::Ptr{Ptr{fmpq}} +end + +const fmpq_mat_t = Ptr{fmpq_mat_struct} + +struct fmpq_poly_struct + coeffs::Ptr{fmpz} + alloc::slong + length::slong + den::fmpz_t +end + +const fmpq_poly_t = Ptr{fmpq_poly_struct} + +#= + A polynomial f is represented as + content * zpoly, + where zpoly should have positive leading coefficient and trivial content. + If f is zero, then the representation should have + content = 0 and zpoly = 0 +=# + +struct fmpq_mpoly_struct #= non zero case: | zero case: =# + content::fmpq_t #= positive or negative content | zero =# + zpoly::fmpz_mpoly_t #= contentless poly, lc is positive | zero =# +end + +const fmpq_mpoly_t = Ptr{fmpq_mpoly_struct} + +struct fmpq_mpoly_factor_struct + constant::fmpq_t + poly::Ptr{fmpq_mpoly_struct} + exp::Ptr{fmpz} + num::slong + alloc::slong +end + +const fmpq_mpoly_factor_t = Ptr{fmpq_mpoly_factor_struct} + +# end fmpq_types.h +############################################################################### + + +############################################################################### +# begin fmpz_mod_types.h + +struct fmpz_mod_ctx_struct + n::fmpz_t + add_fxn::Ptr{Nothing} + sub_fxn::Ptr{Nothing} + mul_fxn::Ptr{Nothing} + mod::nmod_t + n_limbs::NTuple{3, ulong} + ninv_limbs::NTuple{3, ulong} + ninv_huge::Ptr{fmpz_preinvn_struct} +end +const struct_fmpz_mod_ctx = fmpz_mod_ctx_struct + +const fmpz_mod_ctx_t = Ptr{fmpz_mod_ctx_struct} + +const fmpz_mod_mat_struct = fmpz_mat_struct + +const fmpz_mod_mat_t = Ptr{fmpz_mod_mat_struct} + +struct fmpz_mod_poly_struct + coeffs::Ptr{fmpz} + alloc::slong + length::slong +end + +const fmpz_mod_poly_t = Ptr{fmpz_mod_poly_struct} + +struct fmpz_mod_poly_factor_struct + poly::Ptr{fmpz_mod_poly_struct} + exp::Ptr{slong} + num::slong + alloc::slong +end + +const fmpz_mod_poly_factor_t = Ptr{fmpz_mod_poly_factor_struct} + +struct fmpz_mod_mpoly_struct + coeffs::Ptr{fmpz} + exps::Ptr{ulong} + length::slong + bits::flint_bitcnt_t #= number of bits per exponent =# + coeffs_alloc::slong #= abs size in mp_limb_t units =# + exps_alloc::slong #= abs size in ulong units =# +end + +const fmpz_mod_mpoly_t = Ptr{fmpz_mod_mpoly_struct} + +struct fmpz_mod_mpoly_factor_struct + constant::fmpz_t + poly::Ptr{fmpz_mod_mpoly_struct} + exp::Ptr{fmpz} + num::slong + alloc::slong +end + +const fmpz_mod_mpoly_factor_t = Ptr{fmpz_mod_mpoly_factor_struct} + +# end fmpz_mod_types.h +############################################################################### + + +############################################################################### +# begin fq_nmod_types.h + +const fq_nmod_t = nmod_poly_t +const fq_nmod_struct = nmod_poly_struct + +struct fq_nmod_ctx_struct + mod::nmod_t + + sparse_modulus::int + is_conway::int #= whether field was generated using Flint Conway table (assures primitivity =# + + a::Ptr{mp_limb_t} + j::Ptr{slong} + len::slong + + modulus::nmod_poly_t + inv::nmod_poly_t + + var::Ptr{char} +end + +const fq_nmod_ctx_t = Ptr{fq_nmod_ctx_struct} + +struct fq_nmod_mat_struct + entries::Ptr{fq_nmod_struct} + r::slong + c::slong + rows::Ptr{Ptr{fq_nmod_struct}} +end + +const fq_nmod_mat_t = Ptr{fq_nmod_mat_struct} + +struct fq_nmod_poly_struct + coeffs::Ptr{fq_nmod_struct} + alloc::slong + length::slong +end + +const fq_nmod_poly_t = Ptr{fq_nmod_poly_struct} + +struct fq_nmod_poly_factor_struct + poly::Ptr{fq_nmod_poly_struct} + exp::Ptr{slong} + num::slong + alloc::slong +end + +const fq_nmod_poly_factor_t = Ptr{fq_nmod_poly_factor_struct} + +struct fq_nmod_mpoly_struct + coeffs::Ptr{mp_limb_t} + exps::Ptr{ulong} + length::slong + bits::flint_bitcnt_t #= number of bits per exponent =# + coeffs_alloc::slong #= abs size in mp_limb_t units =# + exps_alloc::slong #= abs size in ulong units =# +end + +const fq_nmod_mpoly_t = Ptr{fq_nmod_mpoly_struct} + +# end fq_nmod_types.h +############################################################################### + + +############################################################################### +# begin fq_zech_types.h + +struct fq_zech_struct + value::mp_limb_t +end + +const fq_zech_t = Ptr{fq_zech_struct} + +struct fq_zech_ctx_struct + qm1::ulong #= q - 1 =# + qm1o2::ulong #= (q - 1) / 2 or 1 when p == 2 =# + qm1opm1::ulong #= (q - 1) / (p - 1) =# + p::ulong + ppre::double + prime_root::ulong #= primitive root for prime subfield =# + zech_log_table::Ptr{ulong} + prime_field_table::Ptr{ulong} + eval_table::Ptr{ulong} + + fq_nmod_ctx::Ptr{fq_nmod_ctx_struct} + owns_fq_nmod_ctx::int + is_conway::int #= whether field was generated using Flint Conway tables (assures primitivity) =# +end + +const fq_zech_ctx_t = Ptr{fq_zech_ctx_struct} + +struct fq_zech_mat_struct + entries::Ptr{fq_zech_struct} + r::slong + c::slong + rows::Ptr{Ptr{fq_zech_struct}} +end + +const fq_zech_mat_t = Ptr{fq_zech_mat_struct} + +struct fq_zech_poly_struct + coeffs::Ptr{fq_zech_struct} + alloc::slong + length::slong +end + +const fq_zech_poly_t = Ptr{fq_zech_poly_struct} + +struct fq_zech_poly_factor_struct + poly::Ptr{fq_zech_poly_struct} + exp::Ptr{slong} + num::slong + alloc::slong +end + +const fq_zech_poly_factor_t = Ptr{fq_zech_poly_factor_struct} + +# end fq_zech_types.h +############################################################################### + + +############################################################################### +# begin fq_types.h + +const fq_t = fmpz_poly_t +const fq_struct = fmpz_poly_struct + +struct fq_ctx_struct + ctxp::fmpz_mod_ctx_t + + sparse_modulus::int + is_conway::int #= whether field was initialized with the Flint Conway tables (assures primitivity) =# + + a::Ptr{fmpz} + j::Ptr{slong} + len::slong + + modulus::fmpz_mod_poly_t + inv::fmpz_mod_poly_t + + var::Ptr{char} +end + +const fq_ctx_t = Ptr{fq_ctx_struct} + +struct fq_mat_struct + entries::Ptr{fq_struct} + r::slong + c::slong + rows::Ptr{Ptr{fq_struct}} +end + +const fq_mat_t = Ptr{fq_mat_struct} + +struct fq_poly_struct + coeffs::Ptr{fq_struct} + alloc::slong + length::slong +end + +const fq_poly_t = Ptr{fq_poly_struct} + +struct fq_poly_factor_struct + poly::Ptr{fq_poly_struct} + exp::Ptr{slong} + num::slong + alloc::slong +end + +const fq_poly_factor_t = Ptr{fq_poly_factor_struct} + +# end fq_types.h +############################################################################### + + +############################################################################### +# begin padic_types.h + +struct padic_struct + u::fmpz + v::slong + N::slong +end + +const padic_t = Ptr{padic_struct} + +@enum enum_padic_print_mode begin + PADIC_TERSE + PADIC_SERIES + PADIC_VAL_UNIT +end + +struct padic_ctx_struct + p::fmpz_t + pinv::double + pow::Ptr{fmpz} + min::slong + max::slong + mode::enum_padic_print_mode +end + +const padic_ctx_t = Ptr{padic_ctx_struct} + +struct padic_inv_struct + n::slong + pow::Ptr{fmpz} +end + +const padic_inv_t = Ptr{padic_inv_struct} + +struct padic_mat_struct + mat::fmpz_mat_struct + val::slong + N::slong +end + +const padic_mat_t = Ptr{padic_mat_struct} + +struct padic_poly_struct + coeffs::Ptr{fmpz} + alloc::slong + length::slong + val::slong + N::slong +end + +const padic_poly_t = Ptr{padic_poly_struct} + +# end padic_types.h +############################################################################### + + +############################################################################### +# begin n_poly_types.h + +#= arrays of ulong =# +struct n_poly_struct + coeffs::Ptr{mp_limb_t} + alloc::slong + length::slong +end + +const n_poly_t = Ptr{n_poly_struct} +const n_fq_poly_struct = n_poly_struct +const n_fq_poly_t = n_poly_t + +#= arrays of arrays of ulong =# +struct n_bpoly_struct + coeffs::Ptr{n_poly_struct} + alloc::slong + length::slong +end + +const n_bpoly_t = Ptr{n_bpoly_struct} +const n_fq_bpoly_struct = n_bpoly_struct +const n_fq_bpoly_t = n_bpoly_t + +#= arrays of arrays of arrays of ulong =# +struct n_tpoly_struct + coeffs::Ptr{n_bpoly_struct} + alloc::slong + length::slong +end + +const n_tpoly_t = Ptr{n_tpoly_struct} +const n_fq_tpoly_struct = n_tpoly_struct +const n_fq_tpoly_t = n_tpoly_t + +#= sparse arrays of ulong =# +struct n_polyu_struct + exps::Ptr{ulong} + coeffs::Ptr{mp_limb_t} + length::slong + alloc::slong +end + +const n_polyu_t = Ptr{n_polyu_struct} +const n_fq_polyu_struct = n_polyu_struct +const n_fq_polyu_t = n_polyu_t + +#= + sparse arrays of arrays of ulong + n_polyu1n => one exponent is in the exps[i] + n_polyu2n => two exponents are packed into the exps[i] + ... +=# +struct n_polyun_struct + coeffs::Ptr{n_poly_struct} + exps::Ptr{ulong} + length::slong + alloc::slong +end + +const n_polyun_t = Ptr{n_polyun_struct} +const n_fq_polyun_struct = n_polyun_struct +const n_fq_polyun_t = n_polyun_t + +#= n_poly stack =# +struct n_poly_stack_struct + array::Ptr{Ptr{n_poly_struct}} + alloc::slong + top::slong +end + +const n_poly_stack_t = Ptr{n_poly_stack_struct} + +#= n_bpoly stack =# +struct n_bpoly_stack_struct + array::Ptr{Ptr{n_bpoly_struct}} + alloc::slong + top::slong +end + +const n_bpoly_stack_t = Ptr{n_bpoly_stack_struct} + +struct n_poly_bpoly_stack_struct + poly_stack::n_poly_stack_t + bpoly_stack::n_bpoly_stack_t +end + +const n_poly_bpoly_stack_t = Ptr{n_poly_bpoly_stack_struct} + +struct nmod_eval_interp_struct + M::Ptr{mp_limb_t} + T::Ptr{mp_limb_t} + Q::Ptr{mp_limb_t} + array::Ptr{mp_limb_t} + alloc::slong + d::slong + radix::slong + w::mp_limb_t +end + +const nmod_eval_interp_t = Ptr{nmod_eval_interp_struct} + +# end n_poly_types.h +############################################################################### + + +############################################################################### +# begin mpoly_types.h + +#define MPOLY_MIN_BITS (UWORD(8)) #= minimum number of bits to pack into =# + +@enum ordering_t begin + ORD_LEX + ORD_DEGLEX + ORD_DEGREVLEX +end + +const MPOLY_NUM_ORDERINGS = 3 + +struct mpoly_ctx_struct + nvars::slong #= number of variables =# + nfields::slong #= number of fields in exponent vector =# + ord::ordering_t #= monomial ordering =# + deg::int #= is ord a degree ordering? =# + rev::int #= is ord a reversed ordering? =# + lut_words_per_exp::NTuple{FLINT_BITS, slong} + lut_fix_bits::NTuple{FLINT_BITS, unsigned_char} #= FLINT_BITS < 256 =# +end + +const mpoly_ctx_t = Ptr{mpoly_ctx_struct} + +struct nmod_mpoly_ctx_struct + minfo::mpoly_ctx_t + mod::nmod_t +end + +const nmod_mpoly_ctx_t = Ptr{nmod_mpoly_ctx_struct} + +struct fmpz_mpoly_ctx_struct + minfo::mpoly_ctx_t +end + +const fmpz_mpoly_ctx_t = Ptr{fmpz_mpoly_ctx_struct} + +struct fmpq_mpoly_ctx_struct + zctx::fmpz_mpoly_ctx_t +end + +const fmpq_mpoly_ctx_t = Ptr{fmpq_mpoly_ctx_struct} + +struct fmpz_mod_mpoly_ctx_struct + minfo::mpoly_ctx_t + ffinfo::fmpz_mod_ctx_t +end + +const fmpz_mod_mpoly_ctx_t = Ptr{fmpz_mod_mpoly_ctx_struct} + +struct fq_nmod_mpoly_ctx_struct + minfo::mpoly_ctx_t + fqctx::fq_nmod_ctx_t +end + +const fq_nmod_mpoly_ctx_t = Ptr{fq_nmod_mpoly_ctx_struct} + + +struct struct_mpoly_void_ring_t + elem_size::slong + ctx::Ptr{void} + init::Ptr{Nothing} + clear::Ptr{Nothing} + is_zero::Ptr{Nothing} + zero::Ptr{Nothing} + one::Ptr{Nothing} + set_fmpz::Ptr{Nothing} + set::Ptr{Nothing} + swap::Ptr{Nothing} + neg::Ptr{Nothing} + add::Ptr{Nothing} + sub::Ptr{Nothing} + mul_fmpz::Ptr{Nothing} + mul::Ptr{Nothing} + divexact::Ptr{Nothing} + divides::Ptr{Nothing} + pow_fmpz::Ptr{Nothing} + length::Ptr{Nothing} +end +const mpoly_void_ring_t = Ptr{struct_mpoly_void_ring_t} + +struct mpoly_gcd_info_struct + Amax_exp::Ptr{ulong} + Amin_exp::Ptr{ulong} + Astride::Ptr{ulong} + Adeflate_deg::Ptr{slong} + Alead_count::Ptr{slong} + Atail_count::Ptr{slong} + + Bmax_exp::Ptr{ulong} + Bmin_exp::Ptr{ulong} + Bstride::Ptr{ulong} + Bdeflate_deg::Ptr{slong} + Blead_count::Ptr{slong} + Btail_count::Ptr{slong} + + Gmin_exp::Ptr{ulong} + Abarmin_exp::Ptr{ulong} + Bbarmin_exp::Ptr{ulong} + Gstride::Ptr{ulong} + Gterm_count_est::Ptr{slong} + Gdeflate_deg_bound::Ptr{slong} + + Gbits::flint_bitcnt_t + Abarbits::flint_bitcnt_t + Bbarbits::flint_bitcnt_t + + mvars::slong + Adeflate_tdeg::slong + Bdeflate_tdeg::slong + + Adensity::double + Bdensity::double + + hensel_time::double + brown_time::double + zippel_time::double + zippel2_time::double + hensel_perm::Ptr{slong} + brown_perm::Ptr{slong} + zippel_perm::Ptr{slong} + zippel2_perm::Ptr{slong} + can_use::unsigned_int + Gdeflate_deg_bounds_are_nice::int #= all of Gdeflate_deg_bound came from real gcd computations =# + + data::Ptr{char} +end + +const mpoly_gcd_info_t = Ptr{mpoly_gcd_info_struct} + +struct mpoly_compression_struct + mvars::slong + nvars::slong + exps::Ptr{slong} + exps_alloc::slong + rest::Ptr{slong} + rest_alloc::slong + umat::Ptr{slong} + deltas::Ptr{slong} + degs::Ptr{slong} + is_trivial::int + is_perm::int + is_irred::int +end + +const mpoly_compression_t = Ptr{mpoly_compression_struct} + +#= + nmod_mpolyn_t + multivariates with n_poly_t coefficients +=# +struct nmod_mpolyn_struct + coeffs::Ptr{n_poly_struct} + exps::Ptr{ulong} + alloc::slong + length::slong + bits::slong +end +const nmod_mpolyn_t = Ptr{nmod_mpolyn_struct} + +#= + nmod_mpolyun_t + sparse univariates with nmod_mpolyn_t coefficients + with uniform bits and LEX ordering +=# +struct nmod_mpolyun_struct + coeffs::Ptr{nmod_mpolyn_struct} + exps::Ptr{ulong} + alloc::slong + length::slong + bits::flint_bitcnt_t #= default bits to construct coeffs =# +end +const nmod_mpolyun_t = Ptr{nmod_mpolyun_struct} + +@enum nmod_gcds_ret_t begin + nmod_gcds_success + nmod_gcds_form_main_degree_too_high + nmod_gcds_form_wrong + nmod_gcds_no_solution + nmod_gcds_scales_not_found + nmod_gcds_eval_point_not_found + nmod_gcds_eval_gcd_deg_too_high +end + +# end mpoly_types.h +############################################################################### + + +end # module FlintC diff --git a/src/flint/FlintCTypes_template.jl b/src/flint/FlintCTypes_template.jl new file mode 100644 index 000000000..76c9e8e53 --- /dev/null +++ b/src/flint/FlintCTypes_template.jl @@ -0,0 +1,78 @@ +############################################################################### +# +# Flint C types +# +############################################################################### + +module FlintC + +# +# C types (names provided to ease automatic conversion of struct definitions) +# +const void = Cvoid +const int = Cint +const unsigned_int = Cuint +const char = Cchar +const unsigned_char = Cuchar +const double = Cdouble + +# +# from gmp.h +# + +const mp_limb_t = Base.GMP.Limb +const mp_limb_signed_t = signed(Base.GMP.Limb) +const mp_bitcnt_t = Base.GMP.MPZ.bitcnt_t + +const mp_ptr = Ptr{mp_limb_t} +const mp_srcptr = Ptr{mp_limb_t} + +# +# from flint.h +# + +const ulong = mp_limb_t +const slong = mp_limb_signed_t +const flint_bitcnt_t = ulong +const FLINT_BITS = Base.GMP.BITS_PER_LIMB + +struct nmod_t + n::mp_limb_t + ninv::mp_limb_t + norm::flint_bitcnt_t +end + +const fmpz = slong +const fmpz_t = Ptr{fmpz} + +struct fmpq + num::fmpz + den::fmpz +end + +const fmpq_t = Ptr{fmpq} + + +@include_c_header("limb_types.h") + +@include_c_header("nmod_types.h") + +@include_c_header("fmpz_types.h") + +@include_c_header("fmpq_types.h") + +@include_c_header("fmpz_mod_types.h") + +@include_c_header("fq_nmod_types.h") + +@include_c_header("fq_zech_types.h") + +@include_c_header("fq_types.h") + +@include_c_header("padic_types.h") + +@include_c_header("n_poly_types.h") + +@include_c_header("mpoly_types.h") + +end # module FlintC From 82413f1c92ad94b6772e5e586685baf8801bc268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Thu, 30 Jan 2025 14:39:46 +0100 Subject: [PATCH 03/17] Move template to `/etc` --- {src/flint => etc}/FlintCTypes_template.jl | 0 etc/generate_FLINT_structs.jl | 4 ++-- src/flint/FlintCTypes.jl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename {src/flint => etc}/FlintCTypes_template.jl (100%) diff --git a/src/flint/FlintCTypes_template.jl b/etc/FlintCTypes_template.jl similarity index 100% rename from src/flint/FlintCTypes_template.jl rename to etc/FlintCTypes_template.jl diff --git a/etc/generate_FLINT_structs.jl b/etc/generate_FLINT_structs.jl index ae30c5437..66b7441ec 100644 --- a/etc/generate_FLINT_structs.jl +++ b/etc/generate_FLINT_structs.jl @@ -111,7 +111,7 @@ end file_header_notice(FLINT_jll_version) = """ # Most of this file is generated from FLINT's header files. -# Do not edit manually, only the corresponding `*_template.jl` should be edited. +# Do not edit manually, only the corresponding `etc/*_template.jl` file should be edited. # This file was generated using FLINT_jll v$(FLINT_jll_version). @@ -136,7 +136,7 @@ function main() flintversion = pkgversion(FLINT_jll) @info "Found FLINT" flintpath flintversion - infile = joinpath(nemopath, "src", "flint", "FlintCTypes_template.jl") + infile = joinpath(nemopath, "etc", "FlintCTypes_template.jl") outfile = joinpath(nemopath, "src", "flint", "FlintCTypes.jl") expand_template_file(infile, outfile, flintpath, file_header_notice(flintversion)) end diff --git a/src/flint/FlintCTypes.jl b/src/flint/FlintCTypes.jl index 84ff82bb3..dc1ddc0b3 100644 --- a/src/flint/FlintCTypes.jl +++ b/src/flint/FlintCTypes.jl @@ -1,5 +1,5 @@ # Most of this file is generated from FLINT's header files. -# Do not edit manually, only the corresponding `*_template.jl` should be edited. +# Do not edit manually, only the corresponding `etc/*_template.jl` file should be edited. # This file was generated using FLINT_jll v300.100.301+0. From 465444faa0abad16a7a214a54a3fc1ada200e778 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Thu, 30 Jan 2025 16:11:15 +0100 Subject: [PATCH 04/17] Use Overrides.toml with FLINT 3.2.0-rc1 --- .gitignore | 2 ++ Project.toml | 2 +- etc/FlintCTypes_template.jl | 18 +++------- src/Nemo.jl | 2 ++ src/flint/FlintCTypes.jl | 68 +++++++++++++++++++------------------ 5 files changed, 45 insertions(+), 47 deletions(-) diff --git a/.gitignore b/.gitignore index de729c50b..f1f3455b1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /docs/build/ Manifest.toml .DS_Store + +FLINT-3.2.0-rc1/ diff --git a/Project.toml b/Project.toml index 219156912..8011142cf 100644 --- a/Project.toml +++ b/Project.toml @@ -14,7 +14,7 @@ TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76" [compat] AbstractAlgebra = "0.44.2" -FLINT_jll = "~300.100.300" +FLINT_jll = "~300.100.301" # should be "~300.200.0" Libdl = "1.6" LinearAlgebra = "1.6" Random = "1.6" diff --git a/etc/FlintCTypes_template.jl b/etc/FlintCTypes_template.jl index 76c9e8e53..61bbfe79c 100644 --- a/etc/FlintCTypes_template.jl +++ b/etc/FlintCTypes_template.jl @@ -15,26 +15,18 @@ const unsigned_int = Cuint const char = Cchar const unsigned_char = Cuchar const double = Cdouble +const ulong = UInt +const slong = Int -# -# from gmp.h -# - -const mp_limb_t = Base.GMP.Limb -const mp_limb_signed_t = signed(Base.GMP.Limb) -const mp_bitcnt_t = Base.GMP.MPZ.bitcnt_t - -const mp_ptr = Ptr{mp_limb_t} -const mp_srcptr = Ptr{mp_limb_t} # # from flint.h # -const ulong = mp_limb_t -const slong = mp_limb_signed_t const flint_bitcnt_t = ulong -const FLINT_BITS = Base.GMP.BITS_PER_LIMB +const nn_ptr = Ptr{ulong} +const nn_srcptr = Ptr{ulong} +const FLINT_BITS = UInt == UInt64 ? 64 : 32 struct nmod_t n::mp_limb_t diff --git a/src/Nemo.jl b/src/Nemo.jl index 4b3fef149..611b6ae25 100644 --- a/src/Nemo.jl +++ b/src/Nemo.jl @@ -1,3 +1,5 @@ +# Note to self: Remember to remove the Overrides.toml once FLINT 3.2.0 is released. + @doc raw""" Nemo is a computer algebra package for the Julia programming language, maintained by William Hart, Tommy Hofmann, Claus Fieker and Fredrik Johansson with additional code by Oleksandr Motsak and other contributors. diff --git a/src/flint/FlintCTypes.jl b/src/flint/FlintCTypes.jl index dc1ddc0b3..448847de9 100644 --- a/src/flint/FlintCTypes.jl +++ b/src/flint/FlintCTypes.jl @@ -20,26 +20,18 @@ const unsigned_int = Cuint const char = Cchar const unsigned_char = Cuchar const double = Cdouble +const ulong = UInt +const slong = Int -# -# from gmp.h -# - -const mp_limb_t = Base.GMP.Limb -const mp_limb_signed_t = signed(Base.GMP.Limb) -const mp_bitcnt_t = Base.GMP.MPZ.bitcnt_t - -const mp_ptr = Ptr{mp_limb_t} -const mp_srcptr = Ptr{mp_limb_t} # # from flint.h # -const ulong = mp_limb_t -const slong = mp_limb_signed_t const flint_bitcnt_t = ulong -const FLINT_BITS = Base.GMP.BITS_PER_LIMB +const nn_ptr = Ptr{ulong} +const nn_srcptr = Ptr{ulong} +const FLINT_BITS = UInt == UInt64 ? 64 : 32 struct nmod_t n::mp_limb_t @@ -91,17 +83,17 @@ const n_primes_t = Ptr{n_primes_struct} # begin nmod_types.h struct nmod_mat_struct - entries::Ptr{mp_limb_t} + entries::Ptr{ulong} r::slong c::slong - rows::Ptr{Ptr{mp_limb_t}} + rows::Ptr{Ptr{ulong}} mod::nmod_t end const nmod_mat_t = Ptr{nmod_mat_struct} struct nmod_poly_struct - coeffs::mp_ptr + coeffs::nn_ptr alloc::slong length::slong mod::nmod_t @@ -123,24 +115,24 @@ struct nmod_poly_mat_struct r::slong c::slong rows::Ptr{Ptr{nmod_poly_struct}} - modulus::mp_limb_t + modulus::ulong end const nmod_poly_mat_t = Ptr{nmod_poly_mat_struct} struct nmod_mpoly_struct - coeffs::Ptr{mp_limb_t} + coeffs::Ptr{ulong} exps::Ptr{ulong} length::slong bits::flint_bitcnt_t #= number of bits per exponent =# - coeffs_alloc::slong #= abs size in mp_limb_t units =# + coeffs_alloc::slong #= abs size in ulong units =# exps_alloc::slong #= abs size in ulong units =# end const nmod_mpoly_t = Ptr{nmod_mpoly_struct} struct nmod_mpoly_factor_struct - constant::mp_limb_t + constant::ulong poly::Ptr{nmod_mpoly_struct} exp::Ptr{fmpz} num::slong @@ -156,6 +148,16 @@ const nmod_mpoly_factor_t = Ptr{nmod_mpoly_factor_struct} ############################################################################### # begin fmpz_types.h +struct zz_struct + alloc::int + size::int + ptr::nn_ptr +end + +typedef zz_struct * zz_ptr; +typedef const zz_struct * zz_srcptr; +#define FMPZ_TO_ZZ(x) ((zz_ptr) ((ulong) (x) << 2)) + struct fmpz_factor_struct sign::int p::Ptr{fmpz} @@ -167,7 +169,7 @@ end const fmpz_factor_t = Ptr{fmpz_factor_struct} struct fmpz_preinvn_struct - dinv::mp_ptr + dinv::nn_ptr n::slong norm::flint_bitcnt_t end @@ -349,7 +351,7 @@ struct fmpz_mod_mpoly_struct exps::Ptr{ulong} length::slong bits::flint_bitcnt_t #= number of bits per exponent =# - coeffs_alloc::slong #= abs size in mp_limb_t units =# + coeffs_alloc::slong #= abs size in ulong units =# exps_alloc::slong #= abs size in ulong units =# end @@ -381,7 +383,7 @@ struct fq_nmod_ctx_struct sparse_modulus::int is_conway::int #= whether field was generated using Flint Conway table (assures primitivity =# - a::Ptr{mp_limb_t} + a::Ptr{ulong} j::Ptr{slong} len::slong @@ -420,11 +422,11 @@ end const fq_nmod_poly_factor_t = Ptr{fq_nmod_poly_factor_struct} struct fq_nmod_mpoly_struct - coeffs::Ptr{mp_limb_t} + coeffs::Ptr{ulong} exps::Ptr{ulong} length::slong bits::flint_bitcnt_t #= number of bits per exponent =# - coeffs_alloc::slong #= abs size in mp_limb_t units =# + coeffs_alloc::slong #= abs size in ulong units =# exps_alloc::slong #= abs size in ulong units =# end @@ -438,7 +440,7 @@ const fq_nmod_mpoly_t = Ptr{fq_nmod_mpoly_struct} # begin fq_zech_types.h struct fq_zech_struct - value::mp_limb_t + value::ulong end const fq_zech_t = Ptr{fq_zech_struct} @@ -607,7 +609,7 @@ const padic_poly_t = Ptr{padic_poly_struct} #= arrays of ulong =# struct n_poly_struct - coeffs::Ptr{mp_limb_t} + coeffs::Ptr{ulong} alloc::slong length::slong end @@ -641,7 +643,7 @@ const n_fq_tpoly_t = n_tpoly_t #= sparse arrays of ulong =# struct n_polyu_struct exps::Ptr{ulong} - coeffs::Ptr{mp_limb_t} + coeffs::Ptr{ulong} length::slong alloc::slong end @@ -693,14 +695,14 @@ end const n_poly_bpoly_stack_t = Ptr{n_poly_bpoly_stack_struct} struct nmod_eval_interp_struct - M::Ptr{mp_limb_t} - T::Ptr{mp_limb_t} - Q::Ptr{mp_limb_t} - array::Ptr{mp_limb_t} + M::Ptr{ulong} + T::Ptr{ulong} + Q::Ptr{ulong} + array::Ptr{ulong} alloc::slong d::slong radix::slong - w::mp_limb_t + w::ulong end const nmod_eval_interp_t = Ptr{nmod_eval_interp_struct} From 3fa24e7786b8d68095d53a6feec6312866e28232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Thu, 30 Jan 2025 16:50:14 +0100 Subject: [PATCH 05/17] Improve conversion; also include `flint.h` --- etc/FlintCTypes_template.jl | 21 +------ etc/generate_FLINT_structs.jl | 55 +++++++++++-------- src/flint/FlintCTypes.jl | 100 +++++++++++++++++++++------------- 3 files changed, 96 insertions(+), 80 deletions(-) diff --git a/etc/FlintCTypes_template.jl b/etc/FlintCTypes_template.jl index 61bbfe79c..8743ccb37 100644 --- a/etc/FlintCTypes_template.jl +++ b/etc/FlintCTypes_template.jl @@ -20,30 +20,13 @@ const slong = Int # -# from flint.h +# from `./configure` # -const flint_bitcnt_t = ulong -const nn_ptr = Ptr{ulong} -const nn_srcptr = Ptr{ulong} const FLINT_BITS = UInt == UInt64 ? 64 : 32 -struct nmod_t - n::mp_limb_t - ninv::mp_limb_t - norm::flint_bitcnt_t -end - -const fmpz = slong -const fmpz_t = Ptr{fmpz} - -struct fmpq - num::fmpz - den::fmpz -end - -const fmpq_t = Ptr{fmpq} +@include_c_header("flint.h") @include_c_header("limb_types.h") diff --git a/etc/generate_FLINT_structs.jl b/etc/generate_FLINT_structs.jl index 66b7441ec..dc37c42c9 100644 --- a/etc/generate_FLINT_structs.jl +++ b/etc/generate_FLINT_structs.jl @@ -35,22 +35,21 @@ function expand_templates(input, flintdir) return replace(input, substitutions...) end -const regex_typedef_struct_fields_name = r"typedef struct\s*\{([^{}]+)\}\s*([a-z_]+);" -const regex_typedef_struct_fields_ptrname = r"typedef struct\s*\{([^{}]+)\}\s*([a-z_]+)\[1\];" -const regex_struct_structname_fields = r"struct *([a-z_]+)\s*\{([^{}]+)\}\s*;" -const regex_typedef_struct_structname_fields_name = r"typedef struct *([a-z_]+)\s*\{([^{}]+)\}\s*([a-z_]+);" +const regex_typedef_struct_fields_name = r"^typedef struct\s*\{([^{}]+)\}\s*([a-z_]+);"m +const regex_typedef_struct_fields_ptrname = r"^typedef struct\s*\{([^{}]+)\}\s*([a-z_]+)\[1\];"m +const regex_struct_structname_fields = r"^struct *([a-z_]+)\s*\{([^{}]+)\}\s*;"m +const regex_typedef_struct_structname_fields_name = r"^typedef struct *([a-z_]+)\s*\{([^{}]+)\}\s*([a-z_]+);"m -const regex_typedef_enum_values_name = r"typedef enum\s*\{([^{}]+)\}\s*([a-z_]+);" -const regex_enum_enumname_values = r"enum *([a-z_]+)\s*\{([^{}]+)\}\s*;" -const regex_typedef_enum_enumname_values_name = r"typedef enum *([a-z_]+)\s*\{([^{}]+)\}\s*([a-z_]+);" +const regex_typedef_enum_values_name = r"^typedef enum\s*\{([^{}]+)\}\s*([a-z_]+);"m +const regex_enum_enumname_values = r"^enum *([a-z_]+)\s*\{([^{}]+)\}\s*;"m +const regex_typedef_enum_enumname_values_name = r"^typedef enum *([a-z_]+)\s*\{([^{}]+)\}\s*([a-z_]+);"m function convert_struct(str) - substitutions = Pair{Regex,Union{SubstitutionString, Function}}[ + substitutions = Pair{Regex,Union{SubstitutionString,Function}}[ regex_typedef_struct_fields_name => s"struct \2\1end", # whole typedef struct construct regex_struct_structname_fields => s"struct struct_\1\2end", # whole struct construct regex_typedef_struct_fields_ptrname => s"struct struct_\2\1end\nconst \2 = Ptr{struct_\2}", # whole typedef struct construct with [1] regex_typedef_struct_structname_fields_name => s"struct \3\2end\nconst struct_\1 = \3", # whole typedef struct construct with two names - r"^( +)const "m => s"\1", # remove `const` from fields r"^ +([a-z_]+) +([A-Za-z0-9_]+);"m => s" \2::\1", # simple fields (one to five declared on one line) r"^ +([a-z_]+) +([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+);"m => s" \2::\1\n \3::\1", r"^ +([a-z_]+) +([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+);"m => s" \2::\1\n \3::\1\n \4::\1", @@ -74,7 +73,7 @@ function convert_struct(str) end function convert_enum(str) - substitutions = Pair{Regex,Union{SubstitutionString, Function}}[ + substitutions = Pair{Regex,Union{SubstitutionString,Function}}[ regex_typedef_enum_values_name => s"@enum \2 begin\1end", # whole typedef enum construct regex_enum_enumname_values => s"@enum enum_\1 begin\2end", # whole enum construct regex_typedef_enum_enumname_values_name => s"@enum \3 begin\2end\nconst enum_\1 = \3", # whole typedef enum construct with two names @@ -87,9 +86,17 @@ function convert_enum(str) end function c2julia(str::String) - substitutions = Pair{Regex,Union{SubstitutionString, Function}}[ + preprocessing = Pair{Regex,Union{SubstitutionString,Function}}[ r"unsigned int" => s"unsigned_int", # convert `unsigned int` to a single token r"unsigned char" => s"unsigned_char", # convert `unsigned char` to a single token + r" const " => s" ", # remove all `const` + r"^//(.*)$"m => s"#\1", # line comment + r"/\*(.*?)\*/"s => s"#=\1=#", # block comment + ] + for substitution in preprocessing + str = replace(str, substitution) + end + substitutions = Pair{Regex,Union{SubstitutionString,Function}}[ regex_typedef_struct_fields_name => convert_struct, # whole typedef struct construct regex_typedef_struct_fields_ptrname => convert_struct, # whole typedef struct construct with [1] regex_struct_structname_fields => convert_struct, # whole struct construct @@ -97,16 +104,16 @@ function c2julia(str::String) regex_typedef_enum_values_name => convert_enum, # whole typedef enum construct regex_enum_enumname_values => convert_enum, # whole enum construct regex_typedef_enum_enumname_values_name => convert_enum, # whole typedef enum construct with two names - r"^typedef ([A-Za-z_]+) ([A-Za-z_]+);"m => s"const \2 = \1", # simple typedef - r"^typedef ([A-Za-z_]+) ([A-Za-z_]+)\[1\];"m => s"const \2 = Ptr{\1}", # pointer typedef - r"^#define ([A-Za-z_]+) ([A-Za-z0-9_]+)"m => s"const \1 = \2", # defines used as typedef - r"^//(.*)$"m => s"#\1", # line comment - r"/\*(.*?)\*/"s => s"#=\1=#", # block comment + r"^typedef +([A-Za-z_]+) +([A-Za-z_]+);"m => s"const \2 = \1", # simple typedef + r"^typedef +([A-Za-z_]+) *\* *([A-Za-z_]+);"m => s"const \2 = Ptr{\1}", # pointer typedef + r"^typedef +([A-Za-z_]+) +([A-Za-z_]+)\[1\];"m => s"const \2 = Ptr{\1}", # pointer typedef + r"^#define +([A-Za-z_]+) +(\d+) *$"m => s"const \1 = \2", # defines of integer constants ] - for substitution in substitutions - str = replace(str, substitution) - end - return str + combined_regex = Regex(join(map(re -> re.pattern, first.(substitutions)), "|"), "m") + output = join( + map(m -> replace(m.match, substitutions...), eachmatch(combined_regex, str)), "\n\n" + ) + return output end file_header_notice(FLINT_jll_version) = """ @@ -123,11 +130,15 @@ file_header_notice(FLINT_jll_version) = """ # ################################################################################ -function expand_template_file(infile::String, outfile::String, flintpath::String, file_header::String) +function expand_template_file( + infile::String, outfile::String, flintpath::String, file_header::String +) @info "Expanding file" infile outfile open(outfile, "w") do io write(io, file_header) - write(io, expand_templates(read(infile, String), joinpath(flintpath, "include", "flint"))) + write( + io, expand_templates(read(infile, String), joinpath(flintpath, "include", "flint")) + ) end end diff --git a/src/flint/FlintCTypes.jl b/src/flint/FlintCTypes.jl index 448847de9..94f6407b2 100644 --- a/src/flint/FlintCTypes.jl +++ b/src/flint/FlintCTypes.jl @@ -25,21 +25,56 @@ const slong = Int # -# from flint.h +# from `./configure` # +const FLINT_BITS = UInt == UInt64 ? 64 : 32 + + +############################################################################### +# begin flint.h + +const __FLINT_VERSION = 3 + +const __FLINT_VERSION_MINOR = 2 + +const __FLINT_VERSION_PATCHLEVEL = 0 + const flint_bitcnt_t = ulong + const nn_ptr = Ptr{ulong} + const nn_srcptr = Ptr{ulong} -const FLINT_BITS = UInt == UInt64 ? 64 : 32 + +const thread_pool_handle = int + +struct flint_rand_struct + __gmp_state::Ptr{void} + __randval::ulong + __randval2::ulong +end + +const flint_rand_t = Ptr{flint_rand_struct} + +@enum flint_err_t begin + FLINT_ERROR #= general error =# + FLINT_OVERFLOW #= overflow =# + FLINT_IMPINV #= impossible inverse =# + FLINT_DOMERR #= domain error =# + FLINT_DIVZERO #= divide by zero =# + FLINT_EXPOF #= exponent overflow =# + FLINT_INEXACT #= inexact error =# + FLINT_TEST_FAIL #= test fail =# +end struct nmod_t - n::mp_limb_t - ninv::mp_limb_t + n::ulong + ninv::ulong norm::flint_bitcnt_t end const fmpz = slong + const fmpz_t = Ptr{fmpz} struct fmpq @@ -49,6 +84,11 @@ end const fmpq_t = Ptr{fmpq} +const MPZ_MIN_ALLOC = 2 + +# end flint.h +############################################################################### + ############################################################################### # begin limb_types.h @@ -154,9 +194,9 @@ struct zz_struct ptr::nn_ptr end -typedef zz_struct * zz_ptr; -typedef const zz_struct * zz_srcptr; -#define FMPZ_TO_ZZ(x) ((zz_ptr) ((ulong) (x) << 2)) +const zz_ptr = Ptr{zz_struct} + +const zz_srcptr = Ptr{zz_struct} struct fmpz_factor_struct sign::int @@ -279,14 +319,6 @@ end const fmpq_poly_t = Ptr{fmpq_poly_struct} -#= - A polynomial f is represented as - content * zpoly, - where zpoly should have positive leading coefficient and trivial content. - If f is zero, then the representation should have - content = 0 and zpoly = 0 -=# - struct fmpq_mpoly_struct #= non zero case: | zero case: =# content::fmpq_t #= positive or negative content | zero =# zpoly::fmpz_mpoly_t #= contentless poly, lc is positive | zero =# @@ -375,6 +407,7 @@ const fmpz_mod_mpoly_factor_t = Ptr{fmpz_mod_mpoly_factor_struct} # begin fq_nmod_types.h const fq_nmod_t = nmod_poly_t + const fq_nmod_struct = nmod_poly_struct struct fq_nmod_ctx_struct @@ -497,6 +530,7 @@ const fq_zech_poly_factor_t = Ptr{fq_zech_poly_factor_struct} # begin fq_types.h const fq_t = fmpz_poly_t + const fq_struct = fmpz_poly_struct struct fq_ctx_struct @@ -607,7 +641,6 @@ const padic_poly_t = Ptr{padic_poly_struct} ############################################################################### # begin n_poly_types.h -#= arrays of ulong =# struct n_poly_struct coeffs::Ptr{ulong} alloc::slong @@ -615,10 +648,11 @@ struct n_poly_struct end const n_poly_t = Ptr{n_poly_struct} + const n_fq_poly_struct = n_poly_struct + const n_fq_poly_t = n_poly_t -#= arrays of arrays of ulong =# struct n_bpoly_struct coeffs::Ptr{n_poly_struct} alloc::slong @@ -626,10 +660,11 @@ struct n_bpoly_struct end const n_bpoly_t = Ptr{n_bpoly_struct} + const n_fq_bpoly_struct = n_bpoly_struct + const n_fq_bpoly_t = n_bpoly_t -#= arrays of arrays of arrays of ulong =# struct n_tpoly_struct coeffs::Ptr{n_bpoly_struct} alloc::slong @@ -637,10 +672,11 @@ struct n_tpoly_struct end const n_tpoly_t = Ptr{n_tpoly_struct} + const n_fq_tpoly_struct = n_tpoly_struct + const n_fq_tpoly_t = n_tpoly_t -#= sparse arrays of ulong =# struct n_polyu_struct exps::Ptr{ulong} coeffs::Ptr{ulong} @@ -649,15 +685,11 @@ struct n_polyu_struct end const n_polyu_t = Ptr{n_polyu_struct} + const n_fq_polyu_struct = n_polyu_struct + const n_fq_polyu_t = n_polyu_t -#= - sparse arrays of arrays of ulong - n_polyu1n => one exponent is in the exps[i] - n_polyu2n => two exponents are packed into the exps[i] - ... -=# struct n_polyun_struct coeffs::Ptr{n_poly_struct} exps::Ptr{ulong} @@ -666,10 +698,11 @@ struct n_polyun_struct end const n_polyun_t = Ptr{n_polyun_struct} + const n_fq_polyun_struct = n_polyun_struct + const n_fq_polyun_t = n_polyun_t -#= n_poly stack =# struct n_poly_stack_struct array::Ptr{Ptr{n_poly_struct}} alloc::slong @@ -678,7 +711,6 @@ end const n_poly_stack_t = Ptr{n_poly_stack_struct} -#= n_bpoly stack =# struct n_bpoly_stack_struct array::Ptr{Ptr{n_bpoly_struct}} alloc::slong @@ -714,8 +746,6 @@ const nmod_eval_interp_t = Ptr{nmod_eval_interp_struct} ############################################################################### # begin mpoly_types.h -#define MPOLY_MIN_BITS (UWORD(8)) #= minimum number of bits to pack into =# - @enum ordering_t begin ORD_LEX ORD_DEGLEX @@ -769,7 +799,6 @@ end const fq_nmod_mpoly_ctx_t = Ptr{fq_nmod_mpoly_ctx_struct} - struct struct_mpoly_void_ring_t elem_size::slong ctx::Ptr{void} @@ -859,10 +888,6 @@ end const mpoly_compression_t = Ptr{mpoly_compression_struct} -#= - nmod_mpolyn_t - multivariates with n_poly_t coefficients -=# struct nmod_mpolyn_struct coeffs::Ptr{n_poly_struct} exps::Ptr{ulong} @@ -870,13 +895,9 @@ struct nmod_mpolyn_struct length::slong bits::slong end + const nmod_mpolyn_t = Ptr{nmod_mpolyn_struct} -#= - nmod_mpolyun_t - sparse univariates with nmod_mpolyn_t coefficients - with uniform bits and LEX ordering -=# struct nmod_mpolyun_struct coeffs::Ptr{nmod_mpolyn_struct} exps::Ptr{ulong} @@ -884,6 +905,7 @@ struct nmod_mpolyun_struct length::slong bits::flint_bitcnt_t #= default bits to construct coeffs =# end + const nmod_mpolyun_t = Ptr{nmod_mpolyun_struct} @enum nmod_gcds_ret_t begin From 800bab24fdf1b2bff147ac401a94a5fd2b37ca4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Thu, 30 Jan 2025 17:22:17 +0100 Subject: [PATCH 06/17] Add union handling; include `fq_default.h` --- etc/FlintCTypes_template.jl | 4 ++ etc/generate_FLINT_structs.jl | 74 +++++++++++++++-------- src/flint/FlintCTypes.jl | 110 ++++++++++++++++++++++++++++++++++ 3 files changed, 164 insertions(+), 24 deletions(-) diff --git a/etc/FlintCTypes_template.jl b/etc/FlintCTypes_template.jl index 8743ccb37..474b16607 100644 --- a/etc/FlintCTypes_template.jl +++ b/etc/FlintCTypes_template.jl @@ -44,6 +44,10 @@ const FLINT_BITS = UInt == UInt64 ? 64 : 32 @include_c_header("fq_types.h") +@include_c_header("gr_types.h") + +@include_c_header("fq_default.h") + @include_c_header("padic_types.h") @include_c_header("n_poly_types.h") diff --git a/etc/generate_FLINT_structs.jl b/etc/generate_FLINT_structs.jl index dc37c42c9..ed11f899a 100644 --- a/etc/generate_FLINT_structs.jl +++ b/etc/generate_FLINT_structs.jl @@ -35,36 +35,42 @@ function expand_templates(input, flintdir) return replace(input, substitutions...) end -const regex_typedef_struct_fields_name = r"^typedef struct\s*\{([^{}]+)\}\s*([a-z_]+);"m -const regex_typedef_struct_fields_ptrname = r"^typedef struct\s*\{([^{}]+)\}\s*([a-z_]+)\[1\];"m -const regex_struct_structname_fields = r"^struct *([a-z_]+)\s*\{([^{}]+)\}\s*;"m -const regex_typedef_struct_structname_fields_name = r"^typedef struct *([a-z_]+)\s*\{([^{}]+)\}\s*([a-z_]+);"m +const regex_typedef_struct_fields_name = r"^typedef struct\s*\{([^{}]+)\}\s*([A-Za-z0-9_]+);"m +const regex_typedef_struct_fields_ptrname = r"^typedef struct\s*\{([^{}]+)\}\s*([A-Za-z0-9_]+)\[1\];"m +const regex_struct_structname_fields = r"^struct *([A-Za-z0-9_]+)\s*\{([^{}]+)\}\s*;"m +const regex_struct_structname = r"^struct *([A-Za-z0-9_]+);"m +const regex_typedef_struct_structname_fields_name = r"^typedef struct *([A-Za-z0-9_]+)\s*\{([^{}]+)\}\s*([A-Za-z0-9_]+);"m -const regex_typedef_enum_values_name = r"^typedef enum\s*\{([^{}]+)\}\s*([a-z_]+);"m -const regex_enum_enumname_values = r"^enum *([a-z_]+)\s*\{([^{}]+)\}\s*;"m -const regex_typedef_enum_enumname_values_name = r"^typedef enum *([a-z_]+)\s*\{([^{}]+)\}\s*([a-z_]+);"m +const regex_typedef_enum_values_name = r"^typedef enum\s*\{([^{}]+)\}\s*([A-Za-z0-9_]+);"m +const regex_enum_enumname_values = r"^enum *([A-Za-z0-9_]+)\s*\{([^{}]+)\}\s*;"m +const regex_typedef_enum_enumname_values_name = r"^typedef enum *([A-Za-z0-9_]+)\s*\{([^{}]+)\}\s*([A-Za-z0-9_]+);"m -function convert_struct(str) +const regex_typedef_union_values_name = r"^typedef union\s*\{([^{}]+)\}\s*([A-Za-z0-9_]+);"m +const regex_union_unionname_values = r"^union *([A-Za-z0-9_]+)\s*\{([^{}]+)\}\s*;"m +const regex_typedef_union_unionname_values_name = r"^typedef union *([A-Za-z0-9_]+)\s*\{([^{}]+)\}\s*([A-Za-z0-9_]+);"m + +function convert_struct(str::AbstractString) substitutions = Pair{Regex,Union{SubstitutionString,Function}}[ regex_typedef_struct_fields_name => s"struct \2\1end", # whole typedef struct construct regex_struct_structname_fields => s"struct struct_\1\2end", # whole struct construct + regex_struct_structname => s"struct struct_\1 end", # whole struct construct without fields regex_typedef_struct_fields_ptrname => s"struct struct_\2\1end\nconst \2 = Ptr{struct_\2}", # whole typedef struct construct with [1] regex_typedef_struct_structname_fields_name => s"struct \3\2end\nconst struct_\1 = \3", # whole typedef struct construct with two names - r"^ +([a-z_]+) +([A-Za-z0-9_]+);"m => s" \2::\1", # simple fields (one to five declared on one line) - r"^ +([a-z_]+) +([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+);"m => s" \2::\1\n \3::\1", - r"^ +([a-z_]+) +([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+);"m => s" \2::\1\n \3::\1\n \4::\1", - r"^ +([a-z_]+) +([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+);"m => s" \2::\1\n \3::\1\n \4::\1\n \5::\1", - r"^ +([a-z_]+) +([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+);"m => s" \2::\1\n \3::\1\n \4::\1\n \5::\1\n \6::\1", - r"^ +([a-z_]+) *\* *([A-Za-z0-9_]+);"m => s" \2::Ptr{\1}", # pointer field (one to five declared on one line) - r"^ +([a-z_]+) *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+);"m => s" \2::Ptr{\1}\n \3::Ptr{\1}", - r"^ +([a-z_]+) *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+);"m => s" \2::Ptr{\1}\n \3::Ptr{\1}\n \4::Ptr{\1}", - r"^ +([a-z_]+) *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+);"m => s" \2::Ptr{\1}\n \3::Ptr{\1}\n \4::Ptr{\1}\n \5::Ptr{\1}", - r"^ +([a-z_]+) *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+);"m => s" \2::Ptr{\1}\n \3::Ptr{\1}\n \4::Ptr{\1}\n \5::Ptr{\1}\n \6::Ptr{\1}", - r"^ +([a-z_]+) *\* *\* *([A-Za-z0-9_]+);"m => s" \2::Ptr{Ptr{\1}}", # double pointer field - r"^ +([a-z_]+) +([A-Za-z0-9_]+)\[([A-Za-z0-9_]+)\];"m => s" \2::NTuple{\3, \1}", # fixed len array field - r"^ +[a-z_]+ *\( *\* *([A-Za-z0-9_]+) *\) *\([a-z_, *]+\);"m => s" \1::Ptr{Nothing}", # function pointer field - r"^ +struct *([a-z_]+) +([A-Za-z0-9_]+);"m => s" \2::struct_\1", # struct field (without typedef) - r"^ +enum *([a-z_]+) +([A-Za-z0-9_]+);"m => s" \2::enum_\1", # enum field (without typedef) + r"^ +([A-Za-z0-9_]+) +([A-Za-z0-9_]+);"m => s" \2::\1", # simple fields (one to five declared on one line) + r"^ +([A-Za-z0-9_]+) +([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+);"m => s" \2::\1\n \3::\1", + r"^ +([A-Za-z0-9_]+) +([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+);"m => s" \2::\1\n \3::\1\n \4::\1", + r"^ +([A-Za-z0-9_]+) +([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+);"m => s" \2::\1\n \3::\1\n \4::\1\n \5::\1", + r"^ +([A-Za-z0-9_]+) +([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+);"m => s" \2::\1\n \3::\1\n \4::\1\n \5::\1\n \6::\1", + r"^ +([A-Za-z0-9_]+) *\* *([A-Za-z0-9_]+);"m => s" \2::Ptr{\1}", # pointer field (one to five declared on one line) + r"^ +([A-Za-z0-9_]+) *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+);"m => s" \2::Ptr{\1}\n \3::Ptr{\1}", + r"^ +([A-Za-z0-9_]+) *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+);"m => s" \2::Ptr{\1}\n \3::Ptr{\1}\n \4::Ptr{\1}", + r"^ +([A-Za-z0-9_]+) *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+);"m => s" \2::Ptr{\1}\n \3::Ptr{\1}\n \4::Ptr{\1}\n \5::Ptr{\1}", + r"^ +([A-Za-z0-9_]+) *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+);"m => s" \2::Ptr{\1}\n \3::Ptr{\1}\n \4::Ptr{\1}\n \5::Ptr{\1}\n \6::Ptr{\1}", + r"^ +([A-Za-z0-9_]+) *\* *\* *([A-Za-z0-9_]+);"m => s" \2::Ptr{Ptr{\1}}", # double pointer field + r"^ +([A-Za-z0-9_]+) +([A-Za-z0-9_]+)\[([A-Za-z0-9_]+)\];"m => s" \2::NTuple{\3, \1}", # fixed len array field + r"^ +[A-Za-z0-9_]+ *\( *\* *([A-Za-z0-9_]+) *\) *\([a-z_, *]+\);"m => s" \1::Ptr{Nothing}", # function pointer field + r"^ +struct *([A-Za-z0-9_]+) +([A-Za-z0-9_]+);"m => s" \2::struct_\1", # struct field (without typedef) + r"^ +enum *([A-Za-z0-9_]+) +([A-Za-z0-9_]+);"m => s" \2::enum_\1", # enum field (without typedef) ] for substitution in substitutions str = replace(str, substitution) @@ -72,7 +78,7 @@ function convert_struct(str) return str end -function convert_enum(str) +function convert_enum(str::AbstractString) substitutions = Pair{Regex,Union{SubstitutionString,Function}}[ regex_typedef_enum_values_name => s"@enum \2 begin\1end", # whole typedef enum construct regex_enum_enumname_values => s"@enum enum_\1 begin\2end", # whole enum construct @@ -85,6 +91,19 @@ function convert_enum(str) return str end +function convert_union(str::AbstractString) + substitutions = Pair{Regex,Union{SubstitutionString,Function}}[ + regex_typedef_union_values_name => s"struct \2\n uniondata::NTuple{maximum(sizeof, (\1 )), UInt8}\nend", # whole typedef union construct + regex_union_unionname_values => s"struct union_\1\n uniondata::NTuple{maximum(sizeof, (\2 )), UInt8}\nend", # whole union construct + regex_typedef_union_unionname_values_name => s"struct \3\n uniondata::NTuple{maximum(sizeof, (\2 )), UInt8}\nend\nconst union_\1 = \3", # whole typedef union construct with two names + r"^ +([a-z_]+) +([A-Za-z0-9_]+);"m => s" \1,", + ] + for substitution in substitutions + str = replace(str, substitution) + end + return str +end + function c2julia(str::String) preprocessing = Pair{Regex,Union{SubstitutionString,Function}}[ r"unsigned int" => s"unsigned_int", # convert `unsigned int` to a single token @@ -100,13 +119,20 @@ function c2julia(str::String) regex_typedef_struct_fields_name => convert_struct, # whole typedef struct construct regex_typedef_struct_fields_ptrname => convert_struct, # whole typedef struct construct with [1] regex_struct_structname_fields => convert_struct, # whole struct construct + regex_struct_structname => convert_struct, # whole struct construct without fields regex_typedef_struct_structname_fields_name => convert_struct, # whole typedef struct construct with two names regex_typedef_enum_values_name => convert_enum, # whole typedef enum construct regex_enum_enumname_values => convert_enum, # whole enum construct regex_typedef_enum_enumname_values_name => convert_enum, # whole typedef enum construct with two names + regex_typedef_union_values_name => convert_union, # whole typedef union construct + regex_union_unionname_values => convert_union, # whole union construct + regex_typedef_union_unionname_values_name => convert_union, # whole typedef union construct with two names r"^typedef +([A-Za-z_]+) +([A-Za-z_]+);"m => s"const \2 = \1", # simple typedef r"^typedef +([A-Za-z_]+) *\* *([A-Za-z_]+);"m => s"const \2 = Ptr{\1}", # pointer typedef r"^typedef +([A-Za-z_]+) +([A-Za-z_]+)\[1\];"m => s"const \2 = Ptr{\1}", # pointer typedef + r"^typedef +struct +([A-Za-z_]+) +([A-Za-z_]+);"m => s"const \2 = struct_\1", # struct typedef + r"^typedef +enum +([A-Za-z_]+) +([A-Za-z_]+);"m => s"const \2 = enum_\1", # enum typedef + r"^typedef +union +([A-Za-z_]+) +([A-Za-z_]+);"m => s"const \2 = union_\1", # union typedef r"^#define +([A-Za-z_]+) +(\d+) *$"m => s"const \1 = \2", # defines of integer constants ] combined_regex = Regex(join(map(re -> re.pattern, first.(substitutions)), "|"), "m") diff --git a/src/flint/FlintCTypes.jl b/src/flint/FlintCTypes.jl index 94f6407b2..34d61e26e 100644 --- a/src/flint/FlintCTypes.jl +++ b/src/flint/FlintCTypes.jl @@ -40,6 +40,10 @@ const __FLINT_VERSION_MINOR = 2 const __FLINT_VERSION_PATCHLEVEL = 0 +struct struct___FLINT_FILE end + +const FLINT_FILE = struct___FLINT_FILE + const flint_bitcnt_t = ulong const nn_ptr = Ptr{ulong} @@ -581,6 +585,112 @@ const fq_poly_factor_t = Ptr{fq_poly_factor_struct} ############################################################################### +############################################################################### +# begin gr_types.h + +const GR_SUCCESS = 0 + +const GR_DOMAIN = 1 + +const GR_UNABLE = 2 + +const GR_TEST_FAIL = 4 + +@enum truth_t begin + T_TRUE + T_FALSE + T_UNKNOWN +end + +struct gr_stream_struct + fp::Ptr{FLINT_FILE} + s::Ptr{char} + len::slong + alloc::slong +end + +const gr_stream_t = Ptr{gr_stream_struct} + +struct gr_ctx_struct + data::NTuple{GR_CTX_STRUCT_DATA_BYTES, char} + which_ring::ulong + sizeof_elem::slong + methods::Ptr{gr_funcptr} + size_limit::ulong +end + +const gr_ctx_t = Ptr{gr_ctx_struct} + +const gr_ptr = Ptr{void} + +const gr_srcptr = Ptr{void} + +const gr_ctx_ptr = Ptr{void} + +struct gr_vec_struct + entries::gr_ptr + alloc::slong + length::slong +end + +const gr_vec_t = Ptr{gr_vec_struct} + +struct gr_mat_struct + entries::gr_ptr + r::slong + c::slong + rows::Ptr{gr_ptr} +end + +const gr_mat_t = Ptr{gr_mat_struct} + +struct gr_poly_struct + coeffs::gr_ptr + alloc::slong + length::slong +end + +const gr_poly_t = Ptr{gr_poly_struct} + +# end gr_types.h +############################################################################### + + +############################################################################### +# begin fq_default.h + +struct fq_default_struct + uniondata::NTuple{maximum(sizeof, ( + fq_t, + fq_nmod_t, + fq_zech_t, + ulong, + fmpz_t, + )), UInt8} +end +const union_fq_default_struct = fq_default_struct + +const fq_default_t = Ptr{fq_default_struct} + +const fq_default_ctx_struct = gr_ctx_struct + +const fq_default_ctx_t = Ptr{fq_default_ctx_struct} + +struct _gr_fmpz_mod_ctx_struct + ctx::Ptr{fmpz_mod_ctx_struct} + is_prime::truth_t + a::fmpz #= when used as finite field with defining polynomial x - a =# +end + +struct _gr_nmod_ctx_struct + nmod::nmod_t + a::ulong #= when used as finite field with defining polynomial x - a =# +end + +# end fq_default.h +############################################################################### + + ############################################################################### # begin padic_types.h From 3a6ce0db034b0d20c8fbe5cea8ca1720bf8b2f05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Thu, 30 Jan 2025 17:27:05 +0100 Subject: [PATCH 07/17] Improve conversion again --- etc/generate_FLINT_structs.jl | 2 ++ src/flint/FlintCTypes.jl | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/etc/generate_FLINT_structs.jl b/etc/generate_FLINT_structs.jl index ed11f899a..c7dc948c6 100644 --- a/etc/generate_FLINT_structs.jl +++ b/etc/generate_FLINT_structs.jl @@ -133,7 +133,9 @@ function c2julia(str::String) r"^typedef +struct +([A-Za-z_]+) +([A-Za-z_]+);"m => s"const \2 = struct_\1", # struct typedef r"^typedef +enum +([A-Za-z_]+) +([A-Za-z_]+);"m => s"const \2 = enum_\1", # enum typedef r"^typedef +union +([A-Za-z_]+) +([A-Za-z_]+);"m => s"const \2 = union_\1", # union typedef + r"^typedef +[A-Za-z0-9_]+ *\( *\* *([A-Za-z0-9_]+) *\) *\([a-z_, *]+\);"m => s"const \1 = Ptr{Nothing}", # function pointer typedef r"^#define +([A-Za-z_]+) +(\d+) *$"m => s"const \1 = \2", # defines of integer constants + r"^#define +([A-Za-z_]+) +\(([A-Za-z0-9+*() ]+)\) *$"m => s"const \1 = \2", # defines of more complex constants ] combined_regex = Regex(join(map(re -> re.pattern, first.(substitutions)), "|"), "m") output = join( diff --git a/src/flint/FlintCTypes.jl b/src/flint/FlintCTypes.jl index 34d61e26e..55c13a01c 100644 --- a/src/flint/FlintCTypes.jl +++ b/src/flint/FlintCTypes.jl @@ -50,6 +50,8 @@ const nn_ptr = Ptr{ulong} const nn_srcptr = Ptr{ulong} +const flint_cleanup_function_t = Ptr{Nothing} + const thread_pool_handle = int struct flint_rand_struct @@ -611,6 +613,10 @@ end const gr_stream_t = Ptr{gr_stream_struct} +const gr_funcptr = Ptr{Nothing} + +const GR_CTX_STRUCT_DATA_BYTES = 6 * sizeof(ulong) + struct gr_ctx_struct data::NTuple{GR_CTX_STRUCT_DATA_BYTES, char} which_ring::ulong From 1b884598527a5458dd3fb4e4912341e4a9ccc87e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Thu, 30 Jan 2025 17:31:39 +0100 Subject: [PATCH 08/17] Simplify file parsing a bit --- etc/generate_FLINT_structs.jl | 11 +---------- src/flint/FlintCTypes.jl | 10 ++++++++++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/etc/generate_FLINT_structs.jl b/etc/generate_FLINT_structs.jl index c7dc948c6..b79328ad1 100644 --- a/etc/generate_FLINT_structs.jl +++ b/etc/generate_FLINT_structs.jl @@ -1,8 +1,5 @@ VERSION >= v"1.9" || error("This script requires Julia 1.7 or later") -const headerfile_begin_regex = r"#ifdef __cplusplus\s*extern \"C\"\s*\{\s*#endif" -const headerfile_end_regex = r"#ifdef __cplusplus\s*\}\s*#endif" - function expand_templates(input, flintdir) matches = eachmatch(r"^@include_c_header\(\"([A-Za-z_.]+)\"\)$"m, input) substitutions = Pair{String,String}[] @@ -15,14 +12,8 @@ function expand_templates(input, flintdir) content = open(joinpath(flintdir, filename)) do headerfile read(headerfile, String) end - # Restrict to the relevant part (ignore include guards etc.) - begin_match = match(headerfile_begin_regex, content) - @assert !isnothing(begin_match) - end_match = match(headerfile_end_regex, content) - @assert !isnothing(end_match) - relevant_content = content[(begin_match.offset + length(begin_match.match)):(end_match.offset - 1)] # Convert to julia - translated_content = c2julia(relevant_content) + translated_content = c2julia(content) # Build the substitution value template_val = "###############################################################################\n" * diff --git a/src/flint/FlintCTypes.jl b/src/flint/FlintCTypes.jl index 55c13a01c..f82a9d9b1 100644 --- a/src/flint/FlintCTypes.jl +++ b/src/flint/FlintCTypes.jl @@ -665,6 +665,16 @@ const gr_poly_t = Ptr{gr_poly_struct} ############################################################################### # begin fq_default.h +const FQ_DEFAULT_FQ_ZECH = 1 + +const FQ_DEFAULT_FQ_NMOD = 2 + +const FQ_DEFAULT_FQ = 3 + +const FQ_DEFAULT_NMOD = 4 + +const FQ_DEFAULT_FMPZ_MOD = 5 + struct fq_default_struct uniondata::NTuple{maximum(sizeof, ( fq_t, From 078b27faaa648cc1a11ac46813f66d0615da859e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Thu, 30 Jan 2025 17:43:19 +0100 Subject: [PATCH 09/17] Strip comments as we could extract structs from large block comments by accident --- etc/generate_FLINT_structs.jl | 4 +- src/flint/FlintCTypes.jl | 82 ++++++++++++++++++----------------- 2 files changed, 44 insertions(+), 42 deletions(-) diff --git a/etc/generate_FLINT_structs.jl b/etc/generate_FLINT_structs.jl index b79328ad1..82093aa7f 100644 --- a/etc/generate_FLINT_structs.jl +++ b/etc/generate_FLINT_structs.jl @@ -100,8 +100,8 @@ function c2julia(str::String) r"unsigned int" => s"unsigned_int", # convert `unsigned int` to a single token r"unsigned char" => s"unsigned_char", # convert `unsigned char` to a single token r" const " => s" ", # remove all `const` - r"^//(.*)$"m => s"#\1", # line comment - r"/\*(.*?)\*/"s => s"#=\1=#", # block comment + r"^//(.*)$"m => s"", # remove line comment + r"/\*(.*?)\*/"s => s"", # remove block comment ] for substitution in preprocessing str = replace(str, substitution) diff --git a/src/flint/FlintCTypes.jl b/src/flint/FlintCTypes.jl index f82a9d9b1..8085798ec 100644 --- a/src/flint/FlintCTypes.jl +++ b/src/flint/FlintCTypes.jl @@ -63,14 +63,14 @@ end const flint_rand_t = Ptr{flint_rand_struct} @enum flint_err_t begin - FLINT_ERROR #= general error =# - FLINT_OVERFLOW #= overflow =# - FLINT_IMPINV #= impossible inverse =# - FLINT_DOMERR #= domain error =# - FLINT_DIVZERO #= divide by zero =# - FLINT_EXPOF #= exponent overflow =# - FLINT_INEXACT #= inexact error =# - FLINT_TEST_FAIL #= test fail =# + FLINT_ERROR + FLINT_OVERFLOW + FLINT_IMPINV + FLINT_DOMERR + FLINT_DIVZERO + FLINT_EXPOF + FLINT_INEXACT + FLINT_TEST_FAIL end struct nmod_t @@ -170,9 +170,9 @@ struct nmod_mpoly_struct coeffs::Ptr{ulong} exps::Ptr{ulong} length::slong - bits::flint_bitcnt_t #= number of bits per exponent =# - coeffs_alloc::slong #= abs size in ulong units =# - exps_alloc::slong #= abs size in ulong units =# + bits::flint_bitcnt_t + coeffs_alloc::slong + exps_alloc::slong end const nmod_mpoly_t = Ptr{nmod_mpoly_struct} @@ -259,18 +259,18 @@ end const fmpz_poly_mat_t = Ptr{fmpz_poly_mat_struct} struct fmpz_mpoly_struct - coeffs::Ptr{fmpz} #= alloc fmpzs =# + coeffs::Ptr{fmpz} exps::Ptr{ulong} alloc::slong length::slong - bits::flint_bitcnt_t #= number of bits per exponent =# + bits::flint_bitcnt_t end const fmpz_mpoly_t = Ptr{fmpz_mpoly_struct} struct fmpz_mpoly_factor_struct constant::fmpz_t - constant_den::fmpz_t #= should be one after normal operations =# + constant_den::fmpz_t poly::Ptr{fmpz_mpoly_struct} exp::Ptr{fmpz} num::slong @@ -325,9 +325,9 @@ end const fmpq_poly_t = Ptr{fmpq_poly_struct} -struct fmpq_mpoly_struct #= non zero case: | zero case: =# - content::fmpq_t #= positive or negative content | zero =# - zpoly::fmpz_mpoly_t #= contentless poly, lc is positive | zero =# +struct fmpq_mpoly_struct + content::fmpq_t + zpoly::fmpz_mpoly_t end const fmpq_mpoly_t = Ptr{fmpq_mpoly_struct} @@ -388,9 +388,9 @@ struct fmpz_mod_mpoly_struct coeffs::Ptr{fmpz} exps::Ptr{ulong} length::slong - bits::flint_bitcnt_t #= number of bits per exponent =# - coeffs_alloc::slong #= abs size in ulong units =# - exps_alloc::slong #= abs size in ulong units =# + bits::flint_bitcnt_t + coeffs_alloc::slong + exps_alloc::slong end const fmpz_mod_mpoly_t = Ptr{fmpz_mod_mpoly_struct} @@ -420,7 +420,7 @@ struct fq_nmod_ctx_struct mod::nmod_t sparse_modulus::int - is_conway::int #= whether field was generated using Flint Conway table (assures primitivity =# + is_conway::int a::Ptr{ulong} j::Ptr{slong} @@ -464,9 +464,9 @@ struct fq_nmod_mpoly_struct coeffs::Ptr{ulong} exps::Ptr{ulong} length::slong - bits::flint_bitcnt_t #= number of bits per exponent =# - coeffs_alloc::slong #= abs size in ulong units =# - exps_alloc::slong #= abs size in ulong units =# + bits::flint_bitcnt_t + coeffs_alloc::slong + exps_alloc::slong end const fq_nmod_mpoly_t = Ptr{fq_nmod_mpoly_struct} @@ -485,19 +485,19 @@ end const fq_zech_t = Ptr{fq_zech_struct} struct fq_zech_ctx_struct - qm1::ulong #= q - 1 =# - qm1o2::ulong #= (q - 1) / 2 or 1 when p == 2 =# - qm1opm1::ulong #= (q - 1) / (p - 1) =# + qm1::ulong + qm1o2::ulong + qm1opm1::ulong p::ulong ppre::double - prime_root::ulong #= primitive root for prime subfield =# + prime_root::ulong zech_log_table::Ptr{ulong} prime_field_table::Ptr{ulong} eval_table::Ptr{ulong} fq_nmod_ctx::Ptr{fq_nmod_ctx_struct} owns_fq_nmod_ctx::int - is_conway::int #= whether field was generated using Flint Conway tables (assures primitivity) =# + is_conway::int end const fq_zech_ctx_t = Ptr{fq_zech_ctx_struct} @@ -543,7 +543,7 @@ struct fq_ctx_struct ctxp::fmpz_mod_ctx_t sparse_modulus::int - is_conway::int #= whether field was initialized with the Flint Conway tables (assures primitivity) =# + is_conway::int a::Ptr{fmpz} j::Ptr{slong} @@ -695,12 +695,12 @@ const fq_default_ctx_t = Ptr{fq_default_ctx_struct} struct _gr_fmpz_mod_ctx_struct ctx::Ptr{fmpz_mod_ctx_struct} is_prime::truth_t - a::fmpz #= when used as finite field with defining polynomial x - a =# + a::fmpz end struct _gr_nmod_ctx_struct nmod::nmod_t - a::ulong #= when used as finite field with defining polynomial x - a =# + a::ulong end # end fq_default.h @@ -872,6 +872,8 @@ const nmod_eval_interp_t = Ptr{nmod_eval_interp_struct} ############################################################################### # begin mpoly_types.h +const MPOLY_MIN_BITS = UWORD(8) + @enum ordering_t begin ORD_LEX ORD_DEGLEX @@ -881,13 +883,13 @@ end const MPOLY_NUM_ORDERINGS = 3 struct mpoly_ctx_struct - nvars::slong #= number of variables =# - nfields::slong #= number of fields in exponent vector =# - ord::ordering_t #= monomial ordering =# - deg::int #= is ord a degree ordering? =# - rev::int #= is ord a reversed ordering? =# + nvars::slong + nfields::slong + ord::ordering_t + deg::int + rev::int lut_words_per_exp::NTuple{FLINT_BITS, slong} - lut_fix_bits::NTuple{FLINT_BITS, unsigned_char} #= FLINT_BITS < 256 =# + lut_fix_bits::NTuple{FLINT_BITS, unsigned_char} end const mpoly_ctx_t = Ptr{mpoly_ctx_struct} @@ -990,7 +992,7 @@ struct mpoly_gcd_info_struct zippel_perm::Ptr{slong} zippel2_perm::Ptr{slong} can_use::unsigned_int - Gdeflate_deg_bounds_are_nice::int #= all of Gdeflate_deg_bound came from real gcd computations =# + Gdeflate_deg_bounds_are_nice::int data::Ptr{char} end @@ -1029,7 +1031,7 @@ struct nmod_mpolyun_struct exps::Ptr{ulong} alloc::slong length::slong - bits::flint_bitcnt_t #= default bits to construct coeffs =# + bits::flint_bitcnt_t end const nmod_mpolyun_t = Ptr{nmod_mpolyun_struct} From 18ccd228aec27ea7df47213b1b82b310e77fa106 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Thu, 30 Jan 2025 17:50:52 +0100 Subject: [PATCH 10/17] Strip trailing whitespace --- etc/generate_FLINT_structs.jl | 1 + src/flint/FlintCTypes.jl | 80 +++++++++++++++++------------------ 2 files changed, 41 insertions(+), 40 deletions(-) diff --git a/etc/generate_FLINT_structs.jl b/etc/generate_FLINT_structs.jl index 82093aa7f..a6019feac 100644 --- a/etc/generate_FLINT_structs.jl +++ b/etc/generate_FLINT_structs.jl @@ -132,6 +132,7 @@ function c2julia(str::String) output = join( map(m -> replace(m.match, substitutions...), eachmatch(combined_regex, str)), "\n\n" ) + output = replace(output, r"\h*\n" => "\n") # remove trailing whitespace return output end diff --git a/src/flint/FlintCTypes.jl b/src/flint/FlintCTypes.jl index 8085798ec..b93fd413d 100644 --- a/src/flint/FlintCTypes.jl +++ b/src/flint/FlintCTypes.jl @@ -63,14 +63,14 @@ end const flint_rand_t = Ptr{flint_rand_struct} @enum flint_err_t begin - FLINT_ERROR - FLINT_OVERFLOW - FLINT_IMPINV - FLINT_DOMERR - FLINT_DIVZERO - FLINT_EXPOF - FLINT_INEXACT - FLINT_TEST_FAIL + FLINT_ERROR + FLINT_OVERFLOW + FLINT_IMPINV + FLINT_DOMERR + FLINT_DIVZERO + FLINT_EXPOF + FLINT_INEXACT + FLINT_TEST_FAIL end struct nmod_t @@ -170,9 +170,9 @@ struct nmod_mpoly_struct coeffs::Ptr{ulong} exps::Ptr{ulong} length::slong - bits::flint_bitcnt_t - coeffs_alloc::slong - exps_alloc::slong + bits::flint_bitcnt_t + coeffs_alloc::slong + exps_alloc::slong end const nmod_mpoly_t = Ptr{nmod_mpoly_struct} @@ -259,18 +259,18 @@ end const fmpz_poly_mat_t = Ptr{fmpz_poly_mat_struct} struct fmpz_mpoly_struct - coeffs::Ptr{fmpz} + coeffs::Ptr{fmpz} exps::Ptr{ulong} alloc::slong length::slong - bits::flint_bitcnt_t + bits::flint_bitcnt_t end const fmpz_mpoly_t = Ptr{fmpz_mpoly_struct} struct fmpz_mpoly_factor_struct constant::fmpz_t - constant_den::fmpz_t + constant_den::fmpz_t poly::Ptr{fmpz_mpoly_struct} exp::Ptr{fmpz} num::slong @@ -325,9 +325,9 @@ end const fmpq_poly_t = Ptr{fmpq_poly_struct} -struct fmpq_mpoly_struct - content::fmpq_t - zpoly::fmpz_mpoly_t +struct fmpq_mpoly_struct + content::fmpq_t + zpoly::fmpz_mpoly_t end const fmpq_mpoly_t = Ptr{fmpq_mpoly_struct} @@ -388,9 +388,9 @@ struct fmpz_mod_mpoly_struct coeffs::Ptr{fmpz} exps::Ptr{ulong} length::slong - bits::flint_bitcnt_t - coeffs_alloc::slong - exps_alloc::slong + bits::flint_bitcnt_t + coeffs_alloc::slong + exps_alloc::slong end const fmpz_mod_mpoly_t = Ptr{fmpz_mod_mpoly_struct} @@ -420,7 +420,7 @@ struct fq_nmod_ctx_struct mod::nmod_t sparse_modulus::int - is_conway::int + is_conway::int a::Ptr{ulong} j::Ptr{slong} @@ -464,9 +464,9 @@ struct fq_nmod_mpoly_struct coeffs::Ptr{ulong} exps::Ptr{ulong} length::slong - bits::flint_bitcnt_t - coeffs_alloc::slong - exps_alloc::slong + bits::flint_bitcnt_t + coeffs_alloc::slong + exps_alloc::slong end const fq_nmod_mpoly_t = Ptr{fq_nmod_mpoly_struct} @@ -485,19 +485,19 @@ end const fq_zech_t = Ptr{fq_zech_struct} struct fq_zech_ctx_struct - qm1::ulong - qm1o2::ulong - qm1opm1::ulong + qm1::ulong + qm1o2::ulong + qm1opm1::ulong p::ulong ppre::double - prime_root::ulong + prime_root::ulong zech_log_table::Ptr{ulong} prime_field_table::Ptr{ulong} eval_table::Ptr{ulong} fq_nmod_ctx::Ptr{fq_nmod_ctx_struct} owns_fq_nmod_ctx::int - is_conway::int + is_conway::int end const fq_zech_ctx_t = Ptr{fq_zech_ctx_struct} @@ -543,7 +543,7 @@ struct fq_ctx_struct ctxp::fmpz_mod_ctx_t sparse_modulus::int - is_conway::int + is_conway::int a::Ptr{fmpz} j::Ptr{slong} @@ -695,12 +695,12 @@ const fq_default_ctx_t = Ptr{fq_default_ctx_struct} struct _gr_fmpz_mod_ctx_struct ctx::Ptr{fmpz_mod_ctx_struct} is_prime::truth_t - a::fmpz + a::fmpz end struct _gr_nmod_ctx_struct nmod::nmod_t - a::ulong + a::ulong end # end fq_default.h @@ -883,13 +883,13 @@ end const MPOLY_NUM_ORDERINGS = 3 struct mpoly_ctx_struct - nvars::slong - nfields::slong - ord::ordering_t - deg::int - rev::int + nvars::slong + nfields::slong + ord::ordering_t + deg::int + rev::int lut_words_per_exp::NTuple{FLINT_BITS, slong} - lut_fix_bits::NTuple{FLINT_BITS, unsigned_char} + lut_fix_bits::NTuple{FLINT_BITS, unsigned_char} end const mpoly_ctx_t = Ptr{mpoly_ctx_struct} @@ -992,7 +992,7 @@ struct mpoly_gcd_info_struct zippel_perm::Ptr{slong} zippel2_perm::Ptr{slong} can_use::unsigned_int - Gdeflate_deg_bounds_are_nice::int + Gdeflate_deg_bounds_are_nice::int data::Ptr{char} end @@ -1031,7 +1031,7 @@ struct nmod_mpolyun_struct exps::Ptr{ulong} alloc::slong length::slong - bits::flint_bitcnt_t + bits::flint_bitcnt_t end const nmod_mpolyun_t = Ptr{nmod_mpolyun_struct} From d6a3bccfa3861faf52bb3f95ccbbd6a3edaf823c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Fri, 31 Jan 2025 09:32:38 +0100 Subject: [PATCH 11/17] Fix loading --- etc/FlintCTypes_template.jl | 2 ++ src/flint/FlintCTypes.jl | 2 ++ 2 files changed, 4 insertions(+) diff --git a/etc/FlintCTypes_template.jl b/etc/FlintCTypes_template.jl index 474b16607..7d240f85b 100644 --- a/etc/FlintCTypes_template.jl +++ b/etc/FlintCTypes_template.jl @@ -18,6 +18,8 @@ const double = Cdouble const ulong = UInt const slong = Int +WORD(n) = Int(n) +UWORD(n) = UInt(n) # # from `./configure` diff --git a/src/flint/FlintCTypes.jl b/src/flint/FlintCTypes.jl index b93fd413d..48c86e385 100644 --- a/src/flint/FlintCTypes.jl +++ b/src/flint/FlintCTypes.jl @@ -23,6 +23,8 @@ const double = Cdouble const ulong = UInt const slong = Int +WORD(n) = Int(n) +UWORD(n) = UInt(n) # # from `./configure` From 57a89de09db06e3195e17460801c63bbb81de23b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Fri, 31 Jan 2025 10:03:01 +0100 Subject: [PATCH 12/17] Use julia's `Ctype`s --- etc/FlintCTypes_template.jl | 13 +---- etc/generate_FLINT_structs.jl | 20 +++++--- src/flint/FlintCTypes.jl | 93 ++++++++++++++++------------------- 3 files changed, 56 insertions(+), 70 deletions(-) diff --git a/etc/FlintCTypes_template.jl b/etc/FlintCTypes_template.jl index 7d240f85b..a0ddbd67f 100644 --- a/etc/FlintCTypes_template.jl +++ b/etc/FlintCTypes_template.jl @@ -7,24 +7,15 @@ module FlintC # -# C types (names provided to ease automatic conversion of struct definitions) +# FLINT configuration and global definitions # -const void = Cvoid -const int = Cint -const unsigned_int = Cuint -const char = Cchar -const unsigned_char = Cuchar -const double = Cdouble + const ulong = UInt const slong = Int WORD(n) = Int(n) UWORD(n) = UInt(n) -# -# from `./configure` -# - const FLINT_BITS = UInt == UInt64 ? 64 : 32 diff --git a/etc/generate_FLINT_structs.jl b/etc/generate_FLINT_structs.jl index a6019feac..06ba46778 100644 --- a/etc/generate_FLINT_structs.jl +++ b/etc/generate_FLINT_structs.jl @@ -59,7 +59,7 @@ function convert_struct(str::AbstractString) r"^ +([A-Za-z0-9_]+) *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+);"m => s" \2::Ptr{\1}\n \3::Ptr{\1}\n \4::Ptr{\1}\n \5::Ptr{\1}\n \6::Ptr{\1}", r"^ +([A-Za-z0-9_]+) *\* *\* *([A-Za-z0-9_]+);"m => s" \2::Ptr{Ptr{\1}}", # double pointer field r"^ +([A-Za-z0-9_]+) +([A-Za-z0-9_]+)\[([A-Za-z0-9_]+)\];"m => s" \2::NTuple{\3, \1}", # fixed len array field - r"^ +[A-Za-z0-9_]+ *\( *\* *([A-Za-z0-9_]+) *\) *\([a-z_, *]+\);"m => s" \1::Ptr{Nothing}", # function pointer field + r"^ +[A-Za-z0-9_]+ *\( *\* *([A-Za-z0-9_]+) *\) *\([A-Za-z0-9_, *]+\);"m => s" \1::Ptr{Nothing}", # function pointer field r"^ +struct *([A-Za-z0-9_]+) +([A-Za-z0-9_]+);"m => s" \2::struct_\1", # struct field (without typedef) r"^ +enum *([A-Za-z0-9_]+) +([A-Za-z0-9_]+);"m => s" \2::enum_\1", # enum field (without typedef) ] @@ -96,12 +96,16 @@ function convert_union(str::AbstractString) end function c2julia(str::String) - preprocessing = Pair{Regex,Union{SubstitutionString,Function}}[ - r"unsigned int" => s"unsigned_int", # convert `unsigned int` to a single token - r"unsigned char" => s"unsigned_char", # convert `unsigned char` to a single token - r" const " => s" ", # remove all `const` - r"^//(.*)$"m => s"", # remove line comment - r"/\*(.*?)\*/"s => s"", # remove block comment + preprocessing = Pair{Regex,String}[ + r"^//(.*)$"m => "", # remove line comment + r"/\*(.*?)\*/"s => "", # remove block comment + r" const " => " ", # remove all `const` + r"\bvoid\b" => "Cvoid", # replace `void` C type + r"\bunsigned int\b" => "Cuint", # replace `unsigned int` C type + r"\bint\b" => "Cint", # replace `int` C type + r"\bunsigned char\b" => "Cuchar", # replace `unsigned char` C type + r"\bchar\b" => "Cchar", # replace `char` C type + r"\bdouble\b" => "Cdouble", # replace `double` C type ] for substitution in preprocessing str = replace(str, substitution) @@ -124,7 +128,7 @@ function c2julia(str::String) r"^typedef +struct +([A-Za-z_]+) +([A-Za-z_]+);"m => s"const \2 = struct_\1", # struct typedef r"^typedef +enum +([A-Za-z_]+) +([A-Za-z_]+);"m => s"const \2 = enum_\1", # enum typedef r"^typedef +union +([A-Za-z_]+) +([A-Za-z_]+);"m => s"const \2 = union_\1", # union typedef - r"^typedef +[A-Za-z0-9_]+ *\( *\* *([A-Za-z0-9_]+) *\) *\([a-z_, *]+\);"m => s"const \1 = Ptr{Nothing}", # function pointer typedef + r"^typedef +[A-Za-z0-9_]+ *\( *\* *([A-Za-z0-9_]+) *\) *\([A-Za-z0-9_, *]+\);"m => s"const \1 = Ptr{Nothing}", # function pointer typedef r"^#define +([A-Za-z_]+) +(\d+) *$"m => s"const \1 = \2", # defines of integer constants r"^#define +([A-Za-z_]+) +\(([A-Za-z0-9+*() ]+)\) *$"m => s"const \1 = \2", # defines of more complex constants ] diff --git a/src/flint/FlintCTypes.jl b/src/flint/FlintCTypes.jl index 48c86e385..de884929e 100644 --- a/src/flint/FlintCTypes.jl +++ b/src/flint/FlintCTypes.jl @@ -12,24 +12,15 @@ module FlintC # -# C types (names provided to ease automatic conversion of struct definitions) +# FLINT configuration and global definitions # -const void = Cvoid -const int = Cint -const unsigned_int = Cuint -const char = Cchar -const unsigned_char = Cuchar -const double = Cdouble + const ulong = UInt const slong = Int WORD(n) = Int(n) UWORD(n) = UInt(n) -# -# from `./configure` -# - const FLINT_BITS = UInt == UInt64 ? 64 : 32 @@ -54,10 +45,10 @@ const nn_srcptr = Ptr{ulong} const flint_cleanup_function_t = Ptr{Nothing} -const thread_pool_handle = int +const thread_pool_handle = Cint struct flint_rand_struct - __gmp_state::Ptr{void} + __gmp_state::Ptr{Cvoid} __randval::ulong __randval2::ulong end @@ -104,21 +95,21 @@ const MPZ_MIN_ALLOC = 2 const FLINT_MAX_FACTORS_IN_LIMB = 15 struct n_factor_t - num::int - exp::NTuple{FLINT_MAX_FACTORS_IN_LIMB, int} + num::Cint + exp::NTuple{FLINT_MAX_FACTORS_IN_LIMB, Cint} p::NTuple{FLINT_MAX_FACTORS_IN_LIMB, ulong} end struct n_primes_struct small_i::slong small_num::slong - small_primes::Ptr{unsigned_int} + small_primes::Ptr{Cuint} sieve_a::ulong sieve_b::ulong sieve_i::slong sieve_num::slong - sieve::Ptr{char} + sieve::Ptr{Cchar} end const n_primes_t = Ptr{n_primes_struct} @@ -197,8 +188,8 @@ const nmod_mpoly_factor_t = Ptr{nmod_mpoly_factor_struct} # begin fmpz_types.h struct zz_struct - alloc::int - size::int + alloc::Cint + size::Cint ptr::nn_ptr end @@ -207,7 +198,7 @@ const zz_ptr = Ptr{zz_struct} const zz_srcptr = Ptr{zz_struct} struct fmpz_factor_struct - sign::int + sign::Cint p::Ptr{fmpz} exp::Ptr{ulong} alloc::slong @@ -421,8 +412,8 @@ const fq_nmod_struct = nmod_poly_struct struct fq_nmod_ctx_struct mod::nmod_t - sparse_modulus::int - is_conway::int + sparse_modulus::Cint + is_conway::Cint a::Ptr{ulong} j::Ptr{slong} @@ -431,7 +422,7 @@ struct fq_nmod_ctx_struct modulus::nmod_poly_t inv::nmod_poly_t - var::Ptr{char} + var::Ptr{Cchar} end const fq_nmod_ctx_t = Ptr{fq_nmod_ctx_struct} @@ -491,15 +482,15 @@ struct fq_zech_ctx_struct qm1o2::ulong qm1opm1::ulong p::ulong - ppre::double + ppre::Cdouble prime_root::ulong zech_log_table::Ptr{ulong} prime_field_table::Ptr{ulong} eval_table::Ptr{ulong} fq_nmod_ctx::Ptr{fq_nmod_ctx_struct} - owns_fq_nmod_ctx::int - is_conway::int + owns_fq_nmod_ctx::Cint + is_conway::Cint end const fq_zech_ctx_t = Ptr{fq_zech_ctx_struct} @@ -544,8 +535,8 @@ const fq_struct = fmpz_poly_struct struct fq_ctx_struct ctxp::fmpz_mod_ctx_t - sparse_modulus::int - is_conway::int + sparse_modulus::Cint + is_conway::Cint a::Ptr{fmpz} j::Ptr{slong} @@ -554,7 +545,7 @@ struct fq_ctx_struct modulus::fmpz_mod_poly_t inv::fmpz_mod_poly_t - var::Ptr{char} + var::Ptr{Cchar} end const fq_ctx_t = Ptr{fq_ctx_struct} @@ -608,7 +599,7 @@ end struct gr_stream_struct fp::Ptr{FLINT_FILE} - s::Ptr{char} + s::Ptr{Cchar} len::slong alloc::slong end @@ -620,7 +611,7 @@ const gr_funcptr = Ptr{Nothing} const GR_CTX_STRUCT_DATA_BYTES = 6 * sizeof(ulong) struct gr_ctx_struct - data::NTuple{GR_CTX_STRUCT_DATA_BYTES, char} + data::NTuple{GR_CTX_STRUCT_DATA_BYTES, Cchar} which_ring::ulong sizeof_elem::slong methods::Ptr{gr_funcptr} @@ -629,11 +620,11 @@ end const gr_ctx_t = Ptr{gr_ctx_struct} -const gr_ptr = Ptr{void} +const gr_ptr = Ptr{Cvoid} -const gr_srcptr = Ptr{void} +const gr_srcptr = Ptr{Cvoid} -const gr_ctx_ptr = Ptr{void} +const gr_ctx_ptr = Ptr{Cvoid} struct gr_vec_struct entries::gr_ptr @@ -728,7 +719,7 @@ end struct padic_ctx_struct p::fmpz_t - pinv::double + pinv::Cdouble pow::Ptr{fmpz} min::slong max::slong @@ -888,10 +879,10 @@ struct mpoly_ctx_struct nvars::slong nfields::slong ord::ordering_t - deg::int - rev::int + deg::Cint + rev::Cint lut_words_per_exp::NTuple{FLINT_BITS, slong} - lut_fix_bits::NTuple{FLINT_BITS, unsigned_char} + lut_fix_bits::NTuple{FLINT_BITS, Cuchar} end const mpoly_ctx_t = Ptr{mpoly_ctx_struct} @@ -931,7 +922,7 @@ const fq_nmod_mpoly_ctx_t = Ptr{fq_nmod_mpoly_ctx_struct} struct struct_mpoly_void_ring_t elem_size::slong - ctx::Ptr{void} + ctx::Ptr{Cvoid} init::Ptr{Nothing} clear::Ptr{Nothing} is_zero::Ptr{Nothing} @@ -982,21 +973,21 @@ struct mpoly_gcd_info_struct Adeflate_tdeg::slong Bdeflate_tdeg::slong - Adensity::double - Bdensity::double + Adensity::Cdouble + Bdensity::Cdouble - hensel_time::double - brown_time::double - zippel_time::double - zippel2_time::double + hensel_time::Cdouble + brown_time::Cdouble + zippel_time::Cdouble + zippel2_time::Cdouble hensel_perm::Ptr{slong} brown_perm::Ptr{slong} zippel_perm::Ptr{slong} zippel2_perm::Ptr{slong} - can_use::unsigned_int - Gdeflate_deg_bounds_are_nice::int + can_use::Cuint + Gdeflate_deg_bounds_are_nice::Cint - data::Ptr{char} + data::Ptr{Cchar} end const mpoly_gcd_info_t = Ptr{mpoly_gcd_info_struct} @@ -1011,9 +1002,9 @@ struct mpoly_compression_struct umat::Ptr{slong} deltas::Ptr{slong} degs::Ptr{slong} - is_trivial::int - is_perm::int - is_irred::int + is_trivial::Cint + is_perm::Cint + is_irred::Cint end const mpoly_compression_t = Ptr{mpoly_compression_struct} From 2242acc913b2840fdf0cb10d75f7a7cace17a64a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Fri, 31 Jan 2025 10:33:14 +0100 Subject: [PATCH 13/17] Use ref in `typedef newname oldname[1];` --- etc/generate_FLINT_structs.jl | 20 ++-- src/flint/FlintCTypes.jl | 204 +++++++++++++++++----------------- 2 files changed, 112 insertions(+), 112 deletions(-) diff --git a/etc/generate_FLINT_structs.jl b/etc/generate_FLINT_structs.jl index 06ba46778..de93680e3 100644 --- a/etc/generate_FLINT_structs.jl +++ b/etc/generate_FLINT_structs.jl @@ -27,7 +27,7 @@ function expand_templates(input, flintdir) end const regex_typedef_struct_fields_name = r"^typedef struct\s*\{([^{}]+)\}\s*([A-Za-z0-9_]+);"m -const regex_typedef_struct_fields_ptrname = r"^typedef struct\s*\{([^{}]+)\}\s*([A-Za-z0-9_]+)\[1\];"m +const regex_typedef_struct_fields_refname = r"^typedef struct\s*\{([^{}]+)\}\s*([A-Za-z0-9_]+)\[1\];"m const regex_struct_structname_fields = r"^struct *([A-Za-z0-9_]+)\s*\{([^{}]+)\}\s*;"m const regex_struct_structname = r"^struct *([A-Za-z0-9_]+);"m const regex_typedef_struct_structname_fields_name = r"^typedef struct *([A-Za-z0-9_]+)\s*\{([^{}]+)\}\s*([A-Za-z0-9_]+);"m @@ -42,11 +42,11 @@ const regex_typedef_union_unionname_values_name = r"^typedef union *([A-Za-z0-9_ function convert_struct(str::AbstractString) substitutions = Pair{Regex,Union{SubstitutionString,Function}}[ - regex_typedef_struct_fields_name => s"struct \2\1end", # whole typedef struct construct - regex_struct_structname_fields => s"struct struct_\1\2end", # whole struct construct - regex_struct_structname => s"struct struct_\1 end", # whole struct construct without fields - regex_typedef_struct_fields_ptrname => s"struct struct_\2\1end\nconst \2 = Ptr{struct_\2}", # whole typedef struct construct with [1] - regex_typedef_struct_structname_fields_name => s"struct \3\2end\nconst struct_\1 = \3", # whole typedef struct construct with two names + regex_typedef_struct_fields_name => s"struct \2\1end", # whole typedef struct construct + regex_struct_structname_fields => s"struct struct_\1\2end", # whole struct construct + regex_struct_structname => s"struct struct_\1 end", # whole struct construct without fields + regex_typedef_struct_fields_refname => s"struct struct_\2\1end\nconst \2 = Ref{struct_\2}", # whole typedef struct singleton array construct + regex_typedef_struct_structname_fields_name => s"struct \3\2end\nconst struct_\1 = \3", # whole typedef struct construct with two names r"^ +([A-Za-z0-9_]+) +([A-Za-z0-9_]+);"m => s" \2::\1", # simple fields (one to five declared on one line) r"^ +([A-Za-z0-9_]+) +([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+);"m => s" \2::\1\n \3::\1", r"^ +([A-Za-z0-9_]+) +([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+);"m => s" \2::\1\n \3::\1\n \4::\1", @@ -59,7 +59,7 @@ function convert_struct(str::AbstractString) r"^ +([A-Za-z0-9_]+) *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+) *, *\* *([A-Za-z0-9_]+);"m => s" \2::Ptr{\1}\n \3::Ptr{\1}\n \4::Ptr{\1}\n \5::Ptr{\1}\n \6::Ptr{\1}", r"^ +([A-Za-z0-9_]+) *\* *\* *([A-Za-z0-9_]+);"m => s" \2::Ptr{Ptr{\1}}", # double pointer field r"^ +([A-Za-z0-9_]+) +([A-Za-z0-9_]+)\[([A-Za-z0-9_]+)\];"m => s" \2::NTuple{\3, \1}", # fixed len array field - r"^ +[A-Za-z0-9_]+ *\( *\* *([A-Za-z0-9_]+) *\) *\([A-Za-z0-9_, *]+\);"m => s" \1::Ptr{Nothing}", # function pointer field + r"^ +[A-Za-z0-9_]+ *\( *\* *([A-Za-z0-9_]+) *\) *\([A-Za-z0-9_, *]+\);"m => s" \1::Ptr{Cvoid}", # function pointer field r"^ +struct *([A-Za-z0-9_]+) +([A-Za-z0-9_]+);"m => s" \2::struct_\1", # struct field (without typedef) r"^ +enum *([A-Za-z0-9_]+) +([A-Za-z0-9_]+);"m => s" \2::enum_\1", # enum field (without typedef) ] @@ -112,7 +112,7 @@ function c2julia(str::String) end substitutions = Pair{Regex,Union{SubstitutionString,Function}}[ regex_typedef_struct_fields_name => convert_struct, # whole typedef struct construct - regex_typedef_struct_fields_ptrname => convert_struct, # whole typedef struct construct with [1] + regex_typedef_struct_fields_refname => convert_struct, # whole typedef struct singleton array construct regex_struct_structname_fields => convert_struct, # whole struct construct regex_struct_structname => convert_struct, # whole struct construct without fields regex_typedef_struct_structname_fields_name => convert_struct, # whole typedef struct construct with two names @@ -124,11 +124,11 @@ function c2julia(str::String) regex_typedef_union_unionname_values_name => convert_union, # whole typedef union construct with two names r"^typedef +([A-Za-z_]+) +([A-Za-z_]+);"m => s"const \2 = \1", # simple typedef r"^typedef +([A-Za-z_]+) *\* *([A-Za-z_]+);"m => s"const \2 = Ptr{\1}", # pointer typedef - r"^typedef +([A-Za-z_]+) +([A-Za-z_]+)\[1\];"m => s"const \2 = Ptr{\1}", # pointer typedef + r"^typedef +([A-Za-z_]+) +([A-Za-z_]+)\[1\];"m => s"const \2 = Ref{\1}", # singleton array typedef r"^typedef +struct +([A-Za-z_]+) +([A-Za-z_]+);"m => s"const \2 = struct_\1", # struct typedef r"^typedef +enum +([A-Za-z_]+) +([A-Za-z_]+);"m => s"const \2 = enum_\1", # enum typedef r"^typedef +union +([A-Za-z_]+) +([A-Za-z_]+);"m => s"const \2 = union_\1", # union typedef - r"^typedef +[A-Za-z0-9_]+ *\( *\* *([A-Za-z0-9_]+) *\) *\([A-Za-z0-9_, *]+\);"m => s"const \1 = Ptr{Nothing}", # function pointer typedef + r"^typedef +[A-Za-z0-9_]+ *\( *\* *([A-Za-z0-9_]+) *\) *\([A-Za-z0-9_, *]+\);"m => s"const \1 = Ptr{Cvoid}", # function pointer typedef r"^#define +([A-Za-z_]+) +(\d+) *$"m => s"const \1 = \2", # defines of integer constants r"^#define +([A-Za-z_]+) +\(([A-Za-z0-9+*() ]+)\) *$"m => s"const \1 = \2", # defines of more complex constants ] diff --git a/src/flint/FlintCTypes.jl b/src/flint/FlintCTypes.jl index de884929e..0bb89d742 100644 --- a/src/flint/FlintCTypes.jl +++ b/src/flint/FlintCTypes.jl @@ -43,7 +43,7 @@ const nn_ptr = Ptr{ulong} const nn_srcptr = Ptr{ulong} -const flint_cleanup_function_t = Ptr{Nothing} +const flint_cleanup_function_t = Ptr{Cvoid} const thread_pool_handle = Cint @@ -53,7 +53,7 @@ struct flint_rand_struct __randval2::ulong end -const flint_rand_t = Ptr{flint_rand_struct} +const flint_rand_t = Ref{flint_rand_struct} @enum flint_err_t begin FLINT_ERROR @@ -74,14 +74,14 @@ end const fmpz = slong -const fmpz_t = Ptr{fmpz} +const fmpz_t = Ref{fmpz} struct fmpq num::fmpz den::fmpz end -const fmpq_t = Ptr{fmpq} +const fmpq_t = Ref{fmpq} const MPZ_MIN_ALLOC = 2 @@ -112,7 +112,7 @@ struct n_primes_struct sieve::Ptr{Cchar} end -const n_primes_t = Ptr{n_primes_struct} +const n_primes_t = Ref{n_primes_struct} # end limb_types.h ############################################################################### @@ -129,7 +129,7 @@ struct nmod_mat_struct mod::nmod_t end -const nmod_mat_t = Ptr{nmod_mat_struct} +const nmod_mat_t = Ref{nmod_mat_struct} struct nmod_poly_struct coeffs::nn_ptr @@ -138,7 +138,7 @@ struct nmod_poly_struct mod::nmod_t end -const nmod_poly_t = Ptr{nmod_poly_struct} +const nmod_poly_t = Ref{nmod_poly_struct} struct nmod_poly_factor_struct p::Ptr{nmod_poly_struct} @@ -147,7 +147,7 @@ struct nmod_poly_factor_struct alloc::slong end -const nmod_poly_factor_t = Ptr{nmod_poly_factor_struct} +const nmod_poly_factor_t = Ref{nmod_poly_factor_struct} struct nmod_poly_mat_struct entries::Ptr{nmod_poly_struct} @@ -157,7 +157,7 @@ struct nmod_poly_mat_struct modulus::ulong end -const nmod_poly_mat_t = Ptr{nmod_poly_mat_struct} +const nmod_poly_mat_t = Ref{nmod_poly_mat_struct} struct nmod_mpoly_struct coeffs::Ptr{ulong} @@ -168,7 +168,7 @@ struct nmod_mpoly_struct exps_alloc::slong end -const nmod_mpoly_t = Ptr{nmod_mpoly_struct} +const nmod_mpoly_t = Ref{nmod_mpoly_struct} struct nmod_mpoly_factor_struct constant::ulong @@ -178,7 +178,7 @@ struct nmod_mpoly_factor_struct alloc::slong end -const nmod_mpoly_factor_t = Ptr{nmod_mpoly_factor_struct} +const nmod_mpoly_factor_t = Ref{nmod_mpoly_factor_struct} # end nmod_types.h ############################################################################### @@ -205,7 +205,7 @@ struct fmpz_factor_struct num::slong end -const fmpz_factor_t = Ptr{fmpz_factor_struct} +const fmpz_factor_t = Ref{fmpz_factor_struct} struct fmpz_preinvn_struct dinv::nn_ptr @@ -213,7 +213,7 @@ struct fmpz_preinvn_struct norm::flint_bitcnt_t end -const fmpz_preinvn_t = Ptr{fmpz_preinvn_struct} +const fmpz_preinvn_t = Ref{fmpz_preinvn_struct} struct fmpz_poly_struct coeffs::Ptr{fmpz} @@ -221,7 +221,7 @@ struct fmpz_poly_struct length::slong end -const fmpz_poly_t = Ptr{fmpz_poly_struct} +const fmpz_poly_t = Ref{fmpz_poly_struct} struct fmpz_poly_factor_struct c::fmpz @@ -231,7 +231,7 @@ struct fmpz_poly_factor_struct alloc::slong end -const fmpz_poly_factor_t = Ptr{fmpz_poly_factor_struct} +const fmpz_poly_factor_t = Ref{fmpz_poly_factor_struct} struct fmpz_mat_struct entries::Ptr{fmpz} @@ -240,7 +240,7 @@ struct fmpz_mat_struct rows::Ptr{Ptr{fmpz}} end -const fmpz_mat_t = Ptr{fmpz_mat_struct} +const fmpz_mat_t = Ref{fmpz_mat_struct} struct fmpz_poly_mat_struct entries::Ptr{fmpz_poly_struct} @@ -249,7 +249,7 @@ struct fmpz_poly_mat_struct rows::Ptr{Ptr{fmpz_poly_struct}} end -const fmpz_poly_mat_t = Ptr{fmpz_poly_mat_struct} +const fmpz_poly_mat_t = Ref{fmpz_poly_mat_struct} struct fmpz_mpoly_struct coeffs::Ptr{fmpz} @@ -259,7 +259,7 @@ struct fmpz_mpoly_struct bits::flint_bitcnt_t end -const fmpz_mpoly_t = Ptr{fmpz_mpoly_struct} +const fmpz_mpoly_t = Ref{fmpz_mpoly_struct} struct fmpz_mpoly_factor_struct constant::fmpz_t @@ -270,28 +270,28 @@ struct fmpz_mpoly_factor_struct alloc::slong end -const fmpz_mpoly_factor_t = Ptr{fmpz_mpoly_factor_struct} +const fmpz_mpoly_factor_t = Ref{fmpz_mpoly_factor_struct} struct fmpz_poly_q_struct num::Ptr{fmpz_poly_struct} den::Ptr{fmpz_poly_struct} end -const fmpz_poly_q_t = Ptr{fmpz_poly_q_struct} +const fmpz_poly_q_t = Ref{fmpz_poly_q_struct} struct fmpz_mpoly_q_struct num::fmpz_mpoly_struct den::fmpz_mpoly_struct end -const fmpz_mpoly_q_t = Ptr{fmpz_mpoly_q_struct} +const fmpz_mpoly_q_t = Ref{fmpz_mpoly_q_struct} struct fmpzi_struct a::fmpz b::fmpz end -const fmpzi_t = Ptr{fmpzi_struct} +const fmpzi_t = Ref{fmpzi_struct} # end fmpz_types.h ############################################################################### @@ -307,7 +307,7 @@ struct fmpq_mat_struct rows::Ptr{Ptr{fmpq}} end -const fmpq_mat_t = Ptr{fmpq_mat_struct} +const fmpq_mat_t = Ref{fmpq_mat_struct} struct fmpq_poly_struct coeffs::Ptr{fmpz} @@ -316,14 +316,14 @@ struct fmpq_poly_struct den::fmpz_t end -const fmpq_poly_t = Ptr{fmpq_poly_struct} +const fmpq_poly_t = Ref{fmpq_poly_struct} struct fmpq_mpoly_struct content::fmpq_t zpoly::fmpz_mpoly_t end -const fmpq_mpoly_t = Ptr{fmpq_mpoly_struct} +const fmpq_mpoly_t = Ref{fmpq_mpoly_struct} struct fmpq_mpoly_factor_struct constant::fmpq_t @@ -333,7 +333,7 @@ struct fmpq_mpoly_factor_struct alloc::slong end -const fmpq_mpoly_factor_t = Ptr{fmpq_mpoly_factor_struct} +const fmpq_mpoly_factor_t = Ref{fmpq_mpoly_factor_struct} # end fmpq_types.h ############################################################################### @@ -344,9 +344,9 @@ const fmpq_mpoly_factor_t = Ptr{fmpq_mpoly_factor_struct} struct fmpz_mod_ctx_struct n::fmpz_t - add_fxn::Ptr{Nothing} - sub_fxn::Ptr{Nothing} - mul_fxn::Ptr{Nothing} + add_fxn::Ptr{Cvoid} + sub_fxn::Ptr{Cvoid} + mul_fxn::Ptr{Cvoid} mod::nmod_t n_limbs::NTuple{3, ulong} ninv_limbs::NTuple{3, ulong} @@ -354,11 +354,11 @@ struct fmpz_mod_ctx_struct end const struct_fmpz_mod_ctx = fmpz_mod_ctx_struct -const fmpz_mod_ctx_t = Ptr{fmpz_mod_ctx_struct} +const fmpz_mod_ctx_t = Ref{fmpz_mod_ctx_struct} const fmpz_mod_mat_struct = fmpz_mat_struct -const fmpz_mod_mat_t = Ptr{fmpz_mod_mat_struct} +const fmpz_mod_mat_t = Ref{fmpz_mod_mat_struct} struct fmpz_mod_poly_struct coeffs::Ptr{fmpz} @@ -366,7 +366,7 @@ struct fmpz_mod_poly_struct length::slong end -const fmpz_mod_poly_t = Ptr{fmpz_mod_poly_struct} +const fmpz_mod_poly_t = Ref{fmpz_mod_poly_struct} struct fmpz_mod_poly_factor_struct poly::Ptr{fmpz_mod_poly_struct} @@ -375,7 +375,7 @@ struct fmpz_mod_poly_factor_struct alloc::slong end -const fmpz_mod_poly_factor_t = Ptr{fmpz_mod_poly_factor_struct} +const fmpz_mod_poly_factor_t = Ref{fmpz_mod_poly_factor_struct} struct fmpz_mod_mpoly_struct coeffs::Ptr{fmpz} @@ -386,7 +386,7 @@ struct fmpz_mod_mpoly_struct exps_alloc::slong end -const fmpz_mod_mpoly_t = Ptr{fmpz_mod_mpoly_struct} +const fmpz_mod_mpoly_t = Ref{fmpz_mod_mpoly_struct} struct fmpz_mod_mpoly_factor_struct constant::fmpz_t @@ -396,7 +396,7 @@ struct fmpz_mod_mpoly_factor_struct alloc::slong end -const fmpz_mod_mpoly_factor_t = Ptr{fmpz_mod_mpoly_factor_struct} +const fmpz_mod_mpoly_factor_t = Ref{fmpz_mod_mpoly_factor_struct} # end fmpz_mod_types.h ############################################################################### @@ -425,7 +425,7 @@ struct fq_nmod_ctx_struct var::Ptr{Cchar} end -const fq_nmod_ctx_t = Ptr{fq_nmod_ctx_struct} +const fq_nmod_ctx_t = Ref{fq_nmod_ctx_struct} struct fq_nmod_mat_struct entries::Ptr{fq_nmod_struct} @@ -434,7 +434,7 @@ struct fq_nmod_mat_struct rows::Ptr{Ptr{fq_nmod_struct}} end -const fq_nmod_mat_t = Ptr{fq_nmod_mat_struct} +const fq_nmod_mat_t = Ref{fq_nmod_mat_struct} struct fq_nmod_poly_struct coeffs::Ptr{fq_nmod_struct} @@ -442,7 +442,7 @@ struct fq_nmod_poly_struct length::slong end -const fq_nmod_poly_t = Ptr{fq_nmod_poly_struct} +const fq_nmod_poly_t = Ref{fq_nmod_poly_struct} struct fq_nmod_poly_factor_struct poly::Ptr{fq_nmod_poly_struct} @@ -451,7 +451,7 @@ struct fq_nmod_poly_factor_struct alloc::slong end -const fq_nmod_poly_factor_t = Ptr{fq_nmod_poly_factor_struct} +const fq_nmod_poly_factor_t = Ref{fq_nmod_poly_factor_struct} struct fq_nmod_mpoly_struct coeffs::Ptr{ulong} @@ -462,7 +462,7 @@ struct fq_nmod_mpoly_struct exps_alloc::slong end -const fq_nmod_mpoly_t = Ptr{fq_nmod_mpoly_struct} +const fq_nmod_mpoly_t = Ref{fq_nmod_mpoly_struct} # end fq_nmod_types.h ############################################################################### @@ -475,7 +475,7 @@ struct fq_zech_struct value::ulong end -const fq_zech_t = Ptr{fq_zech_struct} +const fq_zech_t = Ref{fq_zech_struct} struct fq_zech_ctx_struct qm1::ulong @@ -493,7 +493,7 @@ struct fq_zech_ctx_struct is_conway::Cint end -const fq_zech_ctx_t = Ptr{fq_zech_ctx_struct} +const fq_zech_ctx_t = Ref{fq_zech_ctx_struct} struct fq_zech_mat_struct entries::Ptr{fq_zech_struct} @@ -502,7 +502,7 @@ struct fq_zech_mat_struct rows::Ptr{Ptr{fq_zech_struct}} end -const fq_zech_mat_t = Ptr{fq_zech_mat_struct} +const fq_zech_mat_t = Ref{fq_zech_mat_struct} struct fq_zech_poly_struct coeffs::Ptr{fq_zech_struct} @@ -510,7 +510,7 @@ struct fq_zech_poly_struct length::slong end -const fq_zech_poly_t = Ptr{fq_zech_poly_struct} +const fq_zech_poly_t = Ref{fq_zech_poly_struct} struct fq_zech_poly_factor_struct poly::Ptr{fq_zech_poly_struct} @@ -519,7 +519,7 @@ struct fq_zech_poly_factor_struct alloc::slong end -const fq_zech_poly_factor_t = Ptr{fq_zech_poly_factor_struct} +const fq_zech_poly_factor_t = Ref{fq_zech_poly_factor_struct} # end fq_zech_types.h ############################################################################### @@ -548,7 +548,7 @@ struct fq_ctx_struct var::Ptr{Cchar} end -const fq_ctx_t = Ptr{fq_ctx_struct} +const fq_ctx_t = Ref{fq_ctx_struct} struct fq_mat_struct entries::Ptr{fq_struct} @@ -557,7 +557,7 @@ struct fq_mat_struct rows::Ptr{Ptr{fq_struct}} end -const fq_mat_t = Ptr{fq_mat_struct} +const fq_mat_t = Ref{fq_mat_struct} struct fq_poly_struct coeffs::Ptr{fq_struct} @@ -565,7 +565,7 @@ struct fq_poly_struct length::slong end -const fq_poly_t = Ptr{fq_poly_struct} +const fq_poly_t = Ref{fq_poly_struct} struct fq_poly_factor_struct poly::Ptr{fq_poly_struct} @@ -574,7 +574,7 @@ struct fq_poly_factor_struct alloc::slong end -const fq_poly_factor_t = Ptr{fq_poly_factor_struct} +const fq_poly_factor_t = Ref{fq_poly_factor_struct} # end fq_types.h ############################################################################### @@ -604,9 +604,9 @@ struct gr_stream_struct alloc::slong end -const gr_stream_t = Ptr{gr_stream_struct} +const gr_stream_t = Ref{gr_stream_struct} -const gr_funcptr = Ptr{Nothing} +const gr_funcptr = Ptr{Cvoid} const GR_CTX_STRUCT_DATA_BYTES = 6 * sizeof(ulong) @@ -618,7 +618,7 @@ struct gr_ctx_struct size_limit::ulong end -const gr_ctx_t = Ptr{gr_ctx_struct} +const gr_ctx_t = Ref{gr_ctx_struct} const gr_ptr = Ptr{Cvoid} @@ -632,7 +632,7 @@ struct gr_vec_struct length::slong end -const gr_vec_t = Ptr{gr_vec_struct} +const gr_vec_t = Ref{gr_vec_struct} struct gr_mat_struct entries::gr_ptr @@ -641,7 +641,7 @@ struct gr_mat_struct rows::Ptr{gr_ptr} end -const gr_mat_t = Ptr{gr_mat_struct} +const gr_mat_t = Ref{gr_mat_struct} struct gr_poly_struct coeffs::gr_ptr @@ -649,7 +649,7 @@ struct gr_poly_struct length::slong end -const gr_poly_t = Ptr{gr_poly_struct} +const gr_poly_t = Ref{gr_poly_struct} # end gr_types.h ############################################################################### @@ -669,21 +669,21 @@ const FQ_DEFAULT_NMOD = 4 const FQ_DEFAULT_FMPZ_MOD = 5 struct fq_default_struct - uniondata::NTuple{maximum(sizeof, ( + uniondata::Union{ fq_t, fq_nmod_t, fq_zech_t, ulong, fmpz_t, - )), UInt8} + } end const union_fq_default_struct = fq_default_struct -const fq_default_t = Ptr{fq_default_struct} +const fq_default_t = Ref{fq_default_struct} const fq_default_ctx_struct = gr_ctx_struct -const fq_default_ctx_t = Ptr{fq_default_ctx_struct} +const fq_default_ctx_t = Ref{fq_default_ctx_struct} struct _gr_fmpz_mod_ctx_struct ctx::Ptr{fmpz_mod_ctx_struct} @@ -709,7 +709,7 @@ struct padic_struct N::slong end -const padic_t = Ptr{padic_struct} +const padic_t = Ref{padic_struct} @enum enum_padic_print_mode begin PADIC_TERSE @@ -726,14 +726,14 @@ struct padic_ctx_struct mode::enum_padic_print_mode end -const padic_ctx_t = Ptr{padic_ctx_struct} +const padic_ctx_t = Ref{padic_ctx_struct} struct padic_inv_struct n::slong pow::Ptr{fmpz} end -const padic_inv_t = Ptr{padic_inv_struct} +const padic_inv_t = Ref{padic_inv_struct} struct padic_mat_struct mat::fmpz_mat_struct @@ -741,7 +741,7 @@ struct padic_mat_struct N::slong end -const padic_mat_t = Ptr{padic_mat_struct} +const padic_mat_t = Ref{padic_mat_struct} struct padic_poly_struct coeffs::Ptr{fmpz} @@ -751,7 +751,7 @@ struct padic_poly_struct N::slong end -const padic_poly_t = Ptr{padic_poly_struct} +const padic_poly_t = Ref{padic_poly_struct} # end padic_types.h ############################################################################### @@ -766,7 +766,7 @@ struct n_poly_struct length::slong end -const n_poly_t = Ptr{n_poly_struct} +const n_poly_t = Ref{n_poly_struct} const n_fq_poly_struct = n_poly_struct @@ -778,7 +778,7 @@ struct n_bpoly_struct length::slong end -const n_bpoly_t = Ptr{n_bpoly_struct} +const n_bpoly_t = Ref{n_bpoly_struct} const n_fq_bpoly_struct = n_bpoly_struct @@ -790,7 +790,7 @@ struct n_tpoly_struct length::slong end -const n_tpoly_t = Ptr{n_tpoly_struct} +const n_tpoly_t = Ref{n_tpoly_struct} const n_fq_tpoly_struct = n_tpoly_struct @@ -803,7 +803,7 @@ struct n_polyu_struct alloc::slong end -const n_polyu_t = Ptr{n_polyu_struct} +const n_polyu_t = Ref{n_polyu_struct} const n_fq_polyu_struct = n_polyu_struct @@ -816,7 +816,7 @@ struct n_polyun_struct alloc::slong end -const n_polyun_t = Ptr{n_polyun_struct} +const n_polyun_t = Ref{n_polyun_struct} const n_fq_polyun_struct = n_polyun_struct @@ -828,7 +828,7 @@ struct n_poly_stack_struct top::slong end -const n_poly_stack_t = Ptr{n_poly_stack_struct} +const n_poly_stack_t = Ref{n_poly_stack_struct} struct n_bpoly_stack_struct array::Ptr{Ptr{n_bpoly_struct}} @@ -836,14 +836,14 @@ struct n_bpoly_stack_struct top::slong end -const n_bpoly_stack_t = Ptr{n_bpoly_stack_struct} +const n_bpoly_stack_t = Ref{n_bpoly_stack_struct} struct n_poly_bpoly_stack_struct poly_stack::n_poly_stack_t bpoly_stack::n_bpoly_stack_t end -const n_poly_bpoly_stack_t = Ptr{n_poly_bpoly_stack_struct} +const n_poly_bpoly_stack_t = Ref{n_poly_bpoly_stack_struct} struct nmod_eval_interp_struct M::Ptr{ulong} @@ -856,7 +856,7 @@ struct nmod_eval_interp_struct w::ulong end -const nmod_eval_interp_t = Ptr{nmod_eval_interp_struct} +const nmod_eval_interp_t = Ref{nmod_eval_interp_struct} # end n_poly_types.h ############################################################################### @@ -885,63 +885,63 @@ struct mpoly_ctx_struct lut_fix_bits::NTuple{FLINT_BITS, Cuchar} end -const mpoly_ctx_t = Ptr{mpoly_ctx_struct} +const mpoly_ctx_t = Ref{mpoly_ctx_struct} struct nmod_mpoly_ctx_struct minfo::mpoly_ctx_t mod::nmod_t end -const nmod_mpoly_ctx_t = Ptr{nmod_mpoly_ctx_struct} +const nmod_mpoly_ctx_t = Ref{nmod_mpoly_ctx_struct} struct fmpz_mpoly_ctx_struct minfo::mpoly_ctx_t end -const fmpz_mpoly_ctx_t = Ptr{fmpz_mpoly_ctx_struct} +const fmpz_mpoly_ctx_t = Ref{fmpz_mpoly_ctx_struct} struct fmpq_mpoly_ctx_struct zctx::fmpz_mpoly_ctx_t end -const fmpq_mpoly_ctx_t = Ptr{fmpq_mpoly_ctx_struct} +const fmpq_mpoly_ctx_t = Ref{fmpq_mpoly_ctx_struct} struct fmpz_mod_mpoly_ctx_struct minfo::mpoly_ctx_t ffinfo::fmpz_mod_ctx_t end -const fmpz_mod_mpoly_ctx_t = Ptr{fmpz_mod_mpoly_ctx_struct} +const fmpz_mod_mpoly_ctx_t = Ref{fmpz_mod_mpoly_ctx_struct} struct fq_nmod_mpoly_ctx_struct minfo::mpoly_ctx_t fqctx::fq_nmod_ctx_t end -const fq_nmod_mpoly_ctx_t = Ptr{fq_nmod_mpoly_ctx_struct} +const fq_nmod_mpoly_ctx_t = Ref{fq_nmod_mpoly_ctx_struct} struct struct_mpoly_void_ring_t elem_size::slong ctx::Ptr{Cvoid} - init::Ptr{Nothing} - clear::Ptr{Nothing} - is_zero::Ptr{Nothing} - zero::Ptr{Nothing} - one::Ptr{Nothing} - set_fmpz::Ptr{Nothing} - set::Ptr{Nothing} - swap::Ptr{Nothing} - neg::Ptr{Nothing} - add::Ptr{Nothing} - sub::Ptr{Nothing} - mul_fmpz::Ptr{Nothing} - mul::Ptr{Nothing} - divexact::Ptr{Nothing} - divides::Ptr{Nothing} - pow_fmpz::Ptr{Nothing} - length::Ptr{Nothing} -end -const mpoly_void_ring_t = Ptr{struct_mpoly_void_ring_t} + init::Ptr{Cvoid} + clear::Ptr{Cvoid} + is_zero::Ptr{Cvoid} + zero::Ptr{Cvoid} + one::Ptr{Cvoid} + set_fmpz::Ptr{Cvoid} + set::Ptr{Cvoid} + swap::Ptr{Cvoid} + neg::Ptr{Cvoid} + add::Ptr{Cvoid} + sub::Ptr{Cvoid} + mul_fmpz::Ptr{Cvoid} + mul::Ptr{Cvoid} + divexact::Ptr{Cvoid} + divides::Ptr{Cvoid} + pow_fmpz::Ptr{Cvoid} + length::Ptr{Cvoid} +end +const mpoly_void_ring_t = Ref{struct_mpoly_void_ring_t} struct mpoly_gcd_info_struct Amax_exp::Ptr{ulong} @@ -990,7 +990,7 @@ struct mpoly_gcd_info_struct data::Ptr{Cchar} end -const mpoly_gcd_info_t = Ptr{mpoly_gcd_info_struct} +const mpoly_gcd_info_t = Ref{mpoly_gcd_info_struct} struct mpoly_compression_struct mvars::slong @@ -1007,7 +1007,7 @@ struct mpoly_compression_struct is_irred::Cint end -const mpoly_compression_t = Ptr{mpoly_compression_struct} +const mpoly_compression_t = Ref{mpoly_compression_struct} struct nmod_mpolyn_struct coeffs::Ptr{n_poly_struct} @@ -1017,7 +1017,7 @@ struct nmod_mpolyn_struct bits::slong end -const nmod_mpolyn_t = Ptr{nmod_mpolyn_struct} +const nmod_mpolyn_t = Ref{nmod_mpolyn_struct} struct nmod_mpolyun_struct coeffs::Ptr{nmod_mpolyn_struct} @@ -1027,7 +1027,7 @@ struct nmod_mpolyun_struct bits::flint_bitcnt_t end -const nmod_mpolyun_t = Ptr{nmod_mpolyun_struct} +const nmod_mpolyun_t = Ref{nmod_mpolyun_struct} @enum nmod_gcds_ret_t begin nmod_gcds_success From 6c65f331ab0cc2534d73a080c19676101beaabbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Fri, 31 Jan 2025 10:42:10 +0100 Subject: [PATCH 14/17] Use singleton tuples instead --- etc/generate_FLINT_structs.jl | 4 +- src/flint/FlintCTypes.jl | 158 +++++++++++++++++----------------- 2 files changed, 81 insertions(+), 81 deletions(-) diff --git a/etc/generate_FLINT_structs.jl b/etc/generate_FLINT_structs.jl index de93680e3..db61a25ca 100644 --- a/etc/generate_FLINT_structs.jl +++ b/etc/generate_FLINT_structs.jl @@ -45,7 +45,7 @@ function convert_struct(str::AbstractString) regex_typedef_struct_fields_name => s"struct \2\1end", # whole typedef struct construct regex_struct_structname_fields => s"struct struct_\1\2end", # whole struct construct regex_struct_structname => s"struct struct_\1 end", # whole struct construct without fields - regex_typedef_struct_fields_refname => s"struct struct_\2\1end\nconst \2 = Ref{struct_\2}", # whole typedef struct singleton array construct + regex_typedef_struct_fields_refname => s"struct struct_\2\1end\nconst \2 = Tuple{struct_\2}", # whole typedef struct singleton array construct regex_typedef_struct_structname_fields_name => s"struct \3\2end\nconst struct_\1 = \3", # whole typedef struct construct with two names r"^ +([A-Za-z0-9_]+) +([A-Za-z0-9_]+);"m => s" \2::\1", # simple fields (one to five declared on one line) r"^ +([A-Za-z0-9_]+) +([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+);"m => s" \2::\1\n \3::\1", @@ -124,7 +124,7 @@ function c2julia(str::String) regex_typedef_union_unionname_values_name => convert_union, # whole typedef union construct with two names r"^typedef +([A-Za-z_]+) +([A-Za-z_]+);"m => s"const \2 = \1", # simple typedef r"^typedef +([A-Za-z_]+) *\* *([A-Za-z_]+);"m => s"const \2 = Ptr{\1}", # pointer typedef - r"^typedef +([A-Za-z_]+) +([A-Za-z_]+)\[1\];"m => s"const \2 = Ref{\1}", # singleton array typedef + r"^typedef +([A-Za-z_]+) +([A-Za-z_]+)\[1\];"m => s"const \2 = Tuple{\1}", # singleton array typedef r"^typedef +struct +([A-Za-z_]+) +([A-Za-z_]+);"m => s"const \2 = struct_\1", # struct typedef r"^typedef +enum +([A-Za-z_]+) +([A-Za-z_]+);"m => s"const \2 = enum_\1", # enum typedef r"^typedef +union +([A-Za-z_]+) +([A-Za-z_]+);"m => s"const \2 = union_\1", # union typedef diff --git a/src/flint/FlintCTypes.jl b/src/flint/FlintCTypes.jl index 0bb89d742..e7a52839f 100644 --- a/src/flint/FlintCTypes.jl +++ b/src/flint/FlintCTypes.jl @@ -53,7 +53,7 @@ struct flint_rand_struct __randval2::ulong end -const flint_rand_t = Ref{flint_rand_struct} +const flint_rand_t = Tuple{flint_rand_struct} @enum flint_err_t begin FLINT_ERROR @@ -74,14 +74,14 @@ end const fmpz = slong -const fmpz_t = Ref{fmpz} +const fmpz_t = Tuple{fmpz} struct fmpq num::fmpz den::fmpz end -const fmpq_t = Ref{fmpq} +const fmpq_t = Tuple{fmpq} const MPZ_MIN_ALLOC = 2 @@ -112,7 +112,7 @@ struct n_primes_struct sieve::Ptr{Cchar} end -const n_primes_t = Ref{n_primes_struct} +const n_primes_t = Tuple{n_primes_struct} # end limb_types.h ############################################################################### @@ -129,7 +129,7 @@ struct nmod_mat_struct mod::nmod_t end -const nmod_mat_t = Ref{nmod_mat_struct} +const nmod_mat_t = Tuple{nmod_mat_struct} struct nmod_poly_struct coeffs::nn_ptr @@ -138,7 +138,7 @@ struct nmod_poly_struct mod::nmod_t end -const nmod_poly_t = Ref{nmod_poly_struct} +const nmod_poly_t = Tuple{nmod_poly_struct} struct nmod_poly_factor_struct p::Ptr{nmod_poly_struct} @@ -147,7 +147,7 @@ struct nmod_poly_factor_struct alloc::slong end -const nmod_poly_factor_t = Ref{nmod_poly_factor_struct} +const nmod_poly_factor_t = Tuple{nmod_poly_factor_struct} struct nmod_poly_mat_struct entries::Ptr{nmod_poly_struct} @@ -157,7 +157,7 @@ struct nmod_poly_mat_struct modulus::ulong end -const nmod_poly_mat_t = Ref{nmod_poly_mat_struct} +const nmod_poly_mat_t = Tuple{nmod_poly_mat_struct} struct nmod_mpoly_struct coeffs::Ptr{ulong} @@ -168,7 +168,7 @@ struct nmod_mpoly_struct exps_alloc::slong end -const nmod_mpoly_t = Ref{nmod_mpoly_struct} +const nmod_mpoly_t = Tuple{nmod_mpoly_struct} struct nmod_mpoly_factor_struct constant::ulong @@ -178,7 +178,7 @@ struct nmod_mpoly_factor_struct alloc::slong end -const nmod_mpoly_factor_t = Ref{nmod_mpoly_factor_struct} +const nmod_mpoly_factor_t = Tuple{nmod_mpoly_factor_struct} # end nmod_types.h ############################################################################### @@ -205,7 +205,7 @@ struct fmpz_factor_struct num::slong end -const fmpz_factor_t = Ref{fmpz_factor_struct} +const fmpz_factor_t = Tuple{fmpz_factor_struct} struct fmpz_preinvn_struct dinv::nn_ptr @@ -213,7 +213,7 @@ struct fmpz_preinvn_struct norm::flint_bitcnt_t end -const fmpz_preinvn_t = Ref{fmpz_preinvn_struct} +const fmpz_preinvn_t = Tuple{fmpz_preinvn_struct} struct fmpz_poly_struct coeffs::Ptr{fmpz} @@ -221,7 +221,7 @@ struct fmpz_poly_struct length::slong end -const fmpz_poly_t = Ref{fmpz_poly_struct} +const fmpz_poly_t = Tuple{fmpz_poly_struct} struct fmpz_poly_factor_struct c::fmpz @@ -231,7 +231,7 @@ struct fmpz_poly_factor_struct alloc::slong end -const fmpz_poly_factor_t = Ref{fmpz_poly_factor_struct} +const fmpz_poly_factor_t = Tuple{fmpz_poly_factor_struct} struct fmpz_mat_struct entries::Ptr{fmpz} @@ -240,7 +240,7 @@ struct fmpz_mat_struct rows::Ptr{Ptr{fmpz}} end -const fmpz_mat_t = Ref{fmpz_mat_struct} +const fmpz_mat_t = Tuple{fmpz_mat_struct} struct fmpz_poly_mat_struct entries::Ptr{fmpz_poly_struct} @@ -249,7 +249,7 @@ struct fmpz_poly_mat_struct rows::Ptr{Ptr{fmpz_poly_struct}} end -const fmpz_poly_mat_t = Ref{fmpz_poly_mat_struct} +const fmpz_poly_mat_t = Tuple{fmpz_poly_mat_struct} struct fmpz_mpoly_struct coeffs::Ptr{fmpz} @@ -259,7 +259,7 @@ struct fmpz_mpoly_struct bits::flint_bitcnt_t end -const fmpz_mpoly_t = Ref{fmpz_mpoly_struct} +const fmpz_mpoly_t = Tuple{fmpz_mpoly_struct} struct fmpz_mpoly_factor_struct constant::fmpz_t @@ -270,28 +270,28 @@ struct fmpz_mpoly_factor_struct alloc::slong end -const fmpz_mpoly_factor_t = Ref{fmpz_mpoly_factor_struct} +const fmpz_mpoly_factor_t = Tuple{fmpz_mpoly_factor_struct} struct fmpz_poly_q_struct num::Ptr{fmpz_poly_struct} den::Ptr{fmpz_poly_struct} end -const fmpz_poly_q_t = Ref{fmpz_poly_q_struct} +const fmpz_poly_q_t = Tuple{fmpz_poly_q_struct} struct fmpz_mpoly_q_struct num::fmpz_mpoly_struct den::fmpz_mpoly_struct end -const fmpz_mpoly_q_t = Ref{fmpz_mpoly_q_struct} +const fmpz_mpoly_q_t = Tuple{fmpz_mpoly_q_struct} struct fmpzi_struct a::fmpz b::fmpz end -const fmpzi_t = Ref{fmpzi_struct} +const fmpzi_t = Tuple{fmpzi_struct} # end fmpz_types.h ############################################################################### @@ -307,7 +307,7 @@ struct fmpq_mat_struct rows::Ptr{Ptr{fmpq}} end -const fmpq_mat_t = Ref{fmpq_mat_struct} +const fmpq_mat_t = Tuple{fmpq_mat_struct} struct fmpq_poly_struct coeffs::Ptr{fmpz} @@ -316,14 +316,14 @@ struct fmpq_poly_struct den::fmpz_t end -const fmpq_poly_t = Ref{fmpq_poly_struct} +const fmpq_poly_t = Tuple{fmpq_poly_struct} struct fmpq_mpoly_struct content::fmpq_t zpoly::fmpz_mpoly_t end -const fmpq_mpoly_t = Ref{fmpq_mpoly_struct} +const fmpq_mpoly_t = Tuple{fmpq_mpoly_struct} struct fmpq_mpoly_factor_struct constant::fmpq_t @@ -333,7 +333,7 @@ struct fmpq_mpoly_factor_struct alloc::slong end -const fmpq_mpoly_factor_t = Ref{fmpq_mpoly_factor_struct} +const fmpq_mpoly_factor_t = Tuple{fmpq_mpoly_factor_struct} # end fmpq_types.h ############################################################################### @@ -354,11 +354,11 @@ struct fmpz_mod_ctx_struct end const struct_fmpz_mod_ctx = fmpz_mod_ctx_struct -const fmpz_mod_ctx_t = Ref{fmpz_mod_ctx_struct} +const fmpz_mod_ctx_t = Tuple{fmpz_mod_ctx_struct} const fmpz_mod_mat_struct = fmpz_mat_struct -const fmpz_mod_mat_t = Ref{fmpz_mod_mat_struct} +const fmpz_mod_mat_t = Tuple{fmpz_mod_mat_struct} struct fmpz_mod_poly_struct coeffs::Ptr{fmpz} @@ -366,7 +366,7 @@ struct fmpz_mod_poly_struct length::slong end -const fmpz_mod_poly_t = Ref{fmpz_mod_poly_struct} +const fmpz_mod_poly_t = Tuple{fmpz_mod_poly_struct} struct fmpz_mod_poly_factor_struct poly::Ptr{fmpz_mod_poly_struct} @@ -375,7 +375,7 @@ struct fmpz_mod_poly_factor_struct alloc::slong end -const fmpz_mod_poly_factor_t = Ref{fmpz_mod_poly_factor_struct} +const fmpz_mod_poly_factor_t = Tuple{fmpz_mod_poly_factor_struct} struct fmpz_mod_mpoly_struct coeffs::Ptr{fmpz} @@ -386,7 +386,7 @@ struct fmpz_mod_mpoly_struct exps_alloc::slong end -const fmpz_mod_mpoly_t = Ref{fmpz_mod_mpoly_struct} +const fmpz_mod_mpoly_t = Tuple{fmpz_mod_mpoly_struct} struct fmpz_mod_mpoly_factor_struct constant::fmpz_t @@ -396,7 +396,7 @@ struct fmpz_mod_mpoly_factor_struct alloc::slong end -const fmpz_mod_mpoly_factor_t = Ref{fmpz_mod_mpoly_factor_struct} +const fmpz_mod_mpoly_factor_t = Tuple{fmpz_mod_mpoly_factor_struct} # end fmpz_mod_types.h ############################################################################### @@ -425,7 +425,7 @@ struct fq_nmod_ctx_struct var::Ptr{Cchar} end -const fq_nmod_ctx_t = Ref{fq_nmod_ctx_struct} +const fq_nmod_ctx_t = Tuple{fq_nmod_ctx_struct} struct fq_nmod_mat_struct entries::Ptr{fq_nmod_struct} @@ -434,7 +434,7 @@ struct fq_nmod_mat_struct rows::Ptr{Ptr{fq_nmod_struct}} end -const fq_nmod_mat_t = Ref{fq_nmod_mat_struct} +const fq_nmod_mat_t = Tuple{fq_nmod_mat_struct} struct fq_nmod_poly_struct coeffs::Ptr{fq_nmod_struct} @@ -442,7 +442,7 @@ struct fq_nmod_poly_struct length::slong end -const fq_nmod_poly_t = Ref{fq_nmod_poly_struct} +const fq_nmod_poly_t = Tuple{fq_nmod_poly_struct} struct fq_nmod_poly_factor_struct poly::Ptr{fq_nmod_poly_struct} @@ -451,7 +451,7 @@ struct fq_nmod_poly_factor_struct alloc::slong end -const fq_nmod_poly_factor_t = Ref{fq_nmod_poly_factor_struct} +const fq_nmod_poly_factor_t = Tuple{fq_nmod_poly_factor_struct} struct fq_nmod_mpoly_struct coeffs::Ptr{ulong} @@ -462,7 +462,7 @@ struct fq_nmod_mpoly_struct exps_alloc::slong end -const fq_nmod_mpoly_t = Ref{fq_nmod_mpoly_struct} +const fq_nmod_mpoly_t = Tuple{fq_nmod_mpoly_struct} # end fq_nmod_types.h ############################################################################### @@ -475,7 +475,7 @@ struct fq_zech_struct value::ulong end -const fq_zech_t = Ref{fq_zech_struct} +const fq_zech_t = Tuple{fq_zech_struct} struct fq_zech_ctx_struct qm1::ulong @@ -493,7 +493,7 @@ struct fq_zech_ctx_struct is_conway::Cint end -const fq_zech_ctx_t = Ref{fq_zech_ctx_struct} +const fq_zech_ctx_t = Tuple{fq_zech_ctx_struct} struct fq_zech_mat_struct entries::Ptr{fq_zech_struct} @@ -502,7 +502,7 @@ struct fq_zech_mat_struct rows::Ptr{Ptr{fq_zech_struct}} end -const fq_zech_mat_t = Ref{fq_zech_mat_struct} +const fq_zech_mat_t = Tuple{fq_zech_mat_struct} struct fq_zech_poly_struct coeffs::Ptr{fq_zech_struct} @@ -510,7 +510,7 @@ struct fq_zech_poly_struct length::slong end -const fq_zech_poly_t = Ref{fq_zech_poly_struct} +const fq_zech_poly_t = Tuple{fq_zech_poly_struct} struct fq_zech_poly_factor_struct poly::Ptr{fq_zech_poly_struct} @@ -519,7 +519,7 @@ struct fq_zech_poly_factor_struct alloc::slong end -const fq_zech_poly_factor_t = Ref{fq_zech_poly_factor_struct} +const fq_zech_poly_factor_t = Tuple{fq_zech_poly_factor_struct} # end fq_zech_types.h ############################################################################### @@ -548,7 +548,7 @@ struct fq_ctx_struct var::Ptr{Cchar} end -const fq_ctx_t = Ref{fq_ctx_struct} +const fq_ctx_t = Tuple{fq_ctx_struct} struct fq_mat_struct entries::Ptr{fq_struct} @@ -557,7 +557,7 @@ struct fq_mat_struct rows::Ptr{Ptr{fq_struct}} end -const fq_mat_t = Ref{fq_mat_struct} +const fq_mat_t = Tuple{fq_mat_struct} struct fq_poly_struct coeffs::Ptr{fq_struct} @@ -565,7 +565,7 @@ struct fq_poly_struct length::slong end -const fq_poly_t = Ref{fq_poly_struct} +const fq_poly_t = Tuple{fq_poly_struct} struct fq_poly_factor_struct poly::Ptr{fq_poly_struct} @@ -574,7 +574,7 @@ struct fq_poly_factor_struct alloc::slong end -const fq_poly_factor_t = Ref{fq_poly_factor_struct} +const fq_poly_factor_t = Tuple{fq_poly_factor_struct} # end fq_types.h ############################################################################### @@ -604,7 +604,7 @@ struct gr_stream_struct alloc::slong end -const gr_stream_t = Ref{gr_stream_struct} +const gr_stream_t = Tuple{gr_stream_struct} const gr_funcptr = Ptr{Cvoid} @@ -618,7 +618,7 @@ struct gr_ctx_struct size_limit::ulong end -const gr_ctx_t = Ref{gr_ctx_struct} +const gr_ctx_t = Tuple{gr_ctx_struct} const gr_ptr = Ptr{Cvoid} @@ -632,7 +632,7 @@ struct gr_vec_struct length::slong end -const gr_vec_t = Ref{gr_vec_struct} +const gr_vec_t = Tuple{gr_vec_struct} struct gr_mat_struct entries::gr_ptr @@ -641,7 +641,7 @@ struct gr_mat_struct rows::Ptr{gr_ptr} end -const gr_mat_t = Ref{gr_mat_struct} +const gr_mat_t = Tuple{gr_mat_struct} struct gr_poly_struct coeffs::gr_ptr @@ -649,7 +649,7 @@ struct gr_poly_struct length::slong end -const gr_poly_t = Ref{gr_poly_struct} +const gr_poly_t = Tuple{gr_poly_struct} # end gr_types.h ############################################################################### @@ -669,21 +669,21 @@ const FQ_DEFAULT_NMOD = 4 const FQ_DEFAULT_FMPZ_MOD = 5 struct fq_default_struct - uniondata::Union{ + uniondata::NTuple{maximum(sizeof, ( fq_t, fq_nmod_t, fq_zech_t, ulong, fmpz_t, - } + )), UInt8} end const union_fq_default_struct = fq_default_struct -const fq_default_t = Ref{fq_default_struct} +const fq_default_t = Tuple{fq_default_struct} const fq_default_ctx_struct = gr_ctx_struct -const fq_default_ctx_t = Ref{fq_default_ctx_struct} +const fq_default_ctx_t = Tuple{fq_default_ctx_struct} struct _gr_fmpz_mod_ctx_struct ctx::Ptr{fmpz_mod_ctx_struct} @@ -709,7 +709,7 @@ struct padic_struct N::slong end -const padic_t = Ref{padic_struct} +const padic_t = Tuple{padic_struct} @enum enum_padic_print_mode begin PADIC_TERSE @@ -726,14 +726,14 @@ struct padic_ctx_struct mode::enum_padic_print_mode end -const padic_ctx_t = Ref{padic_ctx_struct} +const padic_ctx_t = Tuple{padic_ctx_struct} struct padic_inv_struct n::slong pow::Ptr{fmpz} end -const padic_inv_t = Ref{padic_inv_struct} +const padic_inv_t = Tuple{padic_inv_struct} struct padic_mat_struct mat::fmpz_mat_struct @@ -741,7 +741,7 @@ struct padic_mat_struct N::slong end -const padic_mat_t = Ref{padic_mat_struct} +const padic_mat_t = Tuple{padic_mat_struct} struct padic_poly_struct coeffs::Ptr{fmpz} @@ -751,7 +751,7 @@ struct padic_poly_struct N::slong end -const padic_poly_t = Ref{padic_poly_struct} +const padic_poly_t = Tuple{padic_poly_struct} # end padic_types.h ############################################################################### @@ -766,7 +766,7 @@ struct n_poly_struct length::slong end -const n_poly_t = Ref{n_poly_struct} +const n_poly_t = Tuple{n_poly_struct} const n_fq_poly_struct = n_poly_struct @@ -778,7 +778,7 @@ struct n_bpoly_struct length::slong end -const n_bpoly_t = Ref{n_bpoly_struct} +const n_bpoly_t = Tuple{n_bpoly_struct} const n_fq_bpoly_struct = n_bpoly_struct @@ -790,7 +790,7 @@ struct n_tpoly_struct length::slong end -const n_tpoly_t = Ref{n_tpoly_struct} +const n_tpoly_t = Tuple{n_tpoly_struct} const n_fq_tpoly_struct = n_tpoly_struct @@ -803,7 +803,7 @@ struct n_polyu_struct alloc::slong end -const n_polyu_t = Ref{n_polyu_struct} +const n_polyu_t = Tuple{n_polyu_struct} const n_fq_polyu_struct = n_polyu_struct @@ -816,7 +816,7 @@ struct n_polyun_struct alloc::slong end -const n_polyun_t = Ref{n_polyun_struct} +const n_polyun_t = Tuple{n_polyun_struct} const n_fq_polyun_struct = n_polyun_struct @@ -828,7 +828,7 @@ struct n_poly_stack_struct top::slong end -const n_poly_stack_t = Ref{n_poly_stack_struct} +const n_poly_stack_t = Tuple{n_poly_stack_struct} struct n_bpoly_stack_struct array::Ptr{Ptr{n_bpoly_struct}} @@ -836,14 +836,14 @@ struct n_bpoly_stack_struct top::slong end -const n_bpoly_stack_t = Ref{n_bpoly_stack_struct} +const n_bpoly_stack_t = Tuple{n_bpoly_stack_struct} struct n_poly_bpoly_stack_struct poly_stack::n_poly_stack_t bpoly_stack::n_bpoly_stack_t end -const n_poly_bpoly_stack_t = Ref{n_poly_bpoly_stack_struct} +const n_poly_bpoly_stack_t = Tuple{n_poly_bpoly_stack_struct} struct nmod_eval_interp_struct M::Ptr{ulong} @@ -856,7 +856,7 @@ struct nmod_eval_interp_struct w::ulong end -const nmod_eval_interp_t = Ref{nmod_eval_interp_struct} +const nmod_eval_interp_t = Tuple{nmod_eval_interp_struct} # end n_poly_types.h ############################################################################### @@ -885,40 +885,40 @@ struct mpoly_ctx_struct lut_fix_bits::NTuple{FLINT_BITS, Cuchar} end -const mpoly_ctx_t = Ref{mpoly_ctx_struct} +const mpoly_ctx_t = Tuple{mpoly_ctx_struct} struct nmod_mpoly_ctx_struct minfo::mpoly_ctx_t mod::nmod_t end -const nmod_mpoly_ctx_t = Ref{nmod_mpoly_ctx_struct} +const nmod_mpoly_ctx_t = Tuple{nmod_mpoly_ctx_struct} struct fmpz_mpoly_ctx_struct minfo::mpoly_ctx_t end -const fmpz_mpoly_ctx_t = Ref{fmpz_mpoly_ctx_struct} +const fmpz_mpoly_ctx_t = Tuple{fmpz_mpoly_ctx_struct} struct fmpq_mpoly_ctx_struct zctx::fmpz_mpoly_ctx_t end -const fmpq_mpoly_ctx_t = Ref{fmpq_mpoly_ctx_struct} +const fmpq_mpoly_ctx_t = Tuple{fmpq_mpoly_ctx_struct} struct fmpz_mod_mpoly_ctx_struct minfo::mpoly_ctx_t ffinfo::fmpz_mod_ctx_t end -const fmpz_mod_mpoly_ctx_t = Ref{fmpz_mod_mpoly_ctx_struct} +const fmpz_mod_mpoly_ctx_t = Tuple{fmpz_mod_mpoly_ctx_struct} struct fq_nmod_mpoly_ctx_struct minfo::mpoly_ctx_t fqctx::fq_nmod_ctx_t end -const fq_nmod_mpoly_ctx_t = Ref{fq_nmod_mpoly_ctx_struct} +const fq_nmod_mpoly_ctx_t = Tuple{fq_nmod_mpoly_ctx_struct} struct struct_mpoly_void_ring_t elem_size::slong @@ -941,7 +941,7 @@ struct struct_mpoly_void_ring_t pow_fmpz::Ptr{Cvoid} length::Ptr{Cvoid} end -const mpoly_void_ring_t = Ref{struct_mpoly_void_ring_t} +const mpoly_void_ring_t = Tuple{struct_mpoly_void_ring_t} struct mpoly_gcd_info_struct Amax_exp::Ptr{ulong} @@ -990,7 +990,7 @@ struct mpoly_gcd_info_struct data::Ptr{Cchar} end -const mpoly_gcd_info_t = Ref{mpoly_gcd_info_struct} +const mpoly_gcd_info_t = Tuple{mpoly_gcd_info_struct} struct mpoly_compression_struct mvars::slong @@ -1007,7 +1007,7 @@ struct mpoly_compression_struct is_irred::Cint end -const mpoly_compression_t = Ref{mpoly_compression_struct} +const mpoly_compression_t = Tuple{mpoly_compression_struct} struct nmod_mpolyn_struct coeffs::Ptr{n_poly_struct} @@ -1017,7 +1017,7 @@ struct nmod_mpolyn_struct bits::slong end -const nmod_mpolyn_t = Ref{nmod_mpolyn_struct} +const nmod_mpolyn_t = Tuple{nmod_mpolyn_struct} struct nmod_mpolyun_struct coeffs::Ptr{nmod_mpolyn_struct} @@ -1027,7 +1027,7 @@ struct nmod_mpolyun_struct bits::flint_bitcnt_t end -const nmod_mpolyun_t = Ref{nmod_mpolyun_struct} +const nmod_mpolyun_t = Tuple{nmod_mpolyun_struct} @enum nmod_gcds_ret_t begin nmod_gcds_success From 69899f3e13bf4662c4b08f3b8e4810474e57c148 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Fri, 31 Jan 2025 18:06:33 +0100 Subject: [PATCH 15/17] Import missing headers --- etc/FlintCTypes_template.jl | 6 ++++ src/flint/FlintCTypes.jl | 60 +++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/etc/FlintCTypes_template.jl b/etc/FlintCTypes_template.jl index a0ddbd67f..a487e327f 100644 --- a/etc/FlintCTypes_template.jl +++ b/etc/FlintCTypes_template.jl @@ -41,6 +41,12 @@ const FLINT_BITS = UInt == UInt64 ? 64 : 32 @include_c_header("fq_default.h") +@include_c_header("fq_default_mat.h") + +@include_c_header("fq_default_poly.h") + +@include_c_header("fq_default_poly_factor.h") + @include_c_header("padic_types.h") @include_c_header("n_poly_types.h") diff --git a/src/flint/FlintCTypes.jl b/src/flint/FlintCTypes.jl index e7a52839f..25a68ed0f 100644 --- a/src/flint/FlintCTypes.jl +++ b/src/flint/FlintCTypes.jl @@ -700,6 +700,66 @@ end ############################################################################### +############################################################################### +# begin fq_default_mat.h + +struct fq_default_mat_struct + uniondata::NTuple{maximum(sizeof, ( + fq_mat_t, + fq_nmod_mat_t, + fq_zech_mat_t, + nmod_mat_t, + fmpz_mod_mat_t, + )), UInt8} +end +const union_fq_default_mat_struct = fq_default_mat_struct + +const fq_default_mat_t = Tuple{fq_default_mat_struct} + +# end fq_default_mat.h +############################################################################### + + +############################################################################### +# begin fq_default_poly.h + +struct fq_default_poly_struct + uniondata::NTuple{maximum(sizeof, ( + fq_poly_t, + fq_nmod_poly_t, + fq_zech_poly_t, + nmod_poly_t, + fmpz_mod_poly_t, + )), UInt8} +end +const union_fq_default_poly_struct = fq_default_poly_struct + +const fq_default_poly_t = Tuple{fq_default_poly_struct} + +# end fq_default_poly.h +############################################################################### + + +############################################################################### +# begin fq_default_poly_factor.h + +struct fq_default_poly_factor_struct + uniondata::NTuple{maximum(sizeof, ( + fq_poly_factor_t, + fq_nmod_poly_factor_t, + fq_zech_poly_factor_t, + nmod_poly_factor_t, + fmpz_mod_poly_factor_t, + )), UInt8} +end +const union_fq_default_poly_factor_struct = fq_default_poly_factor_struct + +const fq_default_poly_factor_t = Tuple{fq_default_poly_factor_struct} + +# end fq_default_poly_factor.h +############################################################################### + + ############################################################################### # begin padic_types.h From d8ca38a77a917f9391a80e66906e4f3ee317d259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Fri, 31 Jan 2025 18:12:45 +0100 Subject: [PATCH 16/17] Make script faster --- etc/generate_FLINT_structs.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/etc/generate_FLINT_structs.jl b/etc/generate_FLINT_structs.jl index db61a25ca..5ba08dc2a 100644 --- a/etc/generate_FLINT_structs.jl +++ b/etc/generate_FLINT_structs.jl @@ -180,6 +180,7 @@ const nemopath = dirname(dirname(@__FILE__)) @info "Setting up environment" using Pkg +ENV["JULIA_PKG_PRECOMPILE_AUTO"]=0 Pkg.activate(; temp=true) Pkg.develop(PackageSpec(; path=nemopath)) Pkg.add("FLINT_jll") # version is fixed by Nemo.jl in the line above From 29471dc29bc36e03587a98121082c590122984c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Mon, 3 Feb 2025 11:28:44 +0100 Subject: [PATCH 17/17] Allow easier field access --- Project.toml | 2 + etc/FlintCTypes_template.jl | 2 + etc/generate_FLINT_structs.jl | 10 +-- src/flint/FlintCHelpers.jl | 26 ++++++ src/flint/FlintCTypes.jl | 160 +++++++++++++++++----------------- src/flint/FlintTypes.jl | 3 + 6 files changed, 119 insertions(+), 84 deletions(-) create mode 100644 src/flint/FlintCHelpers.jl diff --git a/Project.toml b/Project.toml index 8011142cf..ee7a11859 100644 --- a/Project.toml +++ b/Project.toml @@ -7,6 +7,7 @@ AbstractAlgebra = "c3fe647b-3220-5bb0-a1ea-a7954cac585d" FLINT_jll = "e134572f-a0d5-539d-bddf-3cad8db41a82" Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" RandomExtensions = "fb686558-2515-59ef-acaa-46db3789a887" SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce" @@ -17,6 +18,7 @@ AbstractAlgebra = "0.44.2" FLINT_jll = "~300.100.301" # should be "~300.200.0" Libdl = "1.6" LinearAlgebra = "1.6" +MacroTools = "0.5.15" Random = "1.6" RandomExtensions = "0.4.2" SHA = "~1.6, ~1.7, 0.7" diff --git a/etc/FlintCTypes_template.jl b/etc/FlintCTypes_template.jl index a487e327f..d6071d78d 100644 --- a/etc/FlintCTypes_template.jl +++ b/etc/FlintCTypes_template.jl @@ -6,6 +6,8 @@ module FlintC +using ..Nemo: @flintstruct, FlintStruct + # # FLINT configuration and global definitions # diff --git a/etc/generate_FLINT_structs.jl b/etc/generate_FLINT_structs.jl index 5ba08dc2a..7f65125a0 100644 --- a/etc/generate_FLINT_structs.jl +++ b/etc/generate_FLINT_structs.jl @@ -42,11 +42,11 @@ const regex_typedef_union_unionname_values_name = r"^typedef union *([A-Za-z0-9_ function convert_struct(str::AbstractString) substitutions = Pair{Regex,Union{SubstitutionString,Function}}[ - regex_typedef_struct_fields_name => s"struct \2\1end", # whole typedef struct construct - regex_struct_structname_fields => s"struct struct_\1\2end", # whole struct construct - regex_struct_structname => s"struct struct_\1 end", # whole struct construct without fields - regex_typedef_struct_fields_refname => s"struct struct_\2\1end\nconst \2 = Tuple{struct_\2}", # whole typedef struct singleton array construct - regex_typedef_struct_structname_fields_name => s"struct \3\2end\nconst struct_\1 = \3", # whole typedef struct construct with two names + regex_typedef_struct_fields_name => s"@flintstruct struct \2\1end", # whole typedef struct construct + regex_struct_structname_fields => s"@flintstruct struct struct_\1\2end", # whole struct construct + regex_struct_structname => s"@flintstruct struct struct_\1 end", # whole struct construct without fields + regex_typedef_struct_fields_refname => s"@flintstruct struct struct_\2\1end\nconst \2 = Tuple{struct_\2}", # whole typedef struct singleton array construct + regex_typedef_struct_structname_fields_name => s"@flintstruct struct \3\2end\nconst struct_\1 = \3", # whole typedef struct construct with two names r"^ +([A-Za-z0-9_]+) +([A-Za-z0-9_]+);"m => s" \2::\1", # simple fields (one to five declared on one line) r"^ +([A-Za-z0-9_]+) +([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+);"m => s" \2::\1\n \3::\1", r"^ +([A-Za-z0-9_]+) +([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+) *, *([A-Za-z0-9_]+);"m => s" \2::\1\n \3::\1\n \4::\1", diff --git a/src/flint/FlintCHelpers.jl b/src/flint/FlintCHelpers.jl new file mode 100644 index 000000000..10fcb285e --- /dev/null +++ b/src/flint/FlintCHelpers.jl @@ -0,0 +1,26 @@ +import MacroTools + +abstract type FlintStruct end + +function Base.getproperty(val::FlintStruct, name::Symbol) + if fieldtype(typeof(val), name) <: Tuple{T} where T # unwrap singleton tuples + return only(getfield(val, name)) + else + getfield(val, name) + end +end + +macro flintstruct(structdef::Expr) + structprops = MacroTools.splitstructdef(structdef) + @assert !structprops[:mutable] + @assert isempty(structprops[:params]) + @assert structprops[:supertype] == :Any + + @show structprops + + structprops[:supertype] = :(FlintStruct) + + return esc(quote + $(MacroTools.combinestructdef(structprops)) + end) +end diff --git a/src/flint/FlintCTypes.jl b/src/flint/FlintCTypes.jl index 25a68ed0f..db2c09602 100644 --- a/src/flint/FlintCTypes.jl +++ b/src/flint/FlintCTypes.jl @@ -11,6 +11,8 @@ module FlintC +using ..Nemo: @flintstruct, FlintStruct + # # FLINT configuration and global definitions # @@ -33,7 +35,7 @@ const __FLINT_VERSION_MINOR = 2 const __FLINT_VERSION_PATCHLEVEL = 0 -struct struct___FLINT_FILE end +@flintstruct struct struct___FLINT_FILE end const FLINT_FILE = struct___FLINT_FILE @@ -47,7 +49,7 @@ const flint_cleanup_function_t = Ptr{Cvoid} const thread_pool_handle = Cint -struct flint_rand_struct +@flintstruct struct flint_rand_struct __gmp_state::Ptr{Cvoid} __randval::ulong __randval2::ulong @@ -66,7 +68,7 @@ const flint_rand_t = Tuple{flint_rand_struct} FLINT_TEST_FAIL end -struct nmod_t +@flintstruct struct nmod_t n::ulong ninv::ulong norm::flint_bitcnt_t @@ -76,7 +78,7 @@ const fmpz = slong const fmpz_t = Tuple{fmpz} -struct fmpq +@flintstruct struct fmpq num::fmpz den::fmpz end @@ -94,13 +96,13 @@ const MPZ_MIN_ALLOC = 2 const FLINT_MAX_FACTORS_IN_LIMB = 15 -struct n_factor_t +@flintstruct struct n_factor_t num::Cint exp::NTuple{FLINT_MAX_FACTORS_IN_LIMB, Cint} p::NTuple{FLINT_MAX_FACTORS_IN_LIMB, ulong} end -struct n_primes_struct +@flintstruct struct n_primes_struct small_i::slong small_num::slong small_primes::Ptr{Cuint} @@ -121,7 +123,7 @@ const n_primes_t = Tuple{n_primes_struct} ############################################################################### # begin nmod_types.h -struct nmod_mat_struct +@flintstruct struct nmod_mat_struct entries::Ptr{ulong} r::slong c::slong @@ -131,7 +133,7 @@ end const nmod_mat_t = Tuple{nmod_mat_struct} -struct nmod_poly_struct +@flintstruct struct nmod_poly_struct coeffs::nn_ptr alloc::slong length::slong @@ -140,7 +142,7 @@ end const nmod_poly_t = Tuple{nmod_poly_struct} -struct nmod_poly_factor_struct +@flintstruct struct nmod_poly_factor_struct p::Ptr{nmod_poly_struct} exp::Ptr{slong} num::slong @@ -149,7 +151,7 @@ end const nmod_poly_factor_t = Tuple{nmod_poly_factor_struct} -struct nmod_poly_mat_struct +@flintstruct struct nmod_poly_mat_struct entries::Ptr{nmod_poly_struct} r::slong c::slong @@ -159,7 +161,7 @@ end const nmod_poly_mat_t = Tuple{nmod_poly_mat_struct} -struct nmod_mpoly_struct +@flintstruct struct nmod_mpoly_struct coeffs::Ptr{ulong} exps::Ptr{ulong} length::slong @@ -170,7 +172,7 @@ end const nmod_mpoly_t = Tuple{nmod_mpoly_struct} -struct nmod_mpoly_factor_struct +@flintstruct struct nmod_mpoly_factor_struct constant::ulong poly::Ptr{nmod_mpoly_struct} exp::Ptr{fmpz} @@ -187,7 +189,7 @@ const nmod_mpoly_factor_t = Tuple{nmod_mpoly_factor_struct} ############################################################################### # begin fmpz_types.h -struct zz_struct +@flintstruct struct zz_struct alloc::Cint size::Cint ptr::nn_ptr @@ -197,7 +199,7 @@ const zz_ptr = Ptr{zz_struct} const zz_srcptr = Ptr{zz_struct} -struct fmpz_factor_struct +@flintstruct struct fmpz_factor_struct sign::Cint p::Ptr{fmpz} exp::Ptr{ulong} @@ -207,7 +209,7 @@ end const fmpz_factor_t = Tuple{fmpz_factor_struct} -struct fmpz_preinvn_struct +@flintstruct struct fmpz_preinvn_struct dinv::nn_ptr n::slong norm::flint_bitcnt_t @@ -215,7 +217,7 @@ end const fmpz_preinvn_t = Tuple{fmpz_preinvn_struct} -struct fmpz_poly_struct +@flintstruct struct fmpz_poly_struct coeffs::Ptr{fmpz} alloc::slong length::slong @@ -223,7 +225,7 @@ end const fmpz_poly_t = Tuple{fmpz_poly_struct} -struct fmpz_poly_factor_struct +@flintstruct struct fmpz_poly_factor_struct c::fmpz p::Ptr{fmpz_poly_struct} exp::Ptr{slong} @@ -233,7 +235,7 @@ end const fmpz_poly_factor_t = Tuple{fmpz_poly_factor_struct} -struct fmpz_mat_struct +@flintstruct struct fmpz_mat_struct entries::Ptr{fmpz} r::slong c::slong @@ -242,7 +244,7 @@ end const fmpz_mat_t = Tuple{fmpz_mat_struct} -struct fmpz_poly_mat_struct +@flintstruct struct fmpz_poly_mat_struct entries::Ptr{fmpz_poly_struct} r::slong c::slong @@ -251,7 +253,7 @@ end const fmpz_poly_mat_t = Tuple{fmpz_poly_mat_struct} -struct fmpz_mpoly_struct +@flintstruct struct fmpz_mpoly_struct coeffs::Ptr{fmpz} exps::Ptr{ulong} alloc::slong @@ -261,7 +263,7 @@ end const fmpz_mpoly_t = Tuple{fmpz_mpoly_struct} -struct fmpz_mpoly_factor_struct +@flintstruct struct fmpz_mpoly_factor_struct constant::fmpz_t constant_den::fmpz_t poly::Ptr{fmpz_mpoly_struct} @@ -272,21 +274,21 @@ end const fmpz_mpoly_factor_t = Tuple{fmpz_mpoly_factor_struct} -struct fmpz_poly_q_struct +@flintstruct struct fmpz_poly_q_struct num::Ptr{fmpz_poly_struct} den::Ptr{fmpz_poly_struct} end const fmpz_poly_q_t = Tuple{fmpz_poly_q_struct} -struct fmpz_mpoly_q_struct +@flintstruct struct fmpz_mpoly_q_struct num::fmpz_mpoly_struct den::fmpz_mpoly_struct end const fmpz_mpoly_q_t = Tuple{fmpz_mpoly_q_struct} -struct fmpzi_struct +@flintstruct struct fmpzi_struct a::fmpz b::fmpz end @@ -300,7 +302,7 @@ const fmpzi_t = Tuple{fmpzi_struct} ############################################################################### # begin fmpq_types.h -struct fmpq_mat_struct +@flintstruct struct fmpq_mat_struct entries::Ptr{fmpq} r::slong c::slong @@ -309,7 +311,7 @@ end const fmpq_mat_t = Tuple{fmpq_mat_struct} -struct fmpq_poly_struct +@flintstruct struct fmpq_poly_struct coeffs::Ptr{fmpz} alloc::slong length::slong @@ -318,14 +320,14 @@ end const fmpq_poly_t = Tuple{fmpq_poly_struct} -struct fmpq_mpoly_struct +@flintstruct struct fmpq_mpoly_struct content::fmpq_t zpoly::fmpz_mpoly_t end const fmpq_mpoly_t = Tuple{fmpq_mpoly_struct} -struct fmpq_mpoly_factor_struct +@flintstruct struct fmpq_mpoly_factor_struct constant::fmpq_t poly::Ptr{fmpq_mpoly_struct} exp::Ptr{fmpz} @@ -342,7 +344,7 @@ const fmpq_mpoly_factor_t = Tuple{fmpq_mpoly_factor_struct} ############################################################################### # begin fmpz_mod_types.h -struct fmpz_mod_ctx_struct +@flintstruct struct fmpz_mod_ctx_struct n::fmpz_t add_fxn::Ptr{Cvoid} sub_fxn::Ptr{Cvoid} @@ -360,7 +362,7 @@ const fmpz_mod_mat_struct = fmpz_mat_struct const fmpz_mod_mat_t = Tuple{fmpz_mod_mat_struct} -struct fmpz_mod_poly_struct +@flintstruct struct fmpz_mod_poly_struct coeffs::Ptr{fmpz} alloc::slong length::slong @@ -368,7 +370,7 @@ end const fmpz_mod_poly_t = Tuple{fmpz_mod_poly_struct} -struct fmpz_mod_poly_factor_struct +@flintstruct struct fmpz_mod_poly_factor_struct poly::Ptr{fmpz_mod_poly_struct} exp::Ptr{slong} num::slong @@ -377,7 +379,7 @@ end const fmpz_mod_poly_factor_t = Tuple{fmpz_mod_poly_factor_struct} -struct fmpz_mod_mpoly_struct +@flintstruct struct fmpz_mod_mpoly_struct coeffs::Ptr{fmpz} exps::Ptr{ulong} length::slong @@ -388,7 +390,7 @@ end const fmpz_mod_mpoly_t = Tuple{fmpz_mod_mpoly_struct} -struct fmpz_mod_mpoly_factor_struct +@flintstruct struct fmpz_mod_mpoly_factor_struct constant::fmpz_t poly::Ptr{fmpz_mod_mpoly_struct} exp::Ptr{fmpz} @@ -409,7 +411,7 @@ const fq_nmod_t = nmod_poly_t const fq_nmod_struct = nmod_poly_struct -struct fq_nmod_ctx_struct +@flintstruct struct fq_nmod_ctx_struct mod::nmod_t sparse_modulus::Cint @@ -427,7 +429,7 @@ end const fq_nmod_ctx_t = Tuple{fq_nmod_ctx_struct} -struct fq_nmod_mat_struct +@flintstruct struct fq_nmod_mat_struct entries::Ptr{fq_nmod_struct} r::slong c::slong @@ -436,7 +438,7 @@ end const fq_nmod_mat_t = Tuple{fq_nmod_mat_struct} -struct fq_nmod_poly_struct +@flintstruct struct fq_nmod_poly_struct coeffs::Ptr{fq_nmod_struct} alloc::slong length::slong @@ -444,7 +446,7 @@ end const fq_nmod_poly_t = Tuple{fq_nmod_poly_struct} -struct fq_nmod_poly_factor_struct +@flintstruct struct fq_nmod_poly_factor_struct poly::Ptr{fq_nmod_poly_struct} exp::Ptr{slong} num::slong @@ -453,7 +455,7 @@ end const fq_nmod_poly_factor_t = Tuple{fq_nmod_poly_factor_struct} -struct fq_nmod_mpoly_struct +@flintstruct struct fq_nmod_mpoly_struct coeffs::Ptr{ulong} exps::Ptr{ulong} length::slong @@ -471,13 +473,13 @@ const fq_nmod_mpoly_t = Tuple{fq_nmod_mpoly_struct} ############################################################################### # begin fq_zech_types.h -struct fq_zech_struct +@flintstruct struct fq_zech_struct value::ulong end const fq_zech_t = Tuple{fq_zech_struct} -struct fq_zech_ctx_struct +@flintstruct struct fq_zech_ctx_struct qm1::ulong qm1o2::ulong qm1opm1::ulong @@ -495,7 +497,7 @@ end const fq_zech_ctx_t = Tuple{fq_zech_ctx_struct} -struct fq_zech_mat_struct +@flintstruct struct fq_zech_mat_struct entries::Ptr{fq_zech_struct} r::slong c::slong @@ -504,7 +506,7 @@ end const fq_zech_mat_t = Tuple{fq_zech_mat_struct} -struct fq_zech_poly_struct +@flintstruct struct fq_zech_poly_struct coeffs::Ptr{fq_zech_struct} alloc::slong length::slong @@ -512,7 +514,7 @@ end const fq_zech_poly_t = Tuple{fq_zech_poly_struct} -struct fq_zech_poly_factor_struct +@flintstruct struct fq_zech_poly_factor_struct poly::Ptr{fq_zech_poly_struct} exp::Ptr{slong} num::slong @@ -532,7 +534,7 @@ const fq_t = fmpz_poly_t const fq_struct = fmpz_poly_struct -struct fq_ctx_struct +@flintstruct struct fq_ctx_struct ctxp::fmpz_mod_ctx_t sparse_modulus::Cint @@ -550,7 +552,7 @@ end const fq_ctx_t = Tuple{fq_ctx_struct} -struct fq_mat_struct +@flintstruct struct fq_mat_struct entries::Ptr{fq_struct} r::slong c::slong @@ -559,7 +561,7 @@ end const fq_mat_t = Tuple{fq_mat_struct} -struct fq_poly_struct +@flintstruct struct fq_poly_struct coeffs::Ptr{fq_struct} alloc::slong length::slong @@ -567,7 +569,7 @@ end const fq_poly_t = Tuple{fq_poly_struct} -struct fq_poly_factor_struct +@flintstruct struct fq_poly_factor_struct poly::Ptr{fq_poly_struct} exp::Ptr{slong} num::slong @@ -597,7 +599,7 @@ const GR_TEST_FAIL = 4 T_UNKNOWN end -struct gr_stream_struct +@flintstruct struct gr_stream_struct fp::Ptr{FLINT_FILE} s::Ptr{Cchar} len::slong @@ -610,7 +612,7 @@ const gr_funcptr = Ptr{Cvoid} const GR_CTX_STRUCT_DATA_BYTES = 6 * sizeof(ulong) -struct gr_ctx_struct +@flintstruct struct gr_ctx_struct data::NTuple{GR_CTX_STRUCT_DATA_BYTES, Cchar} which_ring::ulong sizeof_elem::slong @@ -626,7 +628,7 @@ const gr_srcptr = Ptr{Cvoid} const gr_ctx_ptr = Ptr{Cvoid} -struct gr_vec_struct +@flintstruct struct gr_vec_struct entries::gr_ptr alloc::slong length::slong @@ -634,7 +636,7 @@ end const gr_vec_t = Tuple{gr_vec_struct} -struct gr_mat_struct +@flintstruct struct gr_mat_struct entries::gr_ptr r::slong c::slong @@ -643,7 +645,7 @@ end const gr_mat_t = Tuple{gr_mat_struct} -struct gr_poly_struct +@flintstruct struct gr_poly_struct coeffs::gr_ptr alloc::slong length::slong @@ -685,13 +687,13 @@ const fq_default_ctx_struct = gr_ctx_struct const fq_default_ctx_t = Tuple{fq_default_ctx_struct} -struct _gr_fmpz_mod_ctx_struct +@flintstruct struct _gr_fmpz_mod_ctx_struct ctx::Ptr{fmpz_mod_ctx_struct} is_prime::truth_t a::fmpz end -struct _gr_nmod_ctx_struct +@flintstruct struct _gr_nmod_ctx_struct nmod::nmod_t a::ulong end @@ -763,7 +765,7 @@ const fq_default_poly_factor_t = Tuple{fq_default_poly_factor_struct} ############################################################################### # begin padic_types.h -struct padic_struct +@flintstruct struct padic_struct u::fmpz v::slong N::slong @@ -777,7 +779,7 @@ const padic_t = Tuple{padic_struct} PADIC_VAL_UNIT end -struct padic_ctx_struct +@flintstruct struct padic_ctx_struct p::fmpz_t pinv::Cdouble pow::Ptr{fmpz} @@ -788,14 +790,14 @@ end const padic_ctx_t = Tuple{padic_ctx_struct} -struct padic_inv_struct +@flintstruct struct padic_inv_struct n::slong pow::Ptr{fmpz} end const padic_inv_t = Tuple{padic_inv_struct} -struct padic_mat_struct +@flintstruct struct padic_mat_struct mat::fmpz_mat_struct val::slong N::slong @@ -803,7 +805,7 @@ end const padic_mat_t = Tuple{padic_mat_struct} -struct padic_poly_struct +@flintstruct struct padic_poly_struct coeffs::Ptr{fmpz} alloc::slong length::slong @@ -820,7 +822,7 @@ const padic_poly_t = Tuple{padic_poly_struct} ############################################################################### # begin n_poly_types.h -struct n_poly_struct +@flintstruct struct n_poly_struct coeffs::Ptr{ulong} alloc::slong length::slong @@ -832,7 +834,7 @@ const n_fq_poly_struct = n_poly_struct const n_fq_poly_t = n_poly_t -struct n_bpoly_struct +@flintstruct struct n_bpoly_struct coeffs::Ptr{n_poly_struct} alloc::slong length::slong @@ -844,7 +846,7 @@ const n_fq_bpoly_struct = n_bpoly_struct const n_fq_bpoly_t = n_bpoly_t -struct n_tpoly_struct +@flintstruct struct n_tpoly_struct coeffs::Ptr{n_bpoly_struct} alloc::slong length::slong @@ -856,7 +858,7 @@ const n_fq_tpoly_struct = n_tpoly_struct const n_fq_tpoly_t = n_tpoly_t -struct n_polyu_struct +@flintstruct struct n_polyu_struct exps::Ptr{ulong} coeffs::Ptr{ulong} length::slong @@ -869,7 +871,7 @@ const n_fq_polyu_struct = n_polyu_struct const n_fq_polyu_t = n_polyu_t -struct n_polyun_struct +@flintstruct struct n_polyun_struct coeffs::Ptr{n_poly_struct} exps::Ptr{ulong} length::slong @@ -882,7 +884,7 @@ const n_fq_polyun_struct = n_polyun_struct const n_fq_polyun_t = n_polyun_t -struct n_poly_stack_struct +@flintstruct struct n_poly_stack_struct array::Ptr{Ptr{n_poly_struct}} alloc::slong top::slong @@ -890,7 +892,7 @@ end const n_poly_stack_t = Tuple{n_poly_stack_struct} -struct n_bpoly_stack_struct +@flintstruct struct n_bpoly_stack_struct array::Ptr{Ptr{n_bpoly_struct}} alloc::slong top::slong @@ -898,14 +900,14 @@ end const n_bpoly_stack_t = Tuple{n_bpoly_stack_struct} -struct n_poly_bpoly_stack_struct +@flintstruct struct n_poly_bpoly_stack_struct poly_stack::n_poly_stack_t bpoly_stack::n_bpoly_stack_t end const n_poly_bpoly_stack_t = Tuple{n_poly_bpoly_stack_struct} -struct nmod_eval_interp_struct +@flintstruct struct nmod_eval_interp_struct M::Ptr{ulong} T::Ptr{ulong} Q::Ptr{ulong} @@ -935,7 +937,7 @@ end const MPOLY_NUM_ORDERINGS = 3 -struct mpoly_ctx_struct +@flintstruct struct mpoly_ctx_struct nvars::slong nfields::slong ord::ordering_t @@ -947,40 +949,40 @@ end const mpoly_ctx_t = Tuple{mpoly_ctx_struct} -struct nmod_mpoly_ctx_struct +@flintstruct struct nmod_mpoly_ctx_struct minfo::mpoly_ctx_t mod::nmod_t end const nmod_mpoly_ctx_t = Tuple{nmod_mpoly_ctx_struct} -struct fmpz_mpoly_ctx_struct +@flintstruct struct fmpz_mpoly_ctx_struct minfo::mpoly_ctx_t end const fmpz_mpoly_ctx_t = Tuple{fmpz_mpoly_ctx_struct} -struct fmpq_mpoly_ctx_struct +@flintstruct struct fmpq_mpoly_ctx_struct zctx::fmpz_mpoly_ctx_t end const fmpq_mpoly_ctx_t = Tuple{fmpq_mpoly_ctx_struct} -struct fmpz_mod_mpoly_ctx_struct +@flintstruct struct fmpz_mod_mpoly_ctx_struct minfo::mpoly_ctx_t ffinfo::fmpz_mod_ctx_t end const fmpz_mod_mpoly_ctx_t = Tuple{fmpz_mod_mpoly_ctx_struct} -struct fq_nmod_mpoly_ctx_struct +@flintstruct struct fq_nmod_mpoly_ctx_struct minfo::mpoly_ctx_t fqctx::fq_nmod_ctx_t end const fq_nmod_mpoly_ctx_t = Tuple{fq_nmod_mpoly_ctx_struct} -struct struct_mpoly_void_ring_t +@flintstruct struct struct_mpoly_void_ring_t elem_size::slong ctx::Ptr{Cvoid} init::Ptr{Cvoid} @@ -1003,7 +1005,7 @@ struct struct_mpoly_void_ring_t end const mpoly_void_ring_t = Tuple{struct_mpoly_void_ring_t} -struct mpoly_gcd_info_struct +@flintstruct struct mpoly_gcd_info_struct Amax_exp::Ptr{ulong} Amin_exp::Ptr{ulong} Astride::Ptr{ulong} @@ -1052,7 +1054,7 @@ end const mpoly_gcd_info_t = Tuple{mpoly_gcd_info_struct} -struct mpoly_compression_struct +@flintstruct struct mpoly_compression_struct mvars::slong nvars::slong exps::Ptr{slong} @@ -1069,7 +1071,7 @@ end const mpoly_compression_t = Tuple{mpoly_compression_struct} -struct nmod_mpolyn_struct +@flintstruct struct nmod_mpolyn_struct coeffs::Ptr{n_poly_struct} exps::Ptr{ulong} alloc::slong @@ -1079,7 +1081,7 @@ end const nmod_mpolyn_t = Tuple{nmod_mpolyn_struct} -struct nmod_mpolyun_struct +@flintstruct struct nmod_mpolyun_struct coeffs::Ptr{nmod_mpolyn_struct} exps::Ptr{ulong} alloc::slong diff --git a/src/flint/FlintTypes.jl b/src/flint/FlintTypes.jl index fbc972a79..2c0b4ab33 100644 --- a/src/flint/FlintTypes.jl +++ b/src/flint/FlintTypes.jl @@ -4,6 +4,9 @@ # ############################################################################### +include("FlintCHelpers.jl") +include("FlintCTypes.jl") + const _err_dim_negative = ErrorException("Dimensions must be non-negative") ###############################################################################