Skip to content

Commit

Permalink
WIP: rewrite gap_to_julia
Browse files Browse the repository at this point in the history
TODO:
- add more test cases esp. for the various fixes
  e.g. converting the same (identical) objects to multiple
  output types should be working correctly now
- identify issues this patch resolves
- update docs
- ...
  • Loading branch information
fingolfin committed Sep 22, 2023
1 parent 6bafdba commit ea7e465
Show file tree
Hide file tree
Showing 7 changed files with 415 additions and 214 deletions.
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

0 comments on commit ea7e465

Please sign in to comment.