diff --git a/.travis.yml b/.travis.yml index b3eb40f..1e9eea5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ os: - linux - osx julia: - - 0.4 - 0.5 - nightly notifications: diff --git a/REQUIRE b/REQUIRE index c428d79..41080fc 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,6 +1,6 @@ -julia 0.4 +julia 0.5 DataFrames 0.7 DataArrays 0.3 FileIO 0.1.2 GZip 0.2 -Compat 0.8 +Compat 0.17 diff --git a/appveyor.yml b/appveyor.yml index 9f9f3f0..a8faed8 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,7 +1,5 @@ environment: matrix: - - JULIAVERSION: "julialang/bin/winnt/x86/0.4/julia-0.4-latest-win32.exe" - - JULIAVERSION: "julialang/bin/winnt/x64/0.4/julia-0.4-latest-win64.exe" - JULIAVERSION: "julialang/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe" - JULIAVERSION: "julialang/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe" - JULIAVERSION: "julianightlies/bin/winnt/x86/julia-latest-win32.exe" diff --git a/src/RData.jl b/src/RData.jl index bf4f97e..1dd7a42 100644 --- a/src/RData.jl +++ b/src/RData.jl @@ -5,7 +5,7 @@ module RData using Compat, DataFrames, GZip, FileIO import DataArrays: data import DataFrames: identifier -import Compat: UTF8String, unsafe_string +import Compat: unsafe_string import FileIO: load export @@ -19,7 +19,7 @@ include("sxtypes.jl") """ Abstract RDA format IO stream wrapper. """ -abstract RDAIO +@compat abstract type RDAIO end include("io/XDRIO.jl") include("io/ASCIIIO.jl") diff --git a/src/config.jl b/src/config.jl index be42569..550be65 100644 --- a/src/config.jl +++ b/src/config.jl @@ -30,14 +30,10 @@ const R_NA_STRING = "NA" const LONG_VECTOR_SUPPORT = (Sys.WORD_SIZE > 32) # disable long vectors support on 32-bit machines -if LONG_VECTOR_SUPPORT - typealias RVecLength Int64 -else - typealias RVecLength Int -end +const RVecLength = LONG_VECTOR_SUPPORT ? Int64 : Int -typealias RString UTF8String # default String container for R string -typealias Hash Dict{RString, Any} +const RString = String # default String container for R string +const Hash = Dict{RString, Any} const emptyhash = Hash() const emptyhashkey = RString("\0") diff --git a/src/context.jl b/src/context.jl index b49db79..d655671 100644 --- a/src/context.jl +++ b/src/context.jl @@ -1,12 +1,10 @@ """ RDA (R data archive) reading context. - * Stores flags that define how R objects are read and converted - into Julia objects. - * Maintains the list of R objects that could be referenced later in - the RDA stream. +* Stores flags that define how R objects are read and converted into Julia objects. +* Maintains the list of R objects that could be referenced later in the RDA stream. """ -type RDAContext{T <: RDAIO} +type RDAContext{T<:RDAIO} io::T # RDA input stream # RDA format properties @@ -18,22 +16,15 @@ type RDAContext{T <: RDAIO} # intermediate data ref_tab::Vector{RSEXPREC} # SEXP array for references - - function RDAContext(io::T, kwoptions::Vector{Any}) - fmtver = readint32(io) - rver = readint32(io) - rminver = readint32(io) - kwdict = Dict{Symbol,Any}(kwoptions) - new(io, - fmtver, - VersionNumber(div(rver,65536), div(rver%65536, 256), rver%256), - VersionNumber(div(rminver,65536), div(rminver%65536, 256), rminver%256), - kwdict, - RSEXPREC[]) - end end - -RDAContext{T <: RDAIO}(io::T, kwoptions::Vector{Any}) = RDAContext{T}(io, kwoptions) +int2ver(v::Integer) = VersionNumber(v >> 16, (v >> 8) & 0xff, v & 0xff) +function RDAContext{T<:RDAIO}(io::T, kwoptions::Vector{Any}=Any[]) + fmtver = readuint32(io) + rver = int2ver(readint32(io)) + rminver = int2ver(readint32(io)) + kwdict = Dict{Symbol,Any}(kwoptions) + RDAContext(io, fmtver, rver, rminver, kwdict, RSEXPREC[]) +end """ Registers R object, so that it could be referenced later diff --git a/src/io/ASCIIIO.jl b/src/io/ASCIIIO.jl index c2c2336..37a621d 100644 --- a/src/io/ASCIIIO.jl +++ b/src/io/ASCIIIO.jl @@ -4,8 +4,7 @@ type ASCIIIO{T<:IO} <: RDAIO sub::T # underlying IO stream - ASCIIIO(io::T) = new(io) - @compat (::Type{ASCIIIO}){T<:IO}(io::T) = new{T}(io) + (::Type{ASCIIIO}){T<:IO}(io::T) = new{T}(io) end readint32(io::ASCIIIO) = parse(Int32, readline(io.sub)) diff --git a/src/io/NativeIO.jl b/src/io/NativeIO.jl index e3d892c..fa95e1e 100644 --- a/src/io/NativeIO.jl +++ b/src/io/NativeIO.jl @@ -5,7 +5,5 @@ """ type NativeIO{T<:IO} <: RDAIO sub::T # underlying IO stream - - NativeIO(io::T) = new(io) - @compat (::Type{NativeIO}){T<:IO}(io::T) = new{T}(io) + (::Type{NativeIO}){T<:IO}(io::T) = new{T}(io) end diff --git a/src/io/XDRIO.jl b/src/io/XDRIO.jl index d6ed2d8..48ba09a 100644 --- a/src/io/XDRIO.jl +++ b/src/io/XDRIO.jl @@ -4,17 +4,15 @@ type XDRIO{T<:IO} <: RDAIO sub::T # underlying IO stream buf::Vector{UInt8} # buffer for strings - - XDRIO(io::T) = new(io, Array(UInt8, 1024)) - @compat (::Type{XDRIO}){T <: IO}(io::T) = new{T}(io, Array(UInt8, 1024)) + @compat (::Type{XDRIO}){T <: IO}(io::T) = new{T}(io, Vector{UInt8}(1024)) end readint32(io::XDRIO) = ntoh(read(io.sub, Int32)) readuint32(io::XDRIO) = ntoh(read(io.sub, UInt32)) -readfloat64(io::XDRIO) = ntoh(read(io.sub, Float64)) +readfloat64(io::XDRIO) = reinterpret(Float64, ntoh(read(io.sub, Int64))) readintorNA(io::XDRIO) = readint32(io) -function readintorNA(io::XDRIO, n::RVecLength) +function readintorNA(io::XDRIO, n::RVecLength) v = read(io.sub, Int32, n) map!(ntoh, v, v) end @@ -22,7 +20,6 @@ end # this method have Win32 ABI issues, see JuliaStats/RData.jl#5 # R's NA is silently converted to NaN when the value is loaded in the register(?) #readfloatorNA(io::XDRIO) = readfloat64(io) - function readfloatorNA(io::XDRIO, n::RVecLength) v = read(io.sub, UInt64, n) reinterpret(Float64, map!(ntoh, v, v)) diff --git a/src/readers.jl b/src/readers.jl index 717275f..77ca0b6 100644 --- a/src/readers.jl +++ b/src/readers.jl @@ -184,7 +184,7 @@ immutable BytecodeContext ctx::RDAContext # parent RDA context ref_tab::Vector{Any} # table of bytecode references - BytecodeContext(ctx::RDAContext, nrefs::Int32) = new(ctx, Array(Any, Int(nrefs))) + BytecodeContext(ctx::RDAContext, nrefs::Int32) = new(ctx, Vector{Any}(Int(nrefs))) end const BYTECODELANG_Types = Set([BCREPREF, BCREPDEF, LANGSXP, LISTSXP, ATTRLANGSXP, ATTRLISTSXP]) @@ -254,7 +254,7 @@ end Definition of R type. """ immutable SXTypeInfo - name::UTF8String # R type name + name::String # R type name reader::Function # function to deserialize R type from RDA stream end diff --git a/src/sxtypes.jl b/src/sxtypes.jl index 999e211..7bb3fb0 100644 --- a/src/sxtypes.jl +++ b/src/sxtypes.jl @@ -68,7 +68,7 @@ const ATTRLISTSXP = 0xEF ## ############################################################################## -typealias RDATag UInt32 +const RDATag = UInt32 isobj(fl::RDATag) = (fl & 0x00000100) != 0 hasattr(fl::RDATag) = (fl & 0x00000200) != 0 @@ -85,7 +85,7 @@ sxtype(fl::RDATag) = fl % UInt8 Base class for RData internal representation of all R types. `SEXPREC` stands for S (R predecessor) expression record. """ -abstract RSEXPREC{S} +@compat abstract type RSEXPREC{S} end """ R symbol. @@ -98,12 +98,12 @@ end """ Base class for all R types (objects) that can have attributes. """ -abstract ROBJ{S} <: RSEXPREC{S} +@compat abstract type ROBJ{S} <: RSEXPREC{S} end """ Base class for all R vector-like objects. """ -abstract RVEC{T, S} <: ROBJ{S} +@compat abstract type RVEC{T, S} <: ROBJ{S} end """ R vector object. @@ -112,13 +112,13 @@ type RVector{T, S} <: RVEC{T, S} data::Vector{T} attr::Hash # collection of R object attributes - RVector(v::Vector{T} = T[], attr::Hash = Hash()) = new(v, attr) + (::Type{RVector{T,S}}){T,S}(v::Vector{T}=T[], attr::Hash=Hash()) = new{T,S}(v, attr) end -typealias RLogicalVector RVector{Int32, LGLSXP} -typealias RIntegerVector RVector{Int32, INTSXP} -typealias RNumericVector RVector{Float64, REALSXP} -typealias RComplexVector RVector{Complex128, CPLXSXP} +const RLogicalVector = RVector{Int32, LGLSXP} +const RIntegerVector = RVector{Int32, INTSXP} +const RNumericVector = RVector{Float64, REALSXP} +const RComplexVector = RVector{Complex128, CPLXSXP} """ R vector object with explicit NA values. @@ -129,12 +129,12 @@ immutable RNullableVector{T, S} <: RVEC{T, S} attr::Hash # collection of R object attributes end -typealias RStringVector RNullableVector{RString,STRSXP} -typealias RList RVector{RSEXPREC,VECSXP} # "list" in R == Julia cell array +const RStringVector = RNullableVector{RString,STRSXP} +const RList = RVector{RSEXPREC,VECSXP} # "list" in R == Julia cell array """ Representation of R's paired list-like structures (`LISTSXP`, `LANGSXP`). - Unlike R that represents it as singly-linked list, + Unlike R which represents these as singly-linked list, `RPairList` uses vector representation. """ immutable RPairList <: ROBJ{LISTSXP}