Package abstrasy

Examples of abstrasy.ASymbol


        startAt.isGoodArgsCnt(4);
        /*
         * forme :
         *          (slot 'symbole of delegable) -> valeur
         */
        ASymbol symbole = startAt.getSubNode(1,Node.TYPE_QSYMBOL).getSymbol();
        startAt.requirePCode(2, PCoder.PC_OF);
        Node dn = startAt.getSubNode(3, Node.VTYPE_DELEGABLE);
       
        symbole=new ASymbol(PCoder.unselfing(symbole.getStr()));
        if(symbole.getIdsCnt()!=1)
            throw new InterpreterException(StdErrors.Local_symbol_required);
       
        Node slot=Node.VDelegable.getSlot(dn, symbole.getStr());
       
        if(slot==null)
            throw new InterpreterException(StdErrors.Symbol_not_defined);
        return slot;
    }
View Full Code Here


             */
            Node hnode = startAt.getSubNode(1, Node.VTYPE_DELEGABLE);
            Node cnode = startAt.getSubNode(3, Node.TYPE_QSYMBOL);
            Heap.push();
            Node old_self = SELF.swap(hnode); // vobject -> Self
            cnode = Heap.getv(new ASymbol(PCoder.selfing(cnode.getSymbol().getStr())));
            SELF.restore(old_self);
            Heap.pull();
            return cnode;
        }
        else{
View Full Code Here

       
        ArrayList<String> symboles = Node.VDelegable.slotsOf(vObject);

        for(int i=0;i<symboles.size();i++){
            String symb=symboles.get(i);
            if(Heap.getv(vObject, new ASymbol(PCoder.selfing(symb))).isFunction()){
                Node fx=Node.createInlineFunction(Node.createLazy().append(vObject).append(Node.createQSymbol(symb)));
                Heap.defv(new ASymbol(optScope ? (prefix+symb):PCoder.selfing(prefix+symb)), fx);
            }
        }
        return null;
    }
View Full Code Here

    }
   
    private static final void _provide_(Node n_provide, String moduleID) throws Exception {
        // traiter la liste provide si elle existe...
            for (int i = 0; i < n_provide.size(); i++) {
                ASymbol p_symbole = n_provide.elementAt(i).getSymbol();
                // vérification du symbole : local et immutable
                _check_symbol_(p_symbole);
                // lien 'Symbole <-(synonyme)- 'Module:Symbole
                Heap.defv(p_symbole, Heap.getv(new ASymbol(moduleID + PCoder.SEP + p_symbole.getStr())));
            }
    }
View Full Code Here

        Node rnode = null;

        /*
         * préparation du symbole du module...
         */
        ASymbol symbole = n_module.getSymbol();
        // vérification du symbole : local et immutable
        _check_symbol_(symbole);

        //

        /**
         * ne pas aller plus loin si le module est déjà chargé...
         */
        ASymbol moduleID = new ASymbol(PCoder.REGISTRY + PCoder.SEP + symbole.getStr());
        if (Heap.exists(moduleID)) {
            Heap.defv(symbole, Heap.getv(moduleID));
           
            // traiter la liste provide si elle existe...
            _provide_(n_provide,moduleID.getStr());

            return null;
        }

        /**
         * Le module n'est pas encore chargé.
         * =================================
         *
         * On va le charger...
         *
         */

        // déterminer le nom du fichier à chercher...
        Node npath = n_from == null ? new Node(symbole.getRootNamespace()): n_from;


        // chercher le fichier...
        File src = SourceFile.findSourceFileName(npath.getString());
       
        // c'est parti!...
        String msrc = "";
        SourceFile in = null;

        if (src != null) {
            in = new SourceFile(src.getAbsolutePath());
        }
        else {
            Node iPaths = Heap.getv(ASymbol.SYMBOL_IMPORTS_PATH);
            if (iPaths != null) {
                if (iPaths.getQType()==Node.TYPE_CLIST) {
                    for (int ip = (iPaths.size() - 1); ip >= 0; ip--) {
                        Node pval = iPaths.elementAt(ip);
                        if (pval.isString()) {
                            src = SourceFile.findSourceFileName(pval.getString() + npath.getString());
                            if (src != null) {
                                in = new SourceFile(src.getAbsolutePath());
                                ip = -1;
                            }
                        }
                    }
                }
            }
        }
        if (in == null) {
            Node iPaths = Heap.getv(ASymbol.SYMBOL_IMPORTS_BASE_URL);
            if (iPaths != null) {
                if (iPaths.getQType()==Node.TYPE_CLIST) {
                    for (int ip = (iPaths.size() - 1); ip >= 0; ip--) {
                        Node pval = iPaths.elementAt(ip);
                        if (pval.isString()) {
                            URL surl = SourceFile.findSourceURLName(pval.getString() + npath.getString());
                            if (surl != null) {
                                in = new SourceFile(surl);
                                ip = -1;
                            }
                        }
                    }
                }
            }

        }
        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();
                Heap.DynamicConstants.setMAIN_FALSE();
                if ((rnode = interpreter.getNode().exec(false)) != null) {
                    Interpreter.Log("Retour Import ??? " + rnode);
                }
                Heap.pull();

                // enregistrer le module
                Heap.defv(new ASymbol(symbole.getLocalName()), Heap.getv(moduleID));
               
               
                // traiter la liste provide si elle existe...
                _provide_(n_provide,moduleID.getStr());
               
                return null;

            }
            catch (Exception ex) {
View Full Code Here

     */
        startAt.isGoodArgsCnt(2, 3);
        /**
     * début du traitement
     */
        ASymbol symbole_n = startAt.getSubNode(1, Node.TYPE_QSYMBOL).getSymbol();

        if (symbole_n.getStr().charAt(0) == PCoder.REG) {
            if (symbole_n.getStr().indexOf(PCoder.SEP) < 0) {
                // seul les espace de nom sont acceptables...
                throw new InterpreterException(StdErrors.Illegal_access_to_register);
            }
        }

        //System.out.println("DEF:"+snode);
        if (startAt.size() == 2) {
            Heap.defv(symbole_n, Node.createNothing());
        }
        else {
            // il y a une valeur d'affectation...
            Node rnode = startAt.getSubNode(2, Node.VTYPE_VALUABLE);
            /**
             * Etablissement du code de conditions pour (define 't s) :
             * 1 : s est final.
             * 2 : s est un symbole.
             * 4 : t est immutable.
             *
             * Remarque: Au niveau du Heap, si le symbole recherché est immutable,
             *           un .newRef() .setImmutable() est tjrs réalisé d'office.
             *
             * D'où la table de vérités en considérant que t est toujours un symbole:
             *
             * code | t=immutable | s=symbole | s=final | opération
             * -----+-------------+-----------+---------+----------
             *   7  |      1      |     1     |    1    | Référence
             *   6  |      1      |     1     |    0    | Clonage
             *   5  |      1      |     0     |    1    | Référence
             *   4  |      1      |     0     |    0    | Clonage
             *   3  |      0      |     1     |    1    | Clonage
             *   2  |      0      |     1     |    0    | Référence
             *   1  |      0      |     0     |    1    | Clonage
             *   0  |      0      |     0     |    0    | référence // dépréciation de DeRef (16/12/20010)
             *
             */
            boolean isImmutable=symbole_n.isImmutable();
            int code = (isImmutable ? 4: 0) + (startAt.isNodeType(2, Node.TYPE_SYMBOL) ? 2: 0) + (rnode.isFinalNode() ? 1: 0);

            //if(snode.value.equals("rxx")) System.out.println("Define "+snode.value+" "+(rnode.isFinalNode() ? "FINAL":""));
            /**
             * Dispatching des fonctionnalités selon le code:
View Full Code Here

        int offset=forceFinal ? 1:0;
       
        /**
     * vérification élémentaire
     */
        ASymbol symbol = null;
        Node fn = null;
        switch (startAt.size()-offset) {
            case 3:
                {
                    symbol = startAt.getSubNode(1+offset, Node.TYPE_QSYMBOL).getSymbol();
                    fn = startAt.getSubNode(2+offset, Node.TYPE_LAZY | Node.TYPE_NAMESPACE);
                    break;
                }
            case 2:
                {
                    fn = startAt.getSubNode(1+offset, Node.TYPE_LAZY | Node.TYPE_NAMESPACE | Node.TYPE_QSYMBOL);
                    if (fn.isQSymbol()) {
                        symbol = fn.getSymbol();
                        fn = null;
                    }
                    break;
                }
            case 1:
                {
                    break;
                }
            default:
                {
                    throw new InterpreterException(StdErrors.Argument_count_mismatch);
                }
        }
        Node moduleNode;
        if (fn == null) {
            /**
             * forme (object)
             */
            Heap heap = new Heap();
            moduleNode = new Node(heap);
            moduleNode.setType(Node.TYPE_NAMESPACE);
            moduleNode.setFinalNode(false);
           
            if (symbol != null) {
                /**
                 * forme (object 'symbol)
                 */
                if(forceFinal && !symbol.isImmutable()){
                    throw new InterpreterException(StdErrors.Immutable_symbol_required);
                }
                else{
                    Heap.defv(symbol, moduleNode.letFinal(symbol.isImmutable()));
                }
            }
        }
        else if (fn.isNamespace()) {
            /**
             * fn est vObject...
             */
            if (symbol != null) {
                /**
                 * Attention, il faut respecter la finalité...
                 *
                 * objet | symbol | # | Op.
                 * final | final  |   |
                 * ------+--------+---+------
                 *   0   |    0   | 0 | deref
                 *   0   |    1   | 1 | clone
                 *   1   |    0   | 2 | clone
                 *   1   |    1   | 3 | deref
                 *
                 */
                int code = (fn.isFinalNode() ? 2: 0) + (symbol.isImmutable() ? 1: 0);
                switch (code) {
                    case 0:
                    case 3:{
                        Heap heap = new Heap((Heap)fn.getExternal());
                        moduleNode = new Node(heap);
                        moduleNode.setType(Node.TYPE_NAMESPACE);
                        moduleNode.setFinalNode(false);
                        break;
                    }
                    default:
                        moduleNode = Node.createClone(fn);
                }
                if(forceFinal && !symbol.isImmutable()){
                    throw new InterpreterException(StdErrors.Immutable_symbol_required);
                }
                else{
                    Heap.defv(symbol, moduleNode.letFinal(symbol.isImmutable()));
                }
            }
            else {
                /**
                * pas de symbole...
                * On clone d'office...
                */
                moduleNode = Node.createClone(fn);
            }
        }
        else {
            /**
             * fn est lazy...
             */
            Heap heap = new Heap();
            moduleNode = new Node(heap);
            moduleNode.setType(Node.TYPE_NAMESPACE);
            moduleNode.setFinalNode(false);
            if (symbol != null) {
                if(forceFinal && !symbol.isImmutable()){
                    throw new InterpreterException(StdErrors.Immutable_symbol_required);
                }
                else{
                    Heap.defv(symbol, moduleNode.letFinal(symbol.isImmutable()));
                }
            }
            Heap.push();
            Node old_self = SELF.swap(moduleNode);
            Node tmpn = fn.exec(true);
View Full Code Here

        ArrayList<Node> values = (ArrayList<Node>) mixins[1];

        /**
         * importer les éléments possibles
         */
        ASymbol symbol;
        for (int i = 0; i < symbols.size(); i++) {
            /**
             * composer le symbole dans la forme Self:<symbole>...
             */
            symbol = new ASymbol(PCoder.selfing(symbols.get(i)));
            /**
             * tester s'il y a collision...
             *
             * S'il y a collision, une exception est déclenchée.
             * Un mixin ne peut pas être utilisé pour surdéfinir.
             */
            if (Heap.exists(symbol))
                throw new InterpreterException(StdErrors.extend(StdErrors.Symbol_already_exists, symbol.getStr()));
            /**
             * si tout va bien, on ajoute le mixin qui correspond...
             *
             * La protection minimum (deref).
             *
 
View Full Code Here

            o_arg.requireNodeType(Node.TYPE_QSYMBOL|Node.TYPE_LAZY);
            if(o_arg.isQSymbol()){
                //
                // forme : ... 'symbole {...})
                //
                ASymbol e_symbole = o_arg.getSymbol();
                Node e_body = startAt.getSubNode(++o_rel, Node.TYPE_LAZY);
                startAt.isGoodArgsCnt(o_rel+1); // Vérifie la forme
                Node e_function = Node.createInlineFunction(e_body);
                if (e_final && !e_symbole.isImmutable())
                    throw new InterpreterException(StdErrors.Immutable_symbol_required);
                Heap.defv(e_symbole, e_function.letFinal(e_symbole.isImmutable()));
                return null;  
            }
            else{
                //
                // forme : ... {...})
                //
                startAt.isGoodArgsCnt(o_rel+1);
                Node e_body = o_arg;
                Node e_function = Node.createInlineFunction(e_body).letFinal(e_final);
                return e_function;
            }
        }
        else if(e_override){
            /**
             * override
             */
            //
            // forme : ... 'symbole ...
            //    et : ... function ...
            //
            o_arg.requireNodeType(Node.TYPE_QSYMBOL|Node.TYPE_FUNCTION);
            ASymbol e_symbole=null;
            Node e_body=null;
            Node e_super=null;
            if(o_arg.isQSymbol()){
                e_symbole = o_arg.getSymbol();
                e_super = Heap.getv(e_symbole);
                e_super.requireAccessType(Node.ACCESSVTYPE_MUTABLE_WRITELOCK);
                e_super.requireNodeType(Node.TYPE_FUNCTION);
            }
            else{
               e_super = o_arg;
               e_super.requireAccessType(Node.ACCESSVTYPE_MUTABLE_WRITELOCK);
            }
            //
            // forme : ... [{...}] ...
            //
            if(startAt.testSubNode(++o_rel, Node.TYPE_LAZY)){
                e_body=startAt.getSubNode(o_rel, Node.TYPE_LAZY);
            }
            else{
                o_rel--; // Attention!!! il faut revenir en arrière...
                e_body=((Function) e_super.getExternal()).getBodyFx();
            }
            //
            // Rechercher la forme [with lazy/scope] et/ou [from lazy/scope]
            //
            Node e_with=null;
            Node e_yield=null;
            while(startAt.size()>o_rel+1){
                o_arg=startAt.getSubNode(++o_rel, Node.TYPE_PCODE);
                if(o_arg.isPCode(PCoder.PC_WITH))
                    if(e_with!=null)
                        throw new InterpreterException(StdErrors.extend(StdErrors.Duplicate_parameters,o_arg.toString()));
                    else{
                        e_with=startAt.getSubNode(++o_rel, Node.TYPE_LAZY|Node.TYPE_SCOPE);
                        if(e_with.isLazy())
                            e_with=Node.createScope(e_with);
                    }
                else if(o_arg.isPCode(PCoder.PC_YIELD))
                    if(e_yield!=null)
                        throw new InterpreterException(StdErrors.extend(StdErrors.Duplicate_parameters,o_arg.toString()));
                    else{
                        e_yield=startAt.getSubNode(++o_rel, Node.TYPE_LAZY|Node.TYPE_SCOPE);
                        if(e_yield.isLazy())
                            e_yield=Node.createScope(e_yield);
                    }
            }
            //
            // On a tout ce qu'il faut...
            //
            startAt.isGoodArgsCnt(o_rel+1); // Vérifie la forme
            Node e_function = Node.createOverridedFunction(e_body,e_yield,e_with,e_super);
            if (e_symbole == null)
                return e_function.letFinal(e_final);
            else {
                e_function.derefTo(e_super);
                return null;
            }
           
           
        }
        else if(e_wrapper){
            /**
             * wrapper
             */
            //
            // forme : ... ['symbole] ...
            //
            o_arg.requireNodeType(Node.TYPE_QSYMBOL|Node.TYPE_PCODE);
            ASymbol e_symbole=null;
            if(o_arg.isQSymbol()){
                e_symbole = o_arg.getSymbol();
                o_arg=startAt.getSubNode(++o_rel, Node.TYPE_PCODE);
            }
   
            //
            // Rechercher la forme [with lazy/scope] et/ou [from lazy/scope]
            //
            // Attention, dans ce cas, o_arg contient déjà le premier PCode with ou yield.
            // --------------------------------------------------------------------------
            // La boucle est donc différente ici que dans les autres cas...
            //
            // De plus, il est obligatoire de stipuler au moins un des deux scopes.
            //                                         -----------
            //
            Node e_with=null;
            Node e_yield=null;
            do{
                // on ne cherche o_arg que s'il est null
                if(o_arg==null)
                    o_arg=startAt.getSubNode(++o_rel, Node.TYPE_PCODE);
                if(o_arg.isPCode(PCoder.PC_WITH))
                    if(e_with!=null)
                        throw new InterpreterException(StdErrors.extend(StdErrors.Duplicate_parameters,o_arg.toString()));
                    else{
                        e_with=startAt.getSubNode(++o_rel, Node.TYPE_LAZY|Node.TYPE_SCOPE);
                        if(e_with.isLazy())
                            e_with=Node.createScope(e_with);
                    }
                else if(o_arg.isPCode(PCoder.PC_YIELD))
                    if(e_yield!=null)
                        throw new InterpreterException(StdErrors.extend(StdErrors.Duplicate_parameters,o_arg.toString()));
                    else{
                        e_yield=startAt.getSubNode(++o_rel, Node.TYPE_LAZY|Node.TYPE_SCOPE);
                        if(e_yield.isLazy())
                            e_yield=Node.createScope(e_yield);
                    }
                // on met o_arg=null pour la suite...
                o_arg=null;
            }while(startAt.size()>o_rel+1);
            //
            // On a tout ce qu'il faut...
            //
            startAt.isGoodArgsCnt(o_rel+1); // Vérifie la forme
            Node e_function = Node.createFunction(null,e_yield,e_with); // on crée une fonction wrapper (sans corps)
            if(e_symbole!=null){
                if (e_final && !e_symbole.isImmutable())
                    throw new InterpreterException(StdErrors.Immutable_symbol_required);
                Heap.defv(e_symbole, e_function.letFinal(e_symbole.isImmutable()));
                return null;
            }
            else
                return e_function.letFinal(e_final);
           
        }
        else{
            /**
             * classique
             */
            //
            // forme : ... 'symbole {...} ...
            //    et : ... {...} ...
            //
            o_arg.requireNodeType(Node.TYPE_QSYMBOL|Node.TYPE_LAZY);
            ASymbol e_symbole=null;
            if(o_arg.isQSymbol()){
                e_symbole = o_arg.getSymbol();
                o_arg=startAt.getSubNode(++o_rel, Node.TYPE_LAZY);
            }
            Node e_body = o_arg;
            //
            // Rechercher la forme [with lazy/scope] et/ou [from lazy/scope]
            //
            Node e_with=null;
            Node e_yield=null;
            while(startAt.size()>o_rel+1){
                o_arg=startAt.getSubNode(++o_rel, Node.TYPE_PCODE);
                if(o_arg.isPCode(PCoder.PC_WITH))
                    if(e_with!=null)
                        throw new InterpreterException(StdErrors.extend(StdErrors.Duplicate_parameters,o_arg.toString()));
                    else{
                        e_with=startAt.getSubNode(++o_rel, Node.TYPE_LAZY|Node.TYPE_SCOPE);
                        if(e_with.isLazy())
                            e_with=Node.createScope(e_with);
                    }
                else if(o_arg.isPCode(PCoder.PC_YIELD))
                    if(e_yield!=null)
                        throw new InterpreterException(StdErrors.extend(StdErrors.Duplicate_parameters,o_arg.toString()));
                    else{
                        e_yield=startAt.getSubNode(++o_rel, Node.TYPE_LAZY|Node.TYPE_SCOPE);
                        if(e_yield.isLazy())
                            e_yield=Node.createScope(e_yield);
                    }
            }
            //
            // On a tout ce qu'il faut...
            //
            startAt.isGoodArgsCnt(o_rel+1); // Vérifie la forme
            Node e_function = Node.createFunction(e_body,e_yield,e_with);
            if(e_symbole!=null){
                if (e_final && !e_symbole.isImmutable())
                    throw new InterpreterException(StdErrors.Immutable_symbol_required);
                Heap.defv(e_symbole, e_function.letFinal(e_symbole.isImmutable()));
                return null;
            }
            else
                return e_function.letFinal(e_final);
           
View Full Code Here

   * @throws Exception
   * @todo Implémenter cette méthode abstrasy.PCFx
   */
  public Node eval(Node startAt) throws Exception {
    startAt.isGoodArgsCnt(2);
    ASymbol symbole = startAt.getSubNode(1, Node.TYPE_QSYMBOL).getSymbol();
        /**
         * Si le symbole est malformé... Exception...
         */
        if (symbole.getIdsCnt()>1){
            throw new InterpreterException(StdErrors.Invalid_symbol);
        }
        if (!symbole.isImmutable()) {
            throw new InterpreterException(StdErrors.Immutable_symbol_required);
        }
        Node registry = Heap.getv(ASymbol.SYMBOL_REGISTRY);
        boolean res=false;           
    try {
      synchronized(registry){
                res=Heap.exists(new ASymbol(PCoder.REGISTRY+PCoder.SEP+symbole.getStr()));
            }
    }
    catch (Exception ex) {
            res=false;
    }
View Full Code Here

TOP

Related Classes of abstrasy.ASymbol

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.