Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: rewrite gap_to_julia #777

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
## Version X.Y.Z-DEV (released YYYY-MM-DD)

- Rewrite `gap_to_julia` to improve performance, fix bugs in many corner
cases, and make it easier to extend it correctly in other packages. The
target type of conversions now must be either ...
- `Any` (in which case we try to "guess" a suitable result type),
- or a supertype of the given object (in which case the input is returned unmodified),
- or else a concrete type (and this will then be the type of the result).

Thus e.g. `GAP.gap_to_julia(AbstractString, x)` no longer
works if `x` is a GAP string object; use `GAP.gap_to_julia(String, x)`
instead.
To extend the GAP-to-Julia conversion code, you should provide a method
`gap_to_julia_intern(type::YourType, input::Any, recursive::Bool, dict::GapToJuliaDict)`
TODO: .. consult the documentation in location TODO

# Changes in GAP.jl

## Version 0.9.8 (released 2023-09-11)
Expand Down
4 changes: 2 additions & 2 deletions pkg/JuliaInterface/tst/convert.tst
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ gap> Julia.GAP.Obj( xx );

## empty record
gap> dict:= GAPToJulia( rec() );
<Julia: Dict{Symbol,Any}()>
<Julia: Dict{Symbol, Any}()>
gap> JuliaToGAP( IsRecord, dict );
rec( )
gap> Julia.GAP.Obj( dict );
Expand All @@ -278,7 +278,7 @@ rec( bool := true, list := [ 1, 2, 3 ], string := "abc" )
## something where recursive conversion would run into a Julia error
gap> dict:= GAPToJulia( rec( juliafunc:= Julia.Base.map,
> ) );
<Julia: Dict{Symbol,Any}(:juliafunc=>map)>
<Julia: Dict{Symbol, Any}(:juliafunc => map)>
gap> JuliaToGAP( IsRecord, dict );
rec( juliafunc := <Julia: map> )
gap> Julia.GAP.Obj( dict );
Expand Down
6 changes: 3 additions & 3 deletions src/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ function BitVector(obj::GapObj)
!Wrappers.IsBlist(obj) && throw(ConversionError(obj, BitVector))
# TODO: a much better conversion would be possible, at least if `obj` is
# in IsBlistRep, then we could essentially memcpy data
len = Wrappers.Length(obj)
len = length(obj)
result = BitVector(undef, len)
for i = 1:len
result[i] = obj[i]
Expand Down Expand Up @@ -465,7 +465,7 @@ julia> UnitRange{Int32}(val)

function (::Type{T})(obj::GapObj) where {T<:UnitRange}
!Wrappers.IsRange(obj) && throw(ConversionError(obj, T))
len = Wrappers.Length(obj)
len = length(obj)
if len == 0
# construct an empty UnitRange object
result = 1:0
Expand Down Expand Up @@ -506,7 +506,7 @@ StepRange{Int8, Int8}

function(::Type{T})(obj::GapObj) where {T<:StepRange}
!Wrappers.IsRange(obj) && throw(ConversionError(obj, T))
len = Wrappers.Length(obj)
len = length(obj)
if len == 0
# construct an empty StepRange object
start = 1
Expand Down
Loading
Loading