Skip to content
Snippets Groups Projects
Commit 333db313 authored by Adam Welc's avatar Adam Welc
Browse files

Added support for accessing function arguments as part of RLanguage object.

parent 321b755f
Branches
No related tags found
No related merge requests found
......@@ -112,6 +112,18 @@ import com.oracle.truffle.r.runtime.nodes.RSyntaxNode;
*/
public class RRuntimeASTAccessImpl implements RRuntimeASTAccess {
private static Object getIntrinsicValue(Object result) {
if (result instanceof RSyntaxConstant) {
return ((RSyntaxConstant) result).getValue();
} else if (result instanceof RSyntaxLookup) {
return RDataFactory.createSymbolInterned(((RSyntaxLookup) result).getIdentifier());
} else {
assert result instanceof RSyntaxCall || result instanceof RSyntaxFunction : result.getClass();
return RDataFactory.createLanguage(((RSyntaxNode) result).asRNode());
}
}
@TruffleBoundary
@Override
public int getLength(RLanguage rl) {
......@@ -152,7 +164,15 @@ public class RRuntimeASTAccessImpl implements RRuntimeASTAccess {
result = RSyntaxLookup.createDummyLookup(null, "function", true);
break;
case 1:
throw RInternalError.unimplemented("arguments of 'function'");
ArgumentsSignature sig = ((RSyntaxFunction) s).getSyntaxSignature();
RSyntaxElement[] defaults = ((RSyntaxFunction) s).getSyntaxArgumentDefaults();
Object list = RNull.instance;
for (int i = sig.getLength() - 1; i >= 0; i--) {
list = RDataFactory.createPairList(defaults[i] == null ? RDataFactory.createSymbolInterned("") : getIntrinsicValue(defaults[i]), list,
RDataFactory.createSymbolInterned(sig.getName(i)));
}
return list;
case 2:
result = ((RSyntaxFunction) s).getSyntaxBody();
break;
......@@ -173,14 +193,7 @@ public class RRuntimeASTAccessImpl implements RRuntimeASTAccess {
/*
* Constants and lookups are converted to their intrinsic value:
*/
if (result instanceof RSyntaxConstant) {
return ((RSyntaxConstant) result).getValue();
} else if (result instanceof RSyntaxLookup) {
return RDataFactory.createSymbolInterned(((RSyntaxLookup) result).getIdentifier());
} else {
assert result instanceof RSyntaxCall || result instanceof RSyntaxFunction : result.getClass();
return RDataFactory.createLanguage(((RSyntaxNode) result).asRNode());
}
return getIntrinsicValue(result);
}
@TruffleBoundary
......
......@@ -680,6 +680,11 @@ public class TestSimpleVectors extends TestBase {
assertEval("{ e <- quote(f(x=a, b)); names(e) }");
assertEval("{ e <- quote(f(x=a, y=b)); names(e) }");
assertEval("{ e <- quote(f(x=a, y=b)); names(e[-1]) }");
assertEval("{ x<-quote(function(x, y) 42); x[[2]] }");
assertEval("{ x<-quote(function(x, y) 42); typeof(x[[2]][[1]]) }");
assertEval("{ x<-quote(function(x, y) 42); names(x[[2]]) }");
assertEval("{ x<-quote(function(x, y=7) 42); x[[2]] }");
}
@Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment