com.oracle.truffle.sl.builtins.SLAssertTrueBuiltinFactory 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!
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
*
* Subject to the condition set forth below, permission is hereby granted to any
* person obtaining a copy of this software, associated documentation and/or
* data (collectively the "Software"), free of charge and under any and all
* copyright rights in the Software, and any and all patent rights owned or
* freely licensable by each licensor hereunder covering either (i) the
* unmodified Software as contributed to or provided by such licensor, or (ii)
* the Larger Works (as defined below), to deal in both
*
* (a) the Software, and
*
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
* one is included with the Software each a "Larger Work" to which the Software
* is contributed by such licensors),
*
* without restriction, including without limitation the rights to copy, create
* derivative works of, display, perform, and distribute the Software and make,
* use, sell, offer for sale, import, export, have made, and have sold the
* Software and the Larger Work(s), and to sublicense the foregoing rights on
* either these or other terms.
*
* This license is subject to the following condition:
*
* The above copyright notice and either this complete permission notice or at a
* minimum a reference to the UPL must be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
// 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.dsl.internal.NodeFactoryBase;
import com.oracle.truffle.api.dsl.internal.SpecializationNode;
import com.oracle.truffle.api.dsl.internal.SpecializedNode;
import com.oracle.truffle.api.frame.Frame;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.NodeCost;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.sl.nodes.SLExpressionNode;
import com.oracle.truffle.sl.nodes.SLTypes;
import com.oracle.truffle.sl.nodes.SLTypesGen;
import com.oracle.truffle.sl.runtime.SLContext;
import com.oracle.truffle.sl.runtime.SLNull;
@GeneratedBy(SLAssertTrueBuiltin.class)
public final class SLAssertTrueBuiltinFactory extends NodeFactoryBase {
private static SLAssertTrueBuiltinFactory instance;
private SLAssertTrueBuiltinFactory() {
super(SLAssertTrueBuiltin.class, new Class>[] {SLExpressionNode.class, SLExpressionNode.class}, new Class>[][] {new Class>[] {SLExpressionNode[].class, SLContext.class}});
}
@Override
public SLAssertTrueBuiltin createNode(Object... arguments) {
if (arguments.length == 2 && (arguments[0] == null || arguments[0] instanceof SLExpressionNode[]) && (arguments[1] == null || arguments[1] instanceof SLContext)) {
return create((SLExpressionNode[]) arguments[0], (SLContext) arguments[1]);
} else {
throw new IllegalArgumentException("Invalid create signature.");
}
}
public static NodeFactory getInstance() {
if (instance == null) {
instance = new SLAssertTrueBuiltinFactory();
}
return instance;
}
public static SLAssertTrueBuiltin create(SLExpressionNode[] arguments, SLContext context) {
return new SLAssertTrueBuiltinNodeGen(arguments, context);
}
@GeneratedBy(SLAssertTrueBuiltin.class)
public static final class SLAssertTrueBuiltinNodeGen extends SLAssertTrueBuiltin implements SpecializedNode {
private final SLContext context;
@Child private SLExpressionNode arguments0_;
@Child private SLExpressionNode arguments1_;
@CompilationFinal private Class> arguments0Type_;
@Child private BaseNode_ specialization_;
private SLAssertTrueBuiltinNodeGen(SLExpressionNode[] arguments, SLContext context) {
this.context = context;
this.arguments0_ = arguments != null && 0 < arguments.length ? arguments[0] : null;
this.arguments1_ = arguments != null && 1 < arguments.length ? arguments[1] : null;
this.specialization_ = UninitializedNode_.create(this);
}
@Override
public SLContext getContext() {
return this.context;
}
@Override
public NodeCost getCost() {
return specialization_.getNodeCost();
}
@Override
public Object executeGeneric(VirtualFrame frameValue) {
return specialization_.execute(frameValue);
}
@Override
public void executeVoid(VirtualFrame frameValue) {
specialization_.executeVoid(frameValue);
return;
}
@Override
public boolean executeBoolean(VirtualFrame frameValue) {
return specialization_.executeBoolean(frameValue);
}
@Override
public SpecializationNode getSpecializationNode() {
return specialization_;
}
@Override
public Node deepCopy() {
return SpecializationNode.updateRoot(super.deepCopy());
}
@GeneratedBy(SLAssertTrueBuiltin.class)
private abstract static class BaseNode_ extends SpecializationNode {
protected final SLAssertTrueBuiltinNodeGen root;
BaseNode_(SLAssertTrueBuiltinNodeGen root, int index) {
super(index);
this.root = root;
}
@Override
protected final Node[] getSuppliedChildren() {
return new Node[] {root.arguments0_, root.arguments1_};
}
@Override
public final Object acceptAndExecute(Frame frameValue, Object arguments0Value, Object arguments1Value) {
return this.executeBoolean_((VirtualFrame) frameValue, arguments0Value, arguments1Value);
}
public abstract boolean executeBoolean_(VirtualFrame frameValue, Object arguments0Value, Object arguments1Value);
public Object execute(VirtualFrame frameValue) {
Object arguments0Value_ = executeArguments0_(frameValue);
Object arguments1Value_ = root.arguments1_.executeGeneric(frameValue);
return executeBoolean_(frameValue, arguments0Value_, arguments1Value_);
}
public void executeVoid(VirtualFrame frameValue) {
execute(frameValue);
return;
}
public boolean executeBoolean(VirtualFrame frameValue) {
return (boolean) execute(frameValue);
}
@Override
protected final SpecializationNode createNext(Frame frameValue, Object arguments0Value, Object arguments1Value) {
if (arguments0Value instanceof Boolean) {
if (arguments1Value instanceof String) {
return AssertNode_.create(root);
}
if (SLTypes.isSLNull(arguments1Value)) {
return AssertNullNode_.create(root);
}
}
return null;
}
@Override
protected final SpecializationNode createPolymorphic() {
return PolymorphicNode_.create(root);
}
protected final BaseNode_ getNext() {
return (BaseNode_) this.next;
}
protected final Object executeArguments0_(Frame frameValue) {
Class> arguments0Type_ = root.arguments0Type_;
try {
if (arguments0Type_ == boolean.class) {
return root.arguments0_.executeBoolean((VirtualFrame) frameValue);
} else if (arguments0Type_ == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
Class> _type = Object.class;
try {
Object _value = root.arguments0_.executeGeneric((VirtualFrame) frameValue);
if (_value instanceof Boolean) {
_type = boolean.class;
} else {
_type = Object.class;
}
return _value;
} finally {
root.arguments0Type_ = _type;
}
} else {
return root.arguments0_.executeGeneric((VirtualFrame) frameValue);
}
} catch (UnexpectedResultException ex) {
root.arguments0Type_ = Object.class;
return ex.getResult();
}
}
}
@GeneratedBy(SLAssertTrueBuiltin.class)
private static final class UninitializedNode_ extends BaseNode_ {
UninitializedNode_(SLAssertTrueBuiltinNodeGen root) {
super(root, 2147483647);
}
@Override
public boolean executeBoolean_(VirtualFrame frameValue, Object arguments0Value, Object arguments1Value) {
return (boolean) uninitialized(frameValue, arguments0Value, arguments1Value);
}
static BaseNode_ create(SLAssertTrueBuiltinNodeGen root) {
return new UninitializedNode_(root);
}
}
@GeneratedBy(SLAssertTrueBuiltin.class)
private static final class PolymorphicNode_ extends BaseNode_ {
PolymorphicNode_(SLAssertTrueBuiltinNodeGen root) {
super(root, 0);
}
@Override
public SpecializationNode merge(SpecializationNode newNode, Frame frameValue, Object arguments0Value, Object arguments1Value) {
return polymorphicMerge(newNode, super.merge(newNode, frameValue, arguments0Value, arguments1Value));
}
@Override
public boolean executeBoolean(VirtualFrame frameValue) {
Object arguments0Value_ = executeArguments0_(frameValue);
Object arguments1Value_ = root.arguments1_.executeGeneric(frameValue);
return getNext().executeBoolean_(frameValue, arguments0Value_, arguments1Value_);
}
@Override
public boolean executeBoolean_(VirtualFrame frameValue, Object arguments0Value, Object arguments1Value) {
return getNext().executeBoolean_(frameValue, arguments0Value, arguments1Value);
}
static BaseNode_ create(SLAssertTrueBuiltinNodeGen root) {
return new PolymorphicNode_(root);
}
}
@GeneratedBy(methodName = "doAssert(boolean, String)", value = SLAssertTrueBuiltin.class)
private static final class AssertNode_ extends BaseNode_ {
AssertNode_(SLAssertTrueBuiltinNodeGen root) {
super(root, 1);
}
@Override
public Object execute(VirtualFrame frameValue) {
return executeBoolean(frameValue);
}
@Override
public boolean executeBoolean(VirtualFrame frameValue) {
boolean arguments0Value_;
try {
arguments0Value_ = root.arguments0_.executeBoolean(frameValue);
} catch (UnexpectedResultException ex) {
Object arguments1Value = root.arguments1_.executeGeneric(frameValue);
return getNext().executeBoolean_(frameValue, ex.getResult(), arguments1Value);
}
String arguments1Value_;
try {
arguments1Value_ = SLTypesGen.expectString(root.arguments1_.executeGeneric(frameValue));
} catch (UnexpectedResultException ex) {
return getNext().executeBoolean_(frameValue, arguments0Value_, ex.getResult());
}
return root.doAssert(arguments0Value_, arguments1Value_);
}
@Override
public boolean executeBoolean_(VirtualFrame frameValue, Object arguments0Value, Object arguments1Value) {
if (arguments0Value instanceof Boolean && arguments1Value instanceof String) {
boolean arguments0Value_ = (boolean) arguments0Value;
String arguments1Value_ = (String) arguments1Value;
return root.doAssert(arguments0Value_, arguments1Value_);
}
return getNext().executeBoolean_(frameValue, arguments0Value, arguments1Value);
}
static BaseNode_ create(SLAssertTrueBuiltinNodeGen root) {
return new AssertNode_(root);
}
}
@GeneratedBy(methodName = "doAssertNull(boolean, SLNull)", value = SLAssertTrueBuiltin.class)
private static final class AssertNullNode_ extends BaseNode_ {
AssertNullNode_(SLAssertTrueBuiltinNodeGen root) {
super(root, 2);
}
@Override
public Object execute(VirtualFrame frameValue) {
return executeBoolean(frameValue);
}
@Override
public boolean executeBoolean(VirtualFrame frameValue) {
boolean arguments0Value_;
try {
arguments0Value_ = root.arguments0_.executeBoolean(frameValue);
} catch (UnexpectedResultException ex) {
Object arguments1Value = root.arguments1_.executeGeneric(frameValue);
return getNext().executeBoolean_(frameValue, ex.getResult(), arguments1Value);
}
SLNull arguments1Value_;
try {
arguments1Value_ = SLTypesGen.expectSLNull(root.arguments1_.executeGeneric(frameValue));
} catch (UnexpectedResultException ex) {
return getNext().executeBoolean_(frameValue, arguments0Value_, ex.getResult());
}
return root.doAssertNull(arguments0Value_, arguments1Value_);
}
@Override
public boolean executeBoolean_(VirtualFrame frameValue, Object arguments0Value, Object arguments1Value) {
if (arguments0Value instanceof Boolean && SLTypes.isSLNull(arguments1Value)) {
boolean arguments0Value_ = (boolean) arguments0Value;
SLNull arguments1Value_ = SLTypes.asSLNull(arguments1Value);
return root.doAssertNull(arguments0Value_, arguments1Value_);
}
return getNext().executeBoolean_(frameValue, arguments0Value, arguments1Value);
}
static BaseNode_ create(SLAssertTrueBuiltinNodeGen root) {
return new AssertNullNode_(root);
}
}
}
}