Show
Ignore:
Timestamp:
10/02/08 01:32:37 (3 months ago)
Author:
tekisuke
Message:

lang/actionscript/flmml/: マクロを再帰的定義したときのバグをとりあえず修正。FM音源はまだ封印。

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/actionscript/flmml/trunk/src/com/txt_nifty/sketch/flmml/MML.as

    r19331 r20421  
    2121        protected var m_noteShift:int; 
    2222        protected var m_warning:String; 
     23        protected var m_maxPipe:int; 
     24        protected static var MAX_PIPE:int = 3; 
    2325 
    2426        public function MML() { 
     
    191193                m_tracks[m_trackNo].recGate2(getUInt(2) * 2); // '*2' according to TSSCP 
    192194                break; 
     195                /*case 'i': // Input 
     196                { 
     197                    var sens:int = 0; 
     198                    next(); 
     199                    sens = getUInt(sens); 
     200                    if (getChar() == ',') { 
     201                        next(); 
     202                        a = getUInt(a); 
     203                        if (a > m_maxPipe) a = m_maxPipe; 
     204                    } 
     205                    m_tracks[m_trackNo].recInput(sens, a); 
     206                } 
     207                // @i[n],[m]   m:pipe no 
     208                // if (n == 0) off 
     209                // else sensitivity = n (max:8) 
     210                break; 
     211            case 'o': // Output 
     212                { 
     213                    var mode:int = 0; 
     214                    next(); 
     215                    mode = getUInt(mode); 
     216                    if (getChar() == ',') { 
     217                        next(); 
     218                        a = getUInt(a); 
     219                        if (a > m_maxPipe) { 
     220                            m_maxPipe = a; 
     221                            if (m_maxPipe >= MAX_PIPE) m_maxPipe = a = MAX_PIPE; 
     222                        } 
     223                    } 
     224                    m_tracks[m_trackNo].recOutput(mode, a); 
     225                } 
     226                // @o[n],[m]   m:pipe no 
     227                // if (n == 0) off 
     228                // if (n == 1) overwrite 
     229                // if (n == 2) add 
     230                break;*/ 
    193231            default: 
    194232                m_form = getUInt(m_form); 
     
    436474        } 
    437475 
    438         protected function macroInMacro(str:String, idArr:Array, valArr:Array):String { 
     476        protected function macroInMacro(str:String, idArr:Array, valArr:Array, id0:String):String { 
     477            var idx:int; 
    439478            for(var i:int = 0; i < idArr.length; i++) { 
    440479                var id:String = "$"+idArr[i]; 
    441480                //trace("id:"+id); 
    442                 var idx:int = str.indexOf(id); 
     481                idx = str.indexOf(id); 
    443482                while(idx >= 0) { 
    444483                    str = str.substring(0, idx) + valArr[i] + str.substring(idx + id.length); 
    445484                    idx = str.indexOf(id, idx); 
    446485                } 
     486            } 
     487            // recursive call is prevented. 
     488            id0 = "$" + id0; 
     489            idx = str.indexOf(id0); 
     490            while(idx >= 0) { 
     491                str = str.substring(0, idx) + valArr[i] + str.substring(idx + id0.length); 
     492                idx = str.indexOf(id0, idx); 
     493                warning(MWarning.RECURSIVE_MACRO, id0); 
    447494            } 
    448495            return str; 
     
    454501            var idArr:Array = new Array(); 
    455502            var valArr:Array = new Array(); 
    456             var i:int; 
    457503            var last:int; 
    458504            // [a-zA-Z][a-zA-Z0-9#\+\(\)_]* 
     
    483529                                        // first definition 
    484530                                        if (idx < 0) { 
    485                                             token[1] = macroInMacro(token[1], idArr, valArr); 
     531                                            token[1] = macroInMacro(token[1], idArr, valArr, id[0]); 
    486532                                            //trace("define $"+id[i]+"="+token[1]); 
    487                                             insertLenOrder(idArr, valArr, id[i], token[1]); 
     533                                            insertLenOrder(idArr, valArr, id[0], token[1]); 
    488534                                        } 
    489535                                        // macro redefinition 
    490536                                        else { 
    491                                             token[1] = macroInMacro(token[1], idArr, valArr); 
     537                                            token[1] = macroInMacro(token[1], idArr, valArr, id[0]); 
    492538                                            //trace("redefine $"+id[i]+"="+token[1]); 
    493539                                            valArr[idx] = token[1]; 
     
    592638            m_form = MOscillator.PULSE; 
    593639            m_noteShift = 0; 
     640            m_maxPipe = 0; 
    594641 
    595642            processComment(str); 
     
    616663                m_sequencer.connect(m_tracks[i]); 
    617664            } 
     665            m_sequencer.createPipes(m_maxPipe+1); 
    618666 
    619667            // dispatch event