boot-truffle/src/main/java/net/java/html/boot/truffle/IsArrayNode.java
author Jaroslav Tulach <jtulach@netbeans.org>
Thu, 21 Jul 2016 10:20:52 +0200
branchTruffle
changeset 1101 1c4559516918
parent 1098 20246cbd02c3
permissions -rw-r--r--
Send hasSize message
jtulach@1096
     1
/**
jtulach@1096
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
jtulach@1096
     3
 *
jtulach@1096
     4
 * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
jtulach@1096
     5
 *
jtulach@1096
     6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
jtulach@1096
     7
 * Other names may be trademarks of their respective owners.
jtulach@1096
     8
 *
jtulach@1096
     9
 * The contents of this file are subject to the terms of either the GNU
jtulach@1096
    10
 * General Public License Version 2 only ("GPL") or the Common
jtulach@1096
    11
 * Development and Distribution License("CDDL") (collectively, the
jtulach@1096
    12
 * "License"). You may not use this file except in compliance with the
jtulach@1096
    13
 * License. You can obtain a copy of the License at
jtulach@1096
    14
 * http://www.netbeans.org/cddl-gplv2.html
jtulach@1096
    15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
jtulach@1096
    16
 * specific language governing permissions and limitations under the
jtulach@1096
    17
 * License.  When distributing the software, include this License Header
jtulach@1096
    18
 * Notice in each file and include the License file at
jtulach@1096
    19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
jtulach@1096
    20
 * particular file as subject to the "Classpath" exception as provided
jtulach@1096
    21
 * by Oracle in the GPL Version 2 section of the License file that
jtulach@1096
    22
 * accompanied this code. If applicable, add the following below the
jtulach@1096
    23
 * License Header, with the fields enclosed by brackets [] replaced by
jtulach@1096
    24
 * your own identifying information:
jtulach@1096
    25
 * "Portions Copyrighted [year] [name of copyright owner]"
jtulach@1096
    26
 *
jtulach@1096
    27
 * Contributor(s):
jtulach@1096
    28
 *
jtulach@1096
    29
 * The Original Software is NetBeans. The Initial Developer of the Original
jtulach@1096
    30
 * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
jtulach@1096
    31
 *
jtulach@1096
    32
 * If you wish your version of this file to be governed by only the CDDL
jtulach@1096
    33
 * or only the GPL Version 2, indicate your decision by adding
jtulach@1096
    34
 * "[Contributor] elects to include this software in this distribution
jtulach@1096
    35
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
jtulach@1096
    36
 * single choice of license, a recipient has the option to distribute
jtulach@1096
    37
 * your version of this file under either the CDDL, the GPL Version 2 or
jtulach@1096
    38
 * to extend the choice of license to its licensees as provided above.
jtulach@1096
    39
 * However, if you add GPL Version 2 code and therefore, elected the GPL
jtulach@1096
    40
 * Version 2 license, then the option applies only if the new code is
jtulach@1096
    41
 * made subject to such option by the copyright holder.
jtulach@1096
    42
 */
jtulach@1096
    43
package net.java.html.boot.truffle;
jtulach@1096
    44
jtulach@1096
    45
import com.oracle.truffle.api.TruffleLanguage;
jtulach@1096
    46
import com.oracle.truffle.api.frame.VirtualFrame;
jtulach@1096
    47
import com.oracle.truffle.api.interop.ForeignAccess;
jtulach@1096
    48
import com.oracle.truffle.api.interop.Message;
jtulach@1096
    49
import com.oracle.truffle.api.interop.TruffleObject;
jtulach@1096
    50
import com.oracle.truffle.api.nodes.Node;
jtulach@1096
    51
import com.oracle.truffle.api.nodes.RootNode;
jtulach@1096
    52
jtulach@1098
    53
final class IsArrayNode extends RootNode {
jtulach@1096
    54
    @Child
jtulach@1098
    55
    private Node check;
jtulach@1096
    56
jtulach@1098
    57
    IsArrayNode() {
jtulach@1096
    58
        super(TruffleLanguage.class, null, null);
jtulach@1098
    59
        this.check = Message.HAS_SIZE.createNode();
jtulach@1096
    60
    }
jtulach@1096
    61
jtulach@1096
    62
    @Override
jtulach@1096
    63
    public Object execute(VirtualFrame frame) {
jtulach@1098
    64
        final Object[] args = frame.getArguments();
jtulach@1101
    65
        Object result = ForeignAccess.sendHasSize(check, frame, (TruffleObject) args[0]);
jtulach@1098
    66
        return result;
jtulach@1096
    67
    }
jtulach@1096
    68
}