Package abstrasy

Examples of abstrasy.Interpreter


        }   
        Product product = new Product(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-all-different [l1] [l2]...[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() && product.hasNext() && xnode==null) {
                    _clear_closure_(local);
                    argv = Node.createCList();
                    argv.setArray(product.getNext());
                    argv_h.put(PCoder.ARGV, argv);   // argv peut être assigner de cette manière (il est dans un espace de noms exclusif)...
                    xnode = enode.exec(true);
                }

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

            }
            else if (btype.isPCode(PCoder.PC_LIST)) {
                /**
                 * (foreach-all-different[l1] [l2]...[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() && product.hasNext()) {
                    _clear_closure_(local);
                    argv = Node.createCList();
                    argv.setArray(product.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


                throw new InterpreterException(StdErrors.Syntax_error);
            }
            boolean untilLoop = modenode.isPCode(PCoder.PC_UNTIL);
            Node enode = startAt.getSubNode(1, Node.TYPE_LAZY);

            Interpreter interpreter = Interpreter.mySelf();
            StaticHeap global = interpreter.getGLOBAL();
            boolean oldCanLoop = interpreter.isCanLoop();
            boolean oldInLoop = interpreter.isInLoop();
            interpreter.setCanLoop(true);
            interpreter.setInLoop(true);


            //
            int href = global.size();
            int slock = global.getOffset();
            try {

                //
                boolean loop = true;
                while (loop && interpreter.isCanIterate()) {

                    global.push();
                    rnode = enode.exec(true);
                    global.pull();

                    if (rnode != null)
                        xnode.addElement(rnode.secure());
                   
                    loop = (untilLoop ? !xPC_Condition(global, cnode): xPC_Condition(global, cnode));
                }
                //
            }
            catch (Exception ex) {
                interpreter.consumeBreakCode_onLoop();
                interpreter.setCanLoop(oldCanLoop);
                interpreter.setInLoop(oldInLoop);
                throw ex;
            }

            if (global.size() != href) {
                global.setOffset(slock);
                global.setSize(href); // restaurer le heap à la bonne taille
            }
            //
            interpreter.consumeBreakCode_onLoop();
            interpreter.setCanLoop(oldCanLoop);
            interpreter.setInLoop(oldInLoop);
            return xnode;

        }
        else {
View Full Code Here

        Node anode=null;
       
        /**
         * il doit s'agir d'un tail-node !
         */
        Interpreter interpreter = Interpreter.mySelf();
    if (!interpreter.isTerminalNode()){
      throw new InterpreterException(StdErrors.Restart_misplaced);
    }
       
        /**
         * analyse des arguments...
         */
        switch(startAt.size()){
            case 1: /* forme (restart) */
                break;
            case 2:
                xnode=startAt.getSubNode(1, Node.TYPE_LAZY|Node.TYPE_CLIST);
                if(!xnode.isLazy()){
                    // si ce n'est pas une lazy, c'est une liste...
                    anode=xnode;
                    xnode=null;
                }
                break;
            case 3:
                xnode=startAt.getSubNode(1, Node.TYPE_LAZY);
                anode=startAt.getSubNode(2, Node.TYPE_CLIST);
                break;
            default:
                /**
                 * problème...
                 */
                throw new InterpreterException(StdErrors.Argument_count_mismatch);
        }
   
        throw interpreter.getRestartException(startAt,xnode,anode);
      
    }
View Full Code Here

        }
        if (in != null) {
            try {
                in.load();
                msrc = in.getSource();
                Interpreter interpreter = Interpreter.interpr_getNewChildInterpreter();
                //Register continue dans le même thread...
                Heap.push(); // mais en créant une closure
                interpreter.setSource(msrc);
                interpreter.compile();
                Node res = interpreter.getNode().exec(false);
                Heap.pull();

                return res;

            }
View Full Code Here

  public Node eval(Node startAt) throws Exception {
        /*
         * forme: (skip-loop)
         */
    startAt.isGoodArgsCnt(1);
    Interpreter interpreter = Interpreter.mySelf();
        //System.out.println("skip-loop "+ interpreter.isCanLoop() +" "+ interpreter.isTailNode());
    if (!(interpreter.isCanLoop() && interpreter.isTailNode())) {
      throw new InterpreterException(StdErrors.Skip_loop_misplaced);
    }
    interpreter.setBreakCode(Interpreter.BREAKCODE_LOOP);
    return null;

  }
View Full Code Here

        long time = (long) xnode.getNumber();
        if (time < 0) {
            throw new InterpreterException(StdErrors.Timed_expired_exception);
        }
       
        Interpreter myself=Interpreter.mySelf();
        /**
         * Le programmeur devrait pouvoir utiliser tous les systèmes en même temps:
         * =======================================================================
         * - mutex permet de gérer l'exclusion mutuelle des processus.
         * - lock, sync et share permettent de gérer l'exclusion mutuelle d'accès (éventuellement réentrant R/W)
         *   aux variables partages.
         * - sleep, suspend, resume et kill l'activité d'un processus.
         * - send, receive et postpone les échanges de messages entre processus.
         *
         * Chaque système dispose des ses propres caractéristiques. C'est au programmeur des les utiliser correctement
         * (c-à-d, d'une façon raisonnable).
         *
        // dans une section critique ?...
        if (myself.actor_ISMUTEX()) {
            throw new InterpreterException(StdErrors.Illegal_operation_in_mutex_section);
        }
         *
         *
        // dans une section atomic ?
        if(myself.actor_ISLOCKEDSECTION()){
            throw new InterpreterException(StdErrors.Illegal_operation_in_critical_section);   
        }
        *
        */
        try {
            Interpreter.getSemaphore().sleep(time);

        }
        catch (InterruptedException e) {
            Interpreter.Log("Interrupted... SEMAPHORE MSG");
            throw new SilentException();
        }
        myself.throwInterThreadException();
       
        return null;

    }
View Full Code Here

   * @throws Exception
   * @todo Implémenter cette méthode abstrasy.PCFx
   */
  public Node eval(Node startAt) throws Exception {
    startAt.isGoodArgsCnt(1,2);
    Interpreter interpreter = Interpreter.mySelf();
    //Node rnode=null;
      //
    //System.out.println("Return getCallerSignature :" + interpreter.getCallerSignature());
    if ((!interpreter.isTerminalNode()) || interpreter.getCallerSignature()==0){
      // il ne devrait pas y avoir de signature GUID = 0...
      // si c'est le cas, c'est que qu'aucune fonction n'a été appelée...
      throw new InterpreterException(StdErrors.Return_misplaced);
    }
   
    if (startAt.size() == 2) {
      // s'il y a un résultat à retourner
      Node rnode=startAt.elementAt(1);
      try{
        Heap.setRETURN(rnode);
      }
      catch(Exception ex){
        throw new InterpreterException(StdErrors.Return_register_error);
      }
    }
      //

    if(interpreter.getBreakCode()!=Interpreter.BREAKCODE_TAIL){
      interpreter.setBreakCode(Interpreter.BREAKCODE_RETURN);
    }
    return null;
  }
View Full Code Here

   * @throws Exception
   * @todo Implémenter cette méthode abstrasy.PCFx
   */
  public Node eval(Node startAt) throws Exception {
    startAt.isGoodArgsLength(true, 1);
    Interpreter interpreter = Interpreter.mySelf();
   return new Node( (interpreter.isCanLoop()) ? Node.FALSE: Node.TRUE );
  }
View Full Code Here

         * Le générateur est appelé (fx 1) : L'argument 1 indique au générateur qu'il doit fournir la valeur suivante.
         *
         */
        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 xxx do {...})
                 */
                int nlist = 0;
                Node argv;
                /*
                 * un Heap rien que pour recevoir argv...
                 */
                Heap.push(); // nouvel espace local
                Heap argv_h=Heap.current(); // optimisation du 09/03/2012...
               
                /**
                 * Pour allez plus vite, on défini une section pour les 2 sources possibles...
                 * De cette manière on diminue un peu le nombre de tests à réaliser...
                 */
                if (lNode.getQType()==Node.TYPE_CLIST) {
                    /**
                     * une liste...
                     */
                    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() && (nlist < lNode.size()) && xnode==null) {
                        _clear_closure_(local);
                        Node tmpn = lNode.elementAt(nlist);
                        argv = Node.createCList();
                        argv.addElement(tmpn); // argv0 = element
                        argv.addElement(new Node(nlist++)); // argv1 = index
                        argv_h.put(PCoder.ARGV, argv); // optimisation du 09/03/2012... (argv peut être fixé de cette manière - son espace est exclusif)
                        xnode = enode.exec(true);
                    }
                    Heap.pull(); // supprimer l'espace local...
                }
                else {
                    /**
                     * un générateur...
                     */
                    Node tmpn = lNode; // différent de null... pour commencer...
                    Node fxarg=new Node(0).letFinal(true);
                    Node fxn = Node.createExpr().append(lNode).append(fxarg);
                    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() && tmpn != null && xnode==null) {
                        fxarg.setNumber(nlist);
                        _clear_closure_(local);
                        tmpn = fxn.exec(true);
                        if (tmpn != null) {
                            local.clear();
                            argv = Node.createCList();
                            argv.addElement(tmpn); // argv0 = element
                            argv.addElement(new Node(nlist++)); // argv1 = index
                            argv_h.put(PCoder.ARGV, argv); // optimisation du 09/03/2012...
                            xnode = enode.exec(true);  
                        }   
                    }

                    Heap.pull(); // supprimer l'espace local...
                }
               
                Heap.pull(); // supprimer l'espace pour argv... // optimisation du 09/03/2012...
               
            }
            else if (btype.isPCode(PCoder.PC_LIST)) {
                /**
                 * (foreach xxx list{...})
                 */
                int nlist = 0;
                Node argv;
                xnode = Node.createCList();
               
                /*
                 * un Heap rien que pour recevoir argv...
                 */
                Heap.push(); // nouvel espace local
                Heap argv_h=Heap.current(); // optimisation du 09/03/2012...
               
                /**
                 * Pour allez plus vite, on défini une section pour les 2 sources possibles...
                 * De cette manière on diminue un peu le nombre de tests à réaliser...
                 */
                if (lNode.getQType()==Node.TYPE_CLIST) {
                    /**
                     * une liste...
                     */
                    Heap.push(); // nouvel espace local
                    Heap local=Heap.current();
                   
                    while (interpreter.isCanIterate() && (nlist < lNode.size())) {
                        _clear_closure_(local);
                        argv = Node.createCList();
                        Node tmpn = lNode.elementAt(nlist);
                        argv.addElement(tmpn); // argv0 = element
                        argv.addElement(new Node(nlist++)); // argv1 = index
                        argv_h.put(PCoder.ARGV, argv); // optimisation du 09/03/2012...
                        rnode = enode.exec(true);
                        if (rnode != null)
                            xnode.addElement(rnode.secure());
                       
                    }
                   
                    Heap.pull(); // supprimer l'espace local...
                }
                else {
                    /**
                     * un générateur...
                     */
                    Node tmpn = lNode; // différent de null... pour commencer...
                    Node fxarg=new Node(0).letFinal(true);
                    Node fxn = Node.createExpr().append(lNode).append(fxarg);
                    Heap.push(); // nouvel espace local
                    Heap local=Heap.current();
                   
                    while (interpreter.isCanIterate() && tmpn != null) {
                        fxarg.setNumber(nlist);
                        _clear_closure_(local);
                        tmpn = fxn.exec(true);
                        if (tmpn != null) {
                            argv = Node.createCList();
                            argv.addElement(tmpn); // argv0 = element
                            argv.addElement(new Node(nlist++)); // argv1 = index
                            local.clear();
                            argv_h.put(PCoder.ARGV, argv); // optimisation du 09/03/2012...
                            rnode = enode.exec(true);
                            if (rnode != null) {
                                xnode.addElement(rnode);
                            }
                        }
                       
                    }
                   
                    Heap.pull(); // supprimer l'espace local...
                }
               
                Heap.pull(); // supprimer l'espace pour argv... // optimisation du 09/03/2012...
               
            }
            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

        Node cnode = startAt.getSubNode(1, Node.TYPE_LAZY);
        Node enode = startAt.getSubNode(3, Node.TYPE_LAZY);
        startAt.isGoodArgsCnt(4);
        Node xnode = null;
        Node rnode = null;
        Interpreter interpreter = Interpreter.mySelf();
        StaticHeap global = interpreter.getGLOBAL();
        boolean oldCanLoop = interpreter.isCanLoop();
        boolean oldInLoop = interpreter.isInLoop();
        interpreter.setCanLoop(true);
        interpreter.setInLoop(true);

        try {

            if (tcode.isPCode(PCoder.PC_DO)) {

                // closure pour le corps
                global.push();
                Heap myClosure = global.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 (xnode == null && interpreter.isCanIterate() && xPC_ConditionX(myClosure, cnode)) {
                    _clear_closure_(myClosure);
                    xnode = enode.exec(true);
                }
                global.pull();

            }
            else if (tcode.isPCode(PCoder.PC_LIST)) {
                /**
                 * boucle génératrice de listes.
                 *
                 * respecte la protection des listes finale.
                 *
                 * -> résultat jamais final.
                 *
                 */
                xnode = Node.createCList();
                //

                // closure pour le corps
                global.push();
                Heap myClosure = global.current();
                while (interpreter.isCanIterate() && xPC_ConditionX(myClosure, cnode)) {
                    _clear_closure_(myClosure);
                    rnode = enode.exec(true);
                    if (rnode != null)
                        xnode.addElement(rnode.secure());
                }
                global.pull();

            }
            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

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.