Skip to content
Snippets Groups Projects
Commit 71eeb93b authored by Mick Jordan's avatar Mick Jordan
Browse files

fastr package updates

parent a20dfb93
No related branches found
No related tags found
No related merge requests found
......@@ -40,7 +40,7 @@ import com.oracle.truffle.r.runtime.data.*;
* Run a FastR function, and dump its AST to IGV before and after running. If no function is passed,
* this builtin does not do anything.
*/
@RBuiltin(name = "fastr.rundump", parameterNames = {"function"}, kind = PRIMITIVE)
@RBuiltin(name = "fastr.rundump", parameterNames = {"func"}, kind = PRIMITIVE)
public abstract class FastRRunDump extends RInvisibleBuiltinNode {
// TODO Make this more versatile by allowing actual function calls with arguments to be
......
/*
* Copyright (c) 2014, 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 java.lang.reflect.*;
import com.oracle.truffle.api.dsl.*;
import com.oracle.truffle.api.frame.*;
import com.oracle.truffle.r.nodes.builtin.*;
import com.oracle.truffle.r.runtime.*;
import com.oracle.truffle.r.runtime.RError.*;
import com.oracle.truffle.r.runtime.data.*;
import com.oracle.truffle.r.runtime.data.model.*;
@RBuiltin(name = "fastr.setfield", kind = RBuiltinKind.PRIMITIVE, parameterNames = {"field", "value"})
public abstract class FastRSetField extends RInvisibleBuiltinNode {
@Specialization
RNull setField(VirtualFrame frame, RAbstractStringVector vec, Object value) {
controlVisibility();
String qualFieldName = vec.getDataAt(0);
int lx = qualFieldName.lastIndexOf('.');
String simpleName = qualFieldName.substring(lx + 1);
String className = qualFieldName.substring(0, lx);
if (!className.startsWith("com")) {
className = "com.oracle.truffle.r." + className;
}
try {
Class<?> klass = Class.forName(className);
Field field = klass.getDeclaredField(simpleName);
field.setAccessible(true);
Class<?> fieldType = field.getType();
switch (fieldType.getSimpleName()) {
case "boolean":
if (value instanceof Byte) {
field.setBoolean(null, RRuntime.fromLogical((byte) value));
} else {
error(frame, qualFieldName);
}
}
} catch (Exception ex) {
throw RError.error(frame, Message.GENERIC, ex.getMessage());
}
return RNull.instance;
}
private static void error(VirtualFrame frame, String fieldName) throws RError {
throw RError.error(frame, Message.GENERIC, "value is wrong type for %s", fieldName);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment