Skip to content
Snippets Groups Projects
Commit 60c7df5c authored by Florian Angerer's avatar Florian Angerer
Browse files

Added new FastR builtin to determine temp source file of a function.

parent 9eba177b
Branches
No related tags found
No related merge requests found
......@@ -102,6 +102,8 @@ import com.oracle.truffle.r.nodes.builtin.fastr.FastRRefCountInfo;
import com.oracle.truffle.r.nodes.builtin.fastr.FastRRefCountInfoNodeGen;
import com.oracle.truffle.r.nodes.builtin.fastr.FastRSlotAssign;
import com.oracle.truffle.r.nodes.builtin.fastr.FastRSlotAssignNodeGen;
import com.oracle.truffle.r.nodes.builtin.fastr.FastRSourceInfo;
import com.oracle.truffle.r.nodes.builtin.fastr.FastRSourceInfoNodeGen;
import com.oracle.truffle.r.nodes.builtin.fastr.FastRStackTrace;
import com.oracle.truffle.r.nodes.builtin.fastr.FastRStackTraceNodeGen;
import com.oracle.truffle.r.nodes.builtin.fastr.FastRStats.FastRProfAttr;
......@@ -387,6 +389,7 @@ public class BasePackage extends RBuiltinPackage {
add(FastRInterop.ToShort.class, FastRInteropFactory.ToShortNodeGen::create);
add(FastRRefCountInfo.class, FastRRefCountInfoNodeGen::create);
add(FastRPkgSource.class, FastRPkgSourceNodeGen::create);
add(FastRSourceInfo.class, FastRSourceInfoNodeGen::create);
add(FastRStackTrace.class, FastRStackTraceNodeGen::create);
add(FastRProfAttr.class, FastRStatsFactory.FastRProfAttrNodeGen::create);
add(FastRProfTypecounts.class, FastRStatsFactory.FastRProfTypecountsNodeGen::create);
......
/*
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.truffle.r.nodes.builtin.fastr;
import static com.oracle.truffle.r.runtime.RVisibility.ON;
import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.r.nodes.builtin.RBuiltinNode;
import com.oracle.truffle.r.runtime.builtins.RBehavior;
import com.oracle.truffle.r.runtime.builtins.RBuiltin;
import com.oracle.truffle.r.runtime.data.RFunction;
import com.oracle.truffle.r.runtime.data.RNull;
/**
* Allows to show the actual location of the source section of a provided function.
*/
@RBuiltin(name = ".fastr.srcinfo", visibility = ON, kind = PRIMITIVE, parameterNames = "fun", behavior = RBehavior.IO)
public abstract class FastRSourceInfo extends RBuiltinNode.Arg1 {
static {
Casts.noCasts(FastRSourceInfo.class);
}
@Specialization
public Object srcInfo(@SuppressWarnings("unused") RNull fun) {
return RNull.instance;
}
@Specialization
public Object srcInfo(RFunction fun) {
SourceSection ss = fun.getRootNode().getSourceSection();
if (ss != null) {
String path = ss.getSource().getPath();
if (path != null) {
return path + "#" + ss.getStartLine();
} else {
return ss.getSource().getName();
}
}
return RNull.instance;
}
}
......@@ -373,6 +373,7 @@ public class RDeparse {
if (!Files.exists(path)) {
try (BufferedWriter bw = Files.newBufferedWriter(path, CREATE_NEW, WRITE)) {
bw.write(sb.toString());
bw.newLine();
}
}
return path;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment