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
2078b8ee
Commit
2078b8ee
authored
8 years ago
by
Julien Lopez
Browse files
Options
Downloads
Patches
Plain Diff
Factorize code between translation of lambda and function
parent
e12b52fd
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.nodes/src/com/oracle/truffle/r/nodes/qirinterface/QIRInterface.java
+21
-34
21 additions, 34 deletions
...com/oracle/truffle/r/nodes/qirinterface/QIRInterface.java
with
21 additions
and
34 deletions
com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/qirinterface/QIRInterface.java
+
21
−
34
View file @
2078b8ee
...
...
@@ -27,7 +27,6 @@ import java.io.IOException;
import
java.io.Reader
;
import
java.math.BigInteger
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -209,24 +208,6 @@ public final class QIRInterface {
return
(
Boolean
)
value
?
QIRBoolean
.
qirTrue
:
QIRBoolean
.
qirFalse
;
if
(
value
instanceof
String
)
return
new
QIRString
(
src
,
(
String
)
value
);
if
(
value
instanceof
FunctionExpressionNode
)
{
final
FunctionExpressionNode
fun
=
(
FunctionExpressionNode
)
value
;
if
(
fun
.
getCallTarget
()
==
null
)
return
new
QIRBuiltin
(
src
,
fun
.
getSyntaxDebugName
());
final
String
funName
=
fun
.
getSyntaxDebugName
();
try
{
QIRNode
res
=
((
FunctionDefinitionNode
)
fun
.
getCallTarget
().
getRootNode
()).
getBody
().
accept
(
QIRTranslateVisitor
.
instance
);
final
String
[]
args
=
((
FunctionDefinitionNode
)
fun
.
getCallTarget
().
getRootNode
()).
getSignature
().
getNames
();
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
res
=
new
QIRLambda
(
src
,
funName
,
new
QIRVariable
(
null
,
args
[
i
],
null
),
res
);
return
res
;
}
catch
(
UnsupportedOperationException
e
)
{
final
SourceSection
funSrc
=
fun
.
getCallTarget
().
getRootNode
().
getSourceSection
();
final
String
program
=
funSrc
.
getCode
()
+
"\n"
+
funName
;
// TODO: Handle function dependencies
return
new
QIRTruffleNode
(
funSrc
,
program
);
}
}
if
(
value
instanceof
REnvironment
)
{
REnvironment
env
=
(
REnvironment
)
value
;
final
Object
queryId
=
env
.
get
(
"queryId"
);
...
...
@@ -247,6 +228,9 @@ public final class QIRInterface {
tuple
=
new
QIRTcons
(
src
,
(
String
)
x
,
RToQIRType
(
src
,
env
.
get
((
String
)
x
)),
tuple
);
return
tuple
;
}
if
(
value
instanceof
FunctionExpressionNode
)
{
return
RFunctionToQIRType
(
src
,
((
FunctionExpressionNode
)
value
).
getSyntaxDebugName
(),
(
FunctionDefinitionNode
)
(((
FunctionExpressionNode
)
value
).
getCallTarget
().
getRootNode
()));
}
if
(
value
instanceof
RFunction
)
{
final
RFunction
fun
=
(
RFunction
)
value
;
if
(
fun
.
isBuiltin
())
...
...
@@ -268,22 +252,25 @@ public final class QIRInterface {
default
:
throw
new
RuntimeException
(
"Unsupported value: "
+
value
+
" : "
+
value
.
getClass
());
}
try
{
final
FunctionDefinitionNode
rootNode
=
(
FunctionDefinitionNode
)
fun
.
getRootNode
();
QIRNode
res
=
rootNode
.
getBody
().
accept
(
QIRTranslateVisitor
.
instance
);
final
String
[]
args
=
Arrays
.
asList
(
rootNode
.
argSourceSections
).
stream
().
map
(
arg
->
arg
.
getCode
()).
toArray
(
size
->
new
String
[
size
]);
final
String
funName
=
fun
.
getName
();
if
(
args
.
length
==
0
)
return
new
QIRLambda
(
src
,
funName
,
null
,
res
);
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
res
=
new
QIRLambda
(
src
,
funName
,
new
QIRVariable
(
null
,
args
[
i
],
null
),
res
);
return
res
;
}
catch
(
UnsupportedOperationException
e
)
{
final
SourceSection
funSrc
=
fun
.
getRootNode
().
getSourceSection
();
// TODO: Handle dependencies
return
new
QIRTruffleNode
(
funSrc
,
funSrc
.
getCode
());
}
return
RFunctionToQIRType
(
src
,
fun
.
getName
(),
(
FunctionDefinitionNode
)
fun
.
getRootNode
());
}
throw
new
RuntimeException
(
"Unsupported value: "
+
value
);
}
private
static
final
<
T
>
QIRNode
RFunctionToQIRType
(
final
SourceSection
src
,
final
String
funName
,
final
FunctionDefinitionNode
fun
)
{
try
{
QIRNode
res
=
((
FunctionDefinitionNode
)
fun
.
getCallTarget
().
getRootNode
()).
getBody
().
accept
(
QIRTranslateVisitor
.
instance
);
final
String
[]
args
=
((
FunctionDefinitionNode
)
fun
.
getCallTarget
().
getRootNode
()).
getSignature
().
getNames
();
if
(
args
.
length
==
0
)
return
new
QIRLambda
(
src
,
funName
,
null
,
res
);
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
res
=
new
QIRLambda
(
src
,
funName
,
new
QIRVariable
(
null
,
args
[
i
],
null
),
res
);
return
res
;
}
catch
(
UnsupportedOperationException
e
)
{
final
SourceSection
funSrc
=
fun
.
getCallTarget
().
getRootNode
().
getSourceSection
();
// TODO: Handle dependencies
return
new
QIRTruffleNode
(
funSrc
,
funSrc
.
getCode
());
}
}
}
\ No newline at end of file
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