org.jruby.truffle.language.RubyNode Maven / Gradle / Ivy
The newest version!
/*
* Copyright (c) 2013, 2017 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.language;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.instrumentation.Instrumentable;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.object.DynamicObject;
@Instrumentable(factory = RubyNodeWrapper.class)
public abstract class RubyNode extends RubyBaseNode {
// Fundamental execute methods
public abstract Object execute(VirtualFrame frame);
public void executeVoid(VirtualFrame frame) {
execute(frame);
}
public Object isDefined(VirtualFrame frame) {
return coreStrings().EXPRESSION.createInstance();
}
// Utility methods to execute and expect a particular type
public NotProvided executeNotProvided(VirtualFrame frame) throws UnexpectedResultException {
final Object value = execute(frame);
if (value instanceof NotProvided) {
return (NotProvided) value;
} else {
throw new UnexpectedResultException(value);
}
}
public boolean executeBoolean(VirtualFrame frame) throws UnexpectedResultException {
final Object value = execute(frame);
if (value instanceof Boolean) {
return (boolean) value;
} else {
throw new UnexpectedResultException(value);
}
}
public int executeInteger(VirtualFrame frame) throws UnexpectedResultException {
final Object value = execute(frame);
if (value instanceof Integer) {
return (int) value;
} else {
throw new UnexpectedResultException(value);
}
}
public long executeLong(VirtualFrame frame) throws UnexpectedResultException {
final Object value = execute(frame);
if (value instanceof Long) {
return (long) value;
} else {
throw new UnexpectedResultException(value);
}
}
public double executeDouble(VirtualFrame frame) throws UnexpectedResultException {
final Object value = execute(frame);
if (value instanceof Double) {
return (double) value;
} else {
throw new UnexpectedResultException(value);
}
}
public DynamicObject executeDynamicObject(VirtualFrame frame) throws UnexpectedResultException {
final Object value = execute(frame);
if (value instanceof DynamicObject) {
return (DynamicObject) value;
} else {
throw new UnexpectedResultException(value);
}
}
public Object[] executeObjectArray(VirtualFrame frame) throws UnexpectedResultException {
final Object value = execute(frame);
if (value.getClass() == Object[].class) {
return (Object[]) value;
} else {
throw new UnexpectedResultException(value);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy