
com.oracle.truffle.sl.builtins.SLPrintlnBuiltinFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of truffle-sl Show documentation
Show all versions of truffle-sl Show documentation
Truffle SL is an example language implemented using the Truffle API.
The newest version!
// CheckStyle: start generated
package com.oracle.truffle.sl.builtins;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.dsl.GeneratedBy;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.NodeCost;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.sl.nodes.SLExpressionNode;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.locks.Lock;
@GeneratedBy(SLPrintlnBuiltin.class)
@SuppressWarnings({"unchecked", "rawtypes"})
public final class SLPrintlnBuiltinFactory implements NodeFactory {
private static SLPrintlnBuiltinFactory instance;
private SLPrintlnBuiltinFactory() {
}
@Override
public Class getNodeClass() {
return SLPrintlnBuiltin.class;
}
@Override
public List getExecutionSignature() {
return Arrays.asList(SLExpressionNode.class);
}
@Override
public List getNodeSignatures() {
return Arrays.asList(Arrays.asList(SLExpressionNode[].class));
}
@Override
public SLPrintlnBuiltin createNode(Object... arguments) {
if (arguments.length == 1 && (arguments[0] == null || arguments[0] instanceof SLExpressionNode[])) {
return create((SLExpressionNode[]) arguments[0]);
} else {
throw new IllegalArgumentException("Invalid create signature.");
}
}
public static NodeFactory getInstance() {
if (instance == null) {
instance = new SLPrintlnBuiltinFactory();
}
return instance;
}
public static SLPrintlnBuiltin create(SLExpressionNode[] arguments) {
return new SLPrintlnBuiltinNodeGen(arguments);
}
@GeneratedBy(SLPrintlnBuiltin.class)
public static final class SLPrintlnBuiltinNodeGen extends SLPrintlnBuiltin {
@Child private SLExpressionNode arguments0_;
@CompilationFinal private int state_;
private SLPrintlnBuiltinNodeGen(SLExpressionNode[] arguments) {
this.arguments0_ = arguments != null && 0 < arguments.length ? arguments[0] : null;
}
@Override
protected Object execute(VirtualFrame frameValue) {
int state = state_;
if ((state & 0b1110) == 0 /* only-active println(long) */ && state != 0 /* is-not println(long) && println(boolean) && println(String) && println(Object) */) {
return execute_long0(frameValue, state);
} else if ((state & 0b1101) == 0 /* only-active println(boolean) */ && state != 0 /* is-not println(long) && println(boolean) && println(String) && println(Object) */) {
return execute_boolean1(frameValue, state);
} else {
return execute_generic2(frameValue, state);
}
}
private Object execute_long0(VirtualFrame frameValue, int state) {
long arguments0Value_;
try {
arguments0Value_ = this.arguments0_.executeLong(frameValue);
} catch (UnexpectedResultException ex) {
return executeAndSpecialize(ex.getResult());
}
assert (state & 0b1) != 0 /* is-active println(long) */;
return println(arguments0Value_);
}
private Object execute_boolean1(VirtualFrame frameValue, int state) {
boolean arguments0Value_;
try {
arguments0Value_ = this.arguments0_.executeBoolean(frameValue);
} catch (UnexpectedResultException ex) {
return executeAndSpecialize(ex.getResult());
}
assert (state & 0b10) != 0 /* is-active println(boolean) */;
return println(arguments0Value_);
}
private Object execute_generic2(VirtualFrame frameValue, int state) {
Object arguments0Value_ = this.arguments0_.executeGeneric(frameValue);
if ((state & 0b1) != 0 /* is-active println(long) */ && arguments0Value_ instanceof Long) {
long arguments0Value__ = (long) arguments0Value_;
return println(arguments0Value__);
}
if ((state & 0b10) != 0 /* is-active println(boolean) */ && arguments0Value_ instanceof Boolean) {
boolean arguments0Value__ = (boolean) arguments0Value_;
return println(arguments0Value__);
}
if ((state & 0b100) != 0 /* is-active println(String) */ && arguments0Value_ instanceof String) {
String arguments0Value__ = (String) arguments0Value_;
return println(arguments0Value__);
}
if ((state & 0b1000) != 0 /* is-active println(Object) */) {
return println(arguments0Value_);
}
CompilerDirectives.transferToInterpreterAndInvalidate();
return executeAndSpecialize(arguments0Value_);
}
private Object executeAndSpecialize(Object arguments0Value) {
Lock lock = getLock();
boolean hasLock = true;
lock.lock();
int state = state_;
int oldState = state;
try {
if (arguments0Value instanceof Long) {
long arguments0Value_ = (long) arguments0Value;
this.state_ = state = state | 0b1 /* add-active println(long) */;
lock.unlock();
hasLock = false;
return println(arguments0Value_);
}
if (arguments0Value instanceof Boolean) {
boolean arguments0Value_ = (boolean) arguments0Value;
this.state_ = state = state | 0b10 /* add-active println(boolean) */;
lock.unlock();
hasLock = false;
return println(arguments0Value_);
}
if (arguments0Value instanceof String) {
String arguments0Value_ = (String) arguments0Value;
this.state_ = state = state | 0b100 /* add-active println(String) */;
lock.unlock();
hasLock = false;
return println(arguments0Value_);
}
this.state_ = state = state | 0b1000 /* add-active println(Object) */;
lock.unlock();
hasLock = false;
return println(arguments0Value);
} finally {
if (oldState != 0) {
checkForPolymorphicSpecialize(oldState);
}
if (hasLock) {
lock.unlock();
}
}
}
private void checkForPolymorphicSpecialize(int oldState) {
int newState = this.state_;
if ((oldState ^ newState) != 0) {
this.reportPolymorphicSpecialize();
}
}
@Override
public NodeCost getCost() {
int state = state_;
if (state == 0b0) {
return NodeCost.UNINITIALIZED;
} else if ((state & (state - 1)) == 0 /* is-single-active */) {
return NodeCost.MONOMORPHIC;
}
return NodeCost.POLYMORPHIC;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy