Package abstrasy

Examples of abstrasy.Interpreter


        startAt.isGoodArgsCnt(4);
        Node func = startAt.getSubNode(3, Node.TYPE_FUNCTION);
        Node res = startAt.getSubNode(2, Node.VTYPE_VALUABLE);
        Node src = startAt.getSubNode(1, Node.TYPE_CLIST | Node.TYPE_FUNCTION);
        Node expr = Node.createExpr();
        Interpreter interpreter = Interpreter.mySelf();
        boolean oldTailNode = interpreter.isTailNode();
        boolean oldTerminalNode = interpreter.isTerminalNode();
        Exception allExcep=null;
        try{
        if (src.getQType()==Node.TYPE_CLIST) {
            /**
             * la source est une liste...
             */
            for (int i = 0; i < src.size(); i++) {
                interpreter.setTailNode(false);
                interpreter.setTerminalNode(false);
                res = expr.append(func).append(src.elementAt(i)).append(res).exec(true);
                expr.clearChilds();
            }
        }
        else {
            /**
             * la source est une foction génératrice de séquence...
             */
            int n = 0;
            Node fxarg = new Node(n).letFinal(true);
            Node fxn = Node.createExpr().append(src).append(fxarg);
            Node tmpfxn = fxn; // juste pour qu'il ne soit pas null...
            while (tmpfxn != null) {
                fxarg.setNumber(n++);
                interpreter.setTailNode(false);
                interpreter.setTerminalNode(false);
                tmpfxn = fxn.exec(true);
                if (tmpfxn != null) {
                    interpreter.setTailNode(false);
                    interpreter.setTerminalNode(false);
                    res = expr.append(func).append(tmpfxn).append(res).exec(true);
                    expr.clearChilds();
                }
            }

        }
        }
        catch(Exception ex){
            allExcep=ex;
        }
        interpreter.setTailNode(oldTailNode);
        interpreter.setTerminalNode(oldTerminalNode);
        if(allExcep!=null){ throw allExcep; }
        return res;

    }
View Full Code Here


        }   
        Row row = new Row(rings,maxW);
       
        Node btype = startAt.getSubNode(i++, Node.TYPE_PCODE);
        Node enode = startAt.getSubNode(i++, Node.TYPE_LAZY);
        Interpreter interpreter = Interpreter.mySelf();
        boolean oldCanLoop = interpreter.isCanLoop();
        boolean oldInLoop = interpreter.isInLoop();
        interpreter.setCanLoop(true);
        interpreter.setInLoop(true);

        try {
            if (btype.isPCode(PCoder.PC_DO)) {
                /**
                 * (foreach-col [[l1]...[ln]] do {...})
                 */
                Node argv;

                Heap.push(); // nouvel espace local pour argv (exclusivment)
                Heap argv_h = Heap.current(); // optimisation du 09/03/2012
               
                Heap.push(); // nouvel espace local
                Heap local = Heap.current();

                /*
                 * Correction du 10 mai 2011:
                 * =========================
                 *    Les boucles du type do{...} s'arrête dès qu'un résultat est retourné. Cela ne signifie
                 *    bien entendu pas que la condition qui permet l'itération n'est pas vérifiée. Toutefois,
                 *    comme les boucle du type do{...} ne peuvent retourner qu'un seul résultat, il est inutile
                 *    de relancer l'itération suivante ddès qu'un résultat est fourni. Ainsi, pour permettre
                 *    de continuer la boucle, il est possible de placer le résultat dans une variable et non de
                 *    la retourner directement comme résultat.
                 *   
                 */
                while (interpreter.isCanIterate() && row.hasNext() && xnode==null) {
                    _clear_closure_(local);
                    argv = Node.createCList();
                    argv.setArray(row.getNext());
                    argv_h.put(PCoder.ARGV, argv);
                    xnode = enode.exec(true);
                }

                Heap.pull(); // supprimer l'espace local...
                Heap.pull(); // supprimer espace pour argv...

            }
            else if (btype.isPCode(PCoder.PC_LIST)) {
                /**
                 * (foreach-col [[l1]...[ln]] list{...})
                 */
                Node argv;
                xnode = Node.createCList();

                Heap.push(); // nouvel espace local pour argv (exclusivment)
                Heap argv_h = Heap.current(); // optimisation du 09/03/2012

                Heap.push(); // nouvel espace local
                Heap local = Heap.current();

                while (interpreter.isCanIterate() && row.hasNext()) {
                    _clear_closure_(local);
                    argv = Node.createCList();
                    argv.setArray(row.getNext());
                    argv_h.put(PCoder.ARGV, argv);
                    rnode = enode.exec(true);
                    if (rnode != null)
                        xnode.addElement(rnode.secure());
                   
                }

                Heap.pull(); // supprimer l'espace local...
                Heap.pull(); // supprimer espace pour argv...

            }
            else {
                // erreur de syntaxe.
                throw new InterpreterException(StdErrors.Syntax_error);
            }
        }
        catch (Exception ex) {
            interpreter.consumeBreakCode_onLoop();
            interpreter.setCanLoop(oldCanLoop);
            interpreter.setInLoop(oldInLoop);
            throw ex;
        }
        interpreter.consumeBreakCode_onLoop();
        interpreter.setCanLoop(oldCanLoop);
        interpreter.setInLoop(oldInLoop);
        return xnode;
    }
View Full Code Here

         * forme: (timed <millis> {...})
         */
        startAt.isGoodArgsLength(true, 3);
        Node tnode = startAt.getSubNode(1, Node.TYPE_NUMBER);
        Node xnode = startAt.getSubNode(2, Node.TYPE_LAZY);
        Interpreter myself = Interpreter.mySelf();
        long old_deadlockTime = myself.getDeadlockTime();
        boolean old_timeOutCheck = myself.isTimeOutCheck();
        boolean old_timeOutTimerStatus = myself.getTimeOutTimer().isRunning();
        if (old_timeOutCheck || old_timeOutTimerStatus) {
            myself.setTimeOutCheck(false);
            myself.getTimeOutTimer().stop();
        }
        Interpreter interpreter = Interpreter.mySelf();
        BaseContextSnapshot contextSnapshot=new BaseContextSnapshot(interpreter);
        long delayed = (long) tnode.getNumber();
        if (delayed < 0) {
            throw new InterpreterException(StdErrors.Out_of_range);
        }
View Full Code Here

     * @throws Exception
     * @todo Implémenter cette méthode abstrasy.PCFx
     */
    public Node eval(Node startAt) throws Exception {
        startAt.isGoodArgsCnt(1);
        Interpreter interpreter = Interpreter.mySelf();
    if (!interpreter.isTerminalNode()){
      throw new InterpreterException(StdErrors.Abort_misplaced);
    }
       
        throw new AbortException(startAt);
      
View Full Code Here

   * @todo Implémenter cette méthode abstrasy.PCFx
   */
  public Node eval(Node startAt) throws Exception {
    startAt.isGoodArgsCnt(2);
    String target = startAt.getSubNode(1, Node.TYPE_STRING).getString();
    Interpreter myself = Interpreter.mySelf();
    InterpreterSemaphore sema = Interpreter.getSemaphore();
    Interpreter amie = sema.getThread(target);
    if (amie == myself) {
      throw new InterpreterException(StdErrors.An_actor_can_not_resume_himself);
    }
    if (amie != null) {
      sema.resume(amie);
View Full Code Here

        }   
        Row row = new Row(rings);
       
        Node btype = startAt.getSubNode(i++, Node.TYPE_PCODE);
        Node enode = startAt.getSubNode(i++, Node.TYPE_LAZY);
        Interpreter interpreter = Interpreter.mySelf();
        boolean oldCanLoop = interpreter.isCanLoop();
        boolean oldInLoop = interpreter.isInLoop();
        interpreter.setCanLoop(true);
        interpreter.setInLoop(true);

        try {
            if (btype.isPCode(PCoder.PC_DO)) {
                /**
                 * (foreach-col [[l1]...[ln]] do {...})
                 */
                Node argv;
               
                Heap.push(); // nouvel espace local pour argv (exclusivment)
                Heap argv_h = Heap.current(); // optimisation du 09/03/2012

                Heap.push(); // nouvel espace local
                Heap local = Heap.current();

                /*
                 * Correction du 10 mai 2011:
                 * =========================
                 *    Les boucles du type do{...} s'arrête dès qu'un résultat est retourné. Cela ne signifie
                 *    bien entendu pas que la condition qui permet l'itération n'est pas vérifiée. Toutefois,
                 *    comme les boucle du type do{...} ne peuvent retourner qu'un seul résultat, il est inutile
                 *    de relancer l'itération suivante ddès qu'un résultat est fourni. Ainsi, pour permettre
                 *    de continuer la boucle, il est possible de placer le résultat dans une variable et non de
                 *    la retourner directement comme résultat.
                 *   
                 */
                while (interpreter.isCanIterate() && row.hasNext() && xnode==null) {
                    _clear_closure_(local);
                    argv = Node.createCList();
                    argv.setArray(row.getNext());
                    argv_h.put(PCoder.ARGV, argv);
                    xnode = enode.exec(true);
                }

                Heap.pull(); // supprimer l'espace local...
                Heap.pull(); // supprimer l'espace de noms exclusif pour argv.

            }
            else if (btype.isPCode(PCoder.PC_LIST)) {
                /**
                 * (foreach-col [[l1]...[ln]] list{...})
                 */
                Node argv;
                xnode = Node.createCList();

                Heap.push(); // nouvel espace local pour argv (exclusivment)
                Heap argv_h = Heap.current(); // optimisation du 09/03/2012
               
                Heap.push(); // nouvel espace local
                Heap local = Heap.current();

                while (interpreter.isCanIterate() && row.hasNext()) {
                    _clear_closure_(local);
                    argv = Node.createCList();
                    argv.setArray(row.getNext());
                    argv_h.put(PCoder.ARGV, argv);
                    rnode = enode.exec(true);
                    if (rnode != null)
                        xnode.addElement(rnode.secure());
                   
                }

                Heap.pull(); // supprimer l'espace local...
                Heap.pull(); // supprimer l'espace exclusif pour argv...

            }
            else {
                // erreur de syntaxe.
                throw new InterpreterException(StdErrors.Syntax_error);
            }
        }
        catch (Exception ex) {
            interpreter.consumeBreakCode_onLoop();
            interpreter.setCanLoop(oldCanLoop);
            interpreter.setInLoop(oldInLoop);
            throw ex;
        }
        interpreter.consumeBreakCode_onLoop();
        interpreter.setCanLoop(oldCanLoop);
        interpreter.setInLoop(oldInLoop);
        return xnode;
    }
View Full Code Here

        // résultat...
        Node res = null;

        //
        Interpreter interpreter = Interpreter.mySelf();

        /*
         * récupération de la liste des règles
         */
        Node liste_r = startAt.getSubNode(1, Node.TYPE_CLIST);

        /*
         * rechercher la description de la fermeture s'il y en a une...
         */
        Node with_cache = null;
        if (size == 4) {
            startAt.requirePCode(2,PCoder.PC_WITH);
            /*
             * il y a une fermeture...
             */
            with_cache = startAt.getSubNode(3, Node.TYPE_LAZY);
            fermeture = new Heap();
        }
    
           
        /**
         * protection du système...
         */
        BaseContextSnapshot contextSnapShot = new BaseContextSnapshot(interpreter);


        /**
         * boucle principale...
         */

        interpreter.setCanLoop(true);
        interpreter.setInLoop(true);

        Exception allExcep = null;
        try {

            /**
             * Lecture des règles...
             *
             */
            for (int i = 0; i < liste_r.size(); i++) {
                Node elem_r = liste_r.getSubNode(i, Node.TYPE_QEXPR);
                addRules(rules, elem_r);
            }

            /**
             * On va commencé la boucle d'inférence...
             */
            // placer la fermeture s'il y en a une...
            if(fermeture!=null){
                Heap.push(fermeture);
                with_cache.exec(true);
            }
            // préparer le heap local pour le traitement...
            Heap.push();
            Heap local = Heap.current();

            // préparer la boucle d'inférence...
            int verif;
            do {
                verif = 0;
                int i = 0;
                while (i < rules.size() && interpreter.hasNoBreakCode()) {
                    /*
                     * Conserver rules.size() la taille pouvant être modifiée en cours d'évaluation.
                     * De plus, en cas de code break quelconque, on s'arrête (skip-loop) et (break-loop).
                     * Par contre dans le cas de (complete-loop) on termine l'analyse de l'ensemble des règles
                     * avant d'arrêter.
                     */
                    Rule rule = (Rule) rules.get(i);
                    if (Node.isTrueEquivalent(evalSection(local, rule.condition))) {
                        /*
                         * condition vérifiée... On traite la partie then...
                         */
                        verif++;
                        res = evalSection(local, rule.getConsequenceThen().getSymbolicValue()); // évaluation pareseuse des symboles...
                        if (res != null) {
                            break;
                        }
                        if (rule.getRuleType() == PCoder.PC_ONCE) {
                            // once : supprimer la règle (l'index actuel pointe donc sur la règle suivante)
                            rules.remove(i);
                        }
                        else {
                            // each-time : on ne supprime pas la règle et on passe à la suivante
                            i++;
                        }
                    }
                    else if (rule.getConsequenceElse() != null) {
                        // étant donné le parsing précédent, pas besoin de valider: il ne peut s'agir que de each-time...
                        /*
                         * si pas vérifié et qu'il y a une clause else... On traite la partie else...
                         */
                        verif++;
                        res = evalSection(local, rule.getConsequenceElse().getSymbolicValue()); // évaluation paresseuse des symboles...
                        if (res != null) {
                            break;
                        }
                        // on ne peut avoir ici que each-time -> on ne supprime pas la règle et on passe à la suivante
                        i++;
                    }
                    else {
                        /*
                         * si pas vérifié et pas de else... On passe alors au suivant...
                         */
                        i++;
                    }
                }
            }
            while (verif > 0 && res == null && interpreter.isCanIterate());
            /*
             * Si (skip-loop), on repart...
             * Si (complete-loop), on s'arrête...
             * Si (break-loop), on s'arrête aussi...
             */
 
View Full Code Here

     * @throws Exception
     */
    public static Node create_object(Node symClassNode,Node postInit, Node startAt) throws Exception {

    Node objectNode;
    Interpreter interpreter = Interpreter.mySelf();
    BaseContextSnapshot contextSnapshot = new BaseContextSnapshot(interpreter);

    try {
      /*
             * Instanciation de la classe et exécution du constructeur...
View Full Code Here

     * @todo Implémenter cette méthode abstrasy.PCFx
     */
    public Node eval(Node startAt) throws Exception {
        startAt.isGoodArgsCnt(2);
        String target = startAt.getSubNode(1, Node.TYPE_STRING).getString();
        Interpreter myself = Interpreter.mySelf();
        InterpreterSemaphore sema = Interpreter.getSemaphore();
        Interpreter amie = sema.getThread(target);
        if (amie == null) {
            throw new InterpreterException(StdErrors.extend(StdErrors.Actor_not_found, target));
        }
        else {
            return new Node(amie.isThreadSuspended() ? Node.TRUE: Node.FALSE);
        }
    }
View Full Code Here

        Node res = null;
       
        /*
         * obtenir les paramètres avant le début de l'exécution de la section insure{...} ...
         */
        Interpreter interpreter = Interpreter.mySelf();
        BaseContextSnapshot contextSnapshot=new BaseContextSnapshot(interpreter);

        Exception allExcep = null;

        /*
         * exécuter la section hook et capturer une éventuelle exception...
         */
        try {
            Heap.push();
            res = xnode.exec(true);
            Heap.pull();
        }
        catch (Exception ex) {
            allExcep = ex;
        }

        /*
         * On doit rétablir un environnement exécutable suffisament stable même en cas de
         * suppression ou d'exception grave...
         *
         * La premère chose à faire consiste à bloquer temporairement l'action, si on est
         * dans une section temporisée...
         */
        long old_deadlockTime_after = interpreter.getDeadlockTime();
        boolean old_timeOutCheck_after = interpreter.isTimeOutCheck();
        boolean old_timeOutTimerStatus_after = interpreter.getTimeOutTimer().isRunning();
        if (old_timeOutCheck_after || old_timeOutTimerStatus_after) {
            interpreter.setTimeOutCheck(false);
            interpreter.getTimeOutTimer().stop();
        }
       
        boolean canloop_after = interpreter.isCanLoop();
        boolean inloop_after = interpreter.isInLoop();
        long callerSignature_after = interpreter.getCallerSignature();
        boolean tailNode_after = interpreter.isTailNode();
        boolean terminalNode_after = interpreter.isTerminalNode();
        Node oldThisNode_after = interpreter.getThisFunction();
        Node oldWrapperNode_after = interpreter.getWrapperFunction();
        Node oldSelfNode_after = interpreter.getSelf();
        Node oldRootNode_after = interpreter.getRoot();
        Node oldIfaceNode_after = interpreter.getIface();
        boolean stop_status_after = interpreter.isThreadStopped();
 
        boolean breakingFromSemaphore_after = interpreter.isBreakingFromSEMAPHORE();
        boolean endingFromSemaphore_after = interpreter.isEndingFromSEMAPHORE();
       
        int old_equStackLock_A = interpreter.getEquStack_A().lock();
        int old_equStackLock_B = interpreter.getEquStack_B().lock();
       
        int old_compareStackLock_A = interpreter.getCompareStack_A().lock();
        int old_compareStackLock_B = interpreter.getCompareStack_B().lock();
       
        /*
         * Restaurer les paramètres qui ont précédé l'exécution de la section insure...
         *
         * En cas de problème grave on rétabli les fonctionnlité de base...
         */
        contextSnapshot.restore();
       

        /*
         * Si l'acteur est en état de suppression...
         *
         * Passe en mode Fail-over...
         */
        boolean old_failOver=interpreter.isFailOver();
        interpreter.setFailOver(true);
       
        /*
         * exécuter termination{...}...
         */
        Node tres=null;
        try{
            Heap.push();
            tres=enode.exec(true);
            Heap.pull();
        }
        catch(Exception e){
            Interpreter.Log("Exception in termination:\n"+e);
        }
        if(tres!=null){
            Interpreter.Log("Result value of termination:\n"+tres.toString());
        }
       
        /*
         * De nouveau, si la pile n'est pas correctement rétablie...
         */
        contextSnapshot.restoreGlobalOnly();
       
        /*
         * restaurer les paramètres qui ont précédé l'exécution de la section A...
         *
         * Ceux-ci peuvent être traités par un (try{...} catch{...})
         */
        interpreter.setCanLoop(canloop_after);
        interpreter.setInLoop(inloop_after);
       
        interpreter.setCallerSignature(callerSignature_after);
        interpreter.setTailNode(tailNode_after);
        interpreter.setTerminalNode(terminalNode_after);
        interpreter.setThisFunction(oldThisNode_after);
        interpreter.setWrapperFunction(oldWrapperNode_after);
        interpreter.setSelf(oldSelfNode_after);
        interpreter.setRoot(oldRootNode_after);
        interpreter.setIface(oldIfaceNode_after);
       
        interpreter.getEquStack_A().unlock(old_equStackLock_A);
        interpreter.getEquStack_B().unlock(old_equStackLock_B);
       
        interpreter.getCompareStack_A().unlock(old_compareStackLock_A);
        interpreter.getCompareStack_B().unlock(old_compareStackLock_B);
       
        /*
         * Restaurer le système de timer...
         */
        interpreter.setDeadlockTime(old_deadlockTime_after);
        interpreter.setTimeOutCheck(old_timeOutCheck_after);
        if (old_timeOutCheck_after || old_timeOutTimerStatus_after) {
            interpreter.setTimeOutCheck(true);
            interpreter.getTimeOutTimer().start();
        }
       
        /*
         * Rétablir les états de suppression de l'acteur...
         *
         * Cette partie doit notamment tenir compte de (exit).
         *
         * Combinaison des états avant/après inclusive...
         *
         */
        interpreter.setThreadStopped(stop_status_after || interpreter.isThreadStopped());
        interpreter.setBreakingFromSEMAPHORE(breakingFromSemaphore_after || interpreter.isBreakingFromSEMAPHORE());
        interpreter.setEndingFromSEMAPHORE(endingFromSemaphore_after || interpreter.isEndingFromSEMAPHORE());
        interpreter.setTimeOutRaising(old_timeOutCheck_after);
       
        /*
         * enlever le fail-over...
         */
        interpreter.setFailOver(old_failOver);
       
        /*
         * Reporter l'exception initiale...
         */
        if(allExcep!=null){
            /*
             * déclencher l'exception capturée...
             */
            throw allExcep;
        }
        else{
            interpreter.throwInterThreadException();
        }
       
        /*
         * Si tout s'est bien passé, on continue sans souci...
         */
 
View Full Code Here

TOP

Related Classes of abstrasy.Interpreter

Copyright © 2018 www.massapicom. 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.