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
e2fe2b10
Commit
e2fe2b10
authored
7 years ago
by
Lukas Stadler
Browse files
Options
Downloads
Patches
Plain Diff
allow coercion to LISTSXP/LANGSXP from native API
parent
4ed72afe
No related branches found
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.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/CoerceNodes.java
+35
-24
35 additions, 24 deletions
.../src/com/oracle/truffle/r/ffi/impl/nodes/CoerceNodes.java
with
35 additions
and
24 deletions
com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/CoerceNodes.java
+
35
−
24
View file @
e2fe2b10
...
...
@@ -58,39 +58,51 @@ import com.oracle.truffle.r.runtime.gnur.SEXPTYPE;
public
final
class
CoerceNodes
{
public
abstract
static
class
VectorToPairListNode
extends
FFIUpCallNode
.
Arg1
{
public
static
final
class
VectorToPairListNode
extends
FFIUpCallNode
.
Arg1
{
@Child
private
CopyOfRegAttributesNode
copyRegAttributesNode
;
@Child
private
GetNamesAttributeNode
getNamesAttributeNode
;
@Child
private
CastPairListNode
cast
=
CastPairListNode
.
create
(
SEXPTYPE
.
LISTSXP
);
@Override
public
Object
executeObject
(
Object
value
)
{
return
cast
.
doCast
(
value
);
}
public
static
VectorToPairListNode
create
()
{
return
new
VectorToPairListNode
();
}
}
public
abstract
static
class
CastPairListNode
extends
CastNode
{
private
final
SEXPTYPE
type
;
@Child
private
CopyOfRegAttributesNode
copyRegAttributesNode
=
CopyOfRegAttributesNode
.
create
();
@Child
private
GetNamesAttributeNode
getNamesAttributeNode
=
GetNamesAttributeNode
.
create
();
protected
CastPairListNode
(
SEXPTYPE
type
)
{
this
.
type
=
type
;
}
@Specialization
protected
Object
convert
(
RAbstractVector
v
)
{
RStringVector
names
=
getNamesAttributeNode
.
getNames
(
v
);
SEXPTYPE
gnurType
=
SEXPTYPE
.
gnuRTypeForObject
(
v
);
RPairList
head
=
null
;
RPairList
prev
=
null
;
Object
current
=
RNull
.
instance
;
assert
names
==
null
||
names
.
getLength
()
==
v
.
getLength
();
for
(
int
i
=
0
;
i
<
v
.
getLength
()
;
i
++
)
{
for
(
int
i
=
v
.
getLength
()
-
1
;
i
>=
0
;
i
--
)
{
Object
element
=
v
.
getDataAtAsObject
(
i
);
adjustSharing
(
v
,
element
);
RPairList
cur
=
RDataFactory
.
createPairList
(
element
,
RNull
.
instance
,
names
!=
null
?
RDataFactory
.
createSymbol
(
names
.
getDataAt
(
i
))
:
RNull
.
instance
,
gnurType
);
if
(
prev
==
null
)
{
assert
head
==
null
;
head
=
cur
;
}
else
{
prev
.
setCdr
(
cur
);
}
prev
=
cur
;
current
=
RDataFactory
.
createPairList
(
element
,
current
,
names
!=
null
?
RDataFactory
.
createSymbol
(
names
.
getDataAt
(
i
))
:
RNull
.
instance
,
gnurType
);
}
if
(
head
!=
n
ull
)
{
if
(
current
!=
RN
ull
.
instance
)
{
// also copy regular attributes
copyRegAttributesNode
.
execute
(
v
,
head
);
return
head
;
RPairList
pl
=
(
RPairList
)
current
;
copyRegAttributesNode
.
execute
(
v
,
pl
);
pl
.
setType
(
type
);
pl
.
allowClosure
();
}
return
RNull
.
instance
;
return
current
;
}
private
static
void
adjustSharing
(
RAbstractVector
origin
,
Object
element
)
{
...
...
@@ -110,8 +122,8 @@ public final class CoerceNodes {
}
}
public
static
VectorTo
PairListNode
create
()
{
return
CoerceNodesFactory
.
VectorTo
PairListNodeGen
.
create
();
public
static
Cast
PairListNode
create
(
SEXPTYPE
type
)
{
return
CoerceNodesFactory
.
Cast
PairListNodeGen
.
create
(
type
);
}
private
static
int
getSharingLevel
(
RShareable
r
)
{
...
...
@@ -234,9 +246,8 @@ public final class CoerceNodes {
case
NILSXP:
return
new
CastNullNode
();
case
LISTSXP:
throw
RInternalError
.
unimplemented
(
"Rf_coerceVector unimplemented for PairLists."
);
case
LANGSXP:
throw
RInternalError
.
unimplemented
(
"Rf_coerceVector unimplemented for RPairList."
);
return
CastPairListNode
.
create
(
type
);
case
ENVSXP:
return
new
EnvironmentCast
();
case
VECSXP:
...
...
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