Package abstrasy.pcfx

Source Code of abstrasy.pcfx.PCFx_atomic_and_static

package abstrasy.pcfx;


import abstrasy.Node;
import abstrasy.PCoder;

/**
* Abstrasy Interpreter
*
* Copyright : Copyright (c) 2006-2012, Luc Bruninx.
*
* Concédée sous licence EUPL, version 1.1 uniquement (la «Licence»).
*
* Vous ne pouvez utiliser la présente oeuvre que conformément à la Licence.
* Vous pouvez obtenir une copie de la Licence à l’adresse suivante:
*
*   http://www.osor.eu/eupl
*
* Sauf obligation légale ou contractuelle écrite, le logiciel distribué sous
* la Licence est distribué "en l’état", SANS GARANTIES OU CONDITIONS QUELLES
* QU’ELLES SOIENT, expresses ou implicites.
*
* Consultez la Licence pour les autorisations et les restrictions
* linguistiques spécifiques relevant de la Licence.
*
*
* @author Luc Bruninx
* @version 1.0
*/

public class PCFx_atomic_and_static extends PCFx {

    public PCFx_atomic_and_static() {
    }

    private final static int getInteger(Node enode) throws Exception {
        if (enode.isNumber()) {
            return (int) enode.getNumber();
        }
        else {
            return (int) (Node.isTrueEquivalent(enode) ? Node.TRUE: Node.FALSE);
        }
    }

    /**
     * eval
     *
     * @param startAt Node
     * @return Node
     * @throws Exception
     * @todo Implémenter cette méthode abstrasy.PCFx
     */
    public Node eval(Node startAt) throws Exception {
        /*
         * Forme: (and! x v1 v2 ... vn)
         *        (and! x {lazy1} {lazy2} {lazy3} ... {lazyn})
         *
         * Réalise l'opération logique ET de façon statique et atomique sur la variable.
         *
         */
        int i = 1;
        startAt.isGoodArgsLength(false, 3);
        Node arg0 = startAt.getSubNode(i++, Node.TYPE_NUMBER | Node.VTYPE_DELEGABLE);

        if (arg0.isNumber()) {
            // nombre...

            arg0.requireAccessType(Node.ACCESSVTYPE_MUTABLE_WRITELOCK);

            /*
             * Soit -1 and n -> n...
             *
             * donc on peut appliquer aussi x and (-1 and v1 and v2 and ... and vn)...
             *
             * ou x and y avec y <- (-1 and v1 and v2 ... and vn)...
             *
             * De même si y = 0, on peut arrêter le traitement.
             *
             * C'est pourquoi la forme (and! x {lazy1} {lazy2} ... {lazyn}).
             *
             */

            int n = -1;
            while ((n != 0) && (i < startAt.size()))
                n = n & getInteger(startAt.getSubNode_LazyValue(i++, Node.TYPE_NUMBER));

            boolean loops = true;
            int nvalue;
            double ovalue2;
            double ovalue = arg0.getNumber();
            while (loops) {
                nvalue = ((int) ovalue) & n;
                ovalue2 = arg0.compareAndSwap_number(ovalue, nvalue);
                loops = ovalue2 != ovalue;
                ovalue = ovalue2;
            }
        }
        else //{
            // objet...
            //String method = PCoder.STATIC_AND_;
            //if (Node.VObject.hasSlot(arg0, method, Node.TYPE_FUNCTION))
                return Node.VDelegable.evalMethod(arg0, PCoder.getMethod(PCoder.PC_ATOMIC_AND_STATIC), startAt, i);
            //else
            //    throw new InterpreterException(StdErrors.extend(StdErrors.Function_required, method));
        //}
        return null;

    }

}
TOP

Related Classes of abstrasy.pcfx.PCFx_atomic_and_static

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.