//MACRO Avl.freeall Anchor, FreeMacro, WReg[], FieldDispl= 0 //-------------------------------------------------------------------------------------------------- // // @ CopyRight Roberti & Parau Enterprises, Inc. 2021-2023 // // This work is licensed under the Creative Commons Attribution-NoDerivatives 4.0 International License. // To view a copy of this license, visit http://creativecommons.org/licenses/by-nd/4.0/ // or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. // //-------------------------------------------------------------------------------------------------- // // // Get load/store MIs and word length // eval(DVASM.getEnv()[4]); var ld= "L" + abiWID; var st= "S" + abiWID; var wl= abiWLen; var leftField= FieldDispl; var parentField= wl + "+" + FieldDispl; var rightField= wl*2 + "+" + FieldDispl; var contRight= DVASM.getNewLabel(); var doneLbl= DVASM.getNewLabel(); var emptyLbl= DVASM.getNewLabel(); // // Set up registers and addresses // if (WReg.length < 2) return DVASM.putError("Number of work register is " + WReg.length + ". It must be at least 2"); var node= WReg[0]; var next= WReg[1]; var parent= WReg[1]; var linkType= WReg[1]; var freeMacroWR= "[" + WReg.slice(2) + "]"; // // Generate code // \ // \ // Find leftmost child \ // \#Label #ld #next, #Anchor // Load root node addr \ IF ( #next == 0 ), GOTO, ID= #emptyLbl // Tree is empty nothing to do \ DO // Loop until no more nodes \ MV #node, #next // Copy new node addr \ #ld #next, #leftField[#node] // Load left child addr \ IF ( #next != 0 ), CONTINUE // Process left child if any \#contRight #ld #next, #rightField[#node] // Load left child addr \ IF ( #next != 0 ), CONTINUE // Process left child if any \ ENDDO \ // \ // Scan tree post-order and free each node using the FreeNode macro \ // \ WHILE // Start loop up through parents \ #ld #parent, #parentField[#node] // Load parent field first \ #FreeMacro #node, #freeMacroWR // Free node \ ANDI #node, ~ 0b111 [#parent] // Extract parent addr \ IF ( #node == 0 ), GOTO, ID= #doneLbl // Done if no more nodes \ ANDI #linkType, 0b100 [#parent] // Extract link type \ IF ( #linkType != 0 ), GOTO, ID= #contRight // Go down the right link if link type is left \ ENDWHILE \#doneLbl #st 0, #Anchor // Clear anchor and done \#emptyLbl BYTE 0[0] // Tree is empty - nothing to do