Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
QueryR
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julien Lopez
QueryR
Commits
0f549a90
Commit
0f549a90
authored
8 years ago
by
Mick Jordan
Committed by
Lukas Stadler
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
add cast pipelines for readBin/writeBin
parent
b887c297
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ConnectionFunctions.java
+36
-15
36 additions, 15 deletions
...cle/truffle/r/nodes/builtin/base/ConnectionFunctions.java
with
36 additions
and
15 deletions
com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ConnectionFunctions.java
+
36
−
15
View file @
0f549a90
...
@@ -49,13 +49,11 @@ import com.oracle.truffle.api.dsl.Specialization;
...
@@ -49,13 +49,11 @@ import com.oracle.truffle.api.dsl.Specialization;
import
com.oracle.truffle.api.dsl.TypeSystemReference
;
import
com.oracle.truffle.api.dsl.TypeSystemReference
;
import
com.oracle.truffle.r.nodes.builtin.CastBuilder
;
import
com.oracle.truffle.r.nodes.builtin.CastBuilder
;
import
com.oracle.truffle.r.nodes.builtin.CastBuilder.HeadPhaseBuilder
;
import
com.oracle.truffle.r.nodes.builtin.CastBuilder.HeadPhaseBuilder
;
import
com.oracle.truffle.r.nodes.builtin.CastBuilder.InitialPhaseBuilder
;
import
com.oracle.truffle.r.nodes.builtin.RBuiltinNode
;
import
com.oracle.truffle.r.nodes.builtin.RBuiltinNode
;
import
com.oracle.truffle.r.nodes.builtin.base.ConnectionFunctionsFactory.WriteDataNodeGen
;
import
com.oracle.truffle.r.nodes.builtin.base.ConnectionFunctionsFactory.WriteDataNodeGen
;
import
com.oracle.truffle.r.runtime.RError
;
import
com.oracle.truffle.r.runtime.RError
;
import
com.oracle.truffle.r.runtime.RInternalError
;
import
com.oracle.truffle.r.runtime.RInternalError
;
import
com.oracle.truffle.r.runtime.RRuntime
;
import
com.oracle.truffle.r.runtime.RRuntime
;
import
com.oracle.truffle.r.runtime.RVisibility
;
import
com.oracle.truffle.r.runtime.builtins.RBuiltin
;
import
com.oracle.truffle.r.runtime.builtins.RBuiltin
;
import
com.oracle.truffle.r.runtime.conn.ConnectionSupport.BaseRConnection
;
import
com.oracle.truffle.r.runtime.conn.ConnectionSupport.BaseRConnection
;
import
com.oracle.truffle.r.runtime.conn.FileConnections.FileRConnection
;
import
com.oracle.truffle.r.runtime.conn.FileConnections.FileRConnection
;
...
@@ -69,9 +67,9 @@ import com.oracle.truffle.r.runtime.data.RComplex;
...
@@ -69,9 +67,9 @@ import com.oracle.truffle.r.runtime.data.RComplex;
import
com.oracle.truffle.r.runtime.data.RComplexVector
;
import
com.oracle.truffle.r.runtime.data.RComplexVector
;
import
com.oracle.truffle.r.runtime.data.RDataFactory
;
import
com.oracle.truffle.r.runtime.data.RDataFactory
;
import
com.oracle.truffle.r.runtime.data.RDoubleVector
;
import
com.oracle.truffle.r.runtime.data.RDoubleVector
;
import
com.oracle.truffle.r.runtime.data.RExpression
;
import
com.oracle.truffle.r.runtime.data.RIntVector
;
import
com.oracle.truffle.r.runtime.data.RIntVector
;
import
com.oracle.truffle.r.runtime.data.RList
;
import
com.oracle.truffle.r.runtime.data.RList
;
import
com.oracle.truffle.r.runtime.data.RLogical
;
import
com.oracle.truffle.r.runtime.data.RLogicalVector
;
import
com.oracle.truffle.r.runtime.data.RLogicalVector
;
import
com.oracle.truffle.r.runtime.data.RNull
;
import
com.oracle.truffle.r.runtime.data.RNull
;
import
com.oracle.truffle.r.runtime.data.RRaw
;
import
com.oracle.truffle.r.runtime.data.RRaw
;
...
@@ -703,26 +701,43 @@ public abstract class ConnectionFunctions {
...
@@ -703,26 +701,43 @@ public abstract class ConnectionFunctions {
return
buffer
.
order
(
nb
);
return
buffer
.
order
(
nb
);
}
}
private
abstract
static
class
BinCastHelper
extends
InternalCloseHelper
{
protected
void
n
(
CastBuilder
casts
)
{
casts
.
arg
(
"n"
).
asIntegerVector
().
findFirst
().
mustBe
(
gte
(
0
));
}
protected
void
size
(
CastBuilder
casts
)
{
casts
.
arg
(
"size"
).
asIntegerVector
().
findFirst
();
}
protected
void
swap
(
CastBuilder
casts
)
{
casts
.
arg
(
"swap"
).
asLogicalVector
().
findFirst
().
notNA
().
map
(
toBoolean
());
}
}
@RBuiltin
(
name
=
"readBin"
,
kind
=
INTERNAL
,
parameterNames
=
{
"con"
,
"what"
,
"n"
,
"size"
,
"signed"
,
"swap"
},
behavior
=
IO
)
@RBuiltin
(
name
=
"readBin"
,
kind
=
INTERNAL
,
parameterNames
=
{
"con"
,
"what"
,
"n"
,
"size"
,
"signed"
,
"swap"
},
behavior
=
IO
)
public
abstract
static
class
ReadBin
extends
InternalClose
Helper
{
public
abstract
static
class
ReadBin
extends
BinCast
Helper
{
@Override
@Override
protected
void
createCasts
(
CastBuilder
casts
)
{
protected
void
createCasts
(
CastBuilder
casts
)
{
casts
.
toInteger
(
2
);
// TODO con can be a RAWSXP (not implemented)
connection
(
casts
);
casts
.
arg
(
"what"
).
asStringVector
().
findFirst
();
n
(
casts
);
size
(
casts
);
casts
.
arg
(
"signed"
).
asLogicalVector
().
findFirst
().
notNA
().
map
(
toBoolean
());
swap
(
casts
);
}
}
@Specialization
@Specialization
@TruffleBoundary
@TruffleBoundary
protected
Object
readBin
(
RConnection
con
,
RAbstractStringVector
whatVec
,
RAbstractIntVector
nVec
,
@SuppressWarnings
(
"unused"
)
int
size
,
@SuppressWarnings
(
"unused"
)
byte
signedArg
,
protected
Object
readBin
(
RConnection
con
,
String
what
,
int
n
,
@SuppressWarnings
(
"unused"
)
int
size
,
@SuppressWarnings
(
"unused"
)
boolean
signed
,
byte
swapArg
)
{
boolean
swap
)
{
boolean
swap
=
RRuntime
.
fromLogical
(
swapArg
);
RVector
result
=
null
;
RVector
result
=
null
;
int
n
=
nVec
.
getDataAt
(
0
);
try
(
RConnection
openConn
=
con
.
forceOpen
(
"rb"
))
{
try
(
RConnection
openConn
=
con
.
forceOpen
(
"rb"
))
{
if
(
getBaseConnection
(
openConn
).
getOpenMode
().
isText
())
{
if
(
getBaseConnection
(
openConn
).
getOpenMode
().
isText
())
{
throw
RError
.
error
(
this
,
RError
.
Message
.
ONLY_READ_BINARY_CONNECTION
);
throw
RError
.
error
(
this
,
RError
.
Message
.
ONLY_READ_BINARY_CONNECTION
);
}
}
String
what
=
whatVec
.
getDataAt
(
0
);
switch
(
what
)
{
switch
(
what
)
{
case
"int"
:
case
"int"
:
case
"integer"
:
case
"integer"
:
...
@@ -971,19 +986,25 @@ public abstract class ConnectionFunctions {
...
@@ -971,19 +986,25 @@ public abstract class ConnectionFunctions {
}
}
@RBuiltin
(
name
=
"writeBin"
,
visibility
=
CUSTOM
,
kind
=
INTERNAL
,
parameterNames
=
{
"object"
,
"con"
,
"size"
,
"swap"
,
"useBytes"
},
behavior
=
IO
)
@RBuiltin
(
name
=
"writeBin"
,
visibility
=
CUSTOM
,
kind
=
INTERNAL
,
parameterNames
=
{
"object"
,
"con"
,
"size"
,
"swap"
,
"useBytes"
},
behavior
=
IO
)
public
abstract
static
class
WriteBin
extends
InternalClose
Helper
{
public
abstract
static
class
WriteBin
extends
BinCast
Helper
{
@Override
@Override
protected
void
createCasts
(
CastBuilder
casts
)
{
protected
void
createCasts
(
CastBuilder
casts
)
{
casts
.
firstIntegerWithError
(
2
,
null
,
null
);
// TODO atomic, i.e. not RList or RExpression
casts
.
arg
(
"object"
).
asVector
().
mustBe
(
nullValue
().
not
().
and
(
instanceOf
(
RAbstractVector
.
class
)));
connection
(
casts
);
size
(
casts
);
swap
(
casts
);
useBytes
(
casts
);
}
}
@TruffleBoundary
@TruffleBoundary
@Specialization
@Specialization
protected
Object
writeBin
(
RAbstractVector
object
,
RConnection
con
,
int
size
,
b
yte
swapArg
,
byte
useBytes
Arg
,
//
protected
Object
writeBin
(
RAbstractVector
object
,
RConnection
con
,
int
size
,
b
oolean
swap
,
boolean
useBytes
,
//
@Cached
(
"create()"
)
WriteDataNode
writeData
)
{
@Cached
(
"create()"
)
WriteDataNode
writeData
)
{
boolean
swap
=
RRuntime
.
fromLogical
(
swapArg
);
if
(
object
instanceof
RList
||
object
instanceof
RExpression
)
{
boolean
useBytes
=
RRuntime
.
fromLogical
(
useBytesArg
);
throw
RError
.
error
(
this
,
RError
.
Message
.
INVALID_ARGUMENT
,
"object"
);
}
if
(
object
.
getLength
()
>
0
)
{
if
(
object
.
getLength
()
>
0
)
{
try
(
RConnection
openConn
=
con
.
forceOpen
(
"wb"
))
{
try
(
RConnection
openConn
=
con
.
forceOpen
(
"wb"
))
{
if
(
getBaseConnection
(
openConn
).
isTextMode
())
{
if
(
getBaseConnection
(
openConn
).
isTextMode
())
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment