#NEWLINE# @ staticmethod #NEWLINE# def update_program( program , encoding , gbias , lbias_arr , fdidx ) : #NEWLINE# #INDENT# '\n        Applies the provided `encoding` to the provided `program`. I.e., all\n        specified subroutines are actually called in the program. This mutates\n        the input program and also returns it.\n\n        Arguments:\n        program -- the program to update\n        encoding -- the encoding to use. a list of (idx, cand_subr) tuples\n        gbias -- bias into the global subrs INDEX\n        lbias_arr -- bias into each of the lsubrs INDEXes\n        fdidx -- the FD that this `program` belongs to, or None if global\n        ' #NEWLINE# offset = 0 #NEWLINE# for item in encoding : #NEWLINE# #INDENT# subr = item [ 1 ] #NEWLINE# s = slice ( ( item [ 0 ] - offset ) , ( ( item [ 0 ] + subr . length ) - offset ) ) #NEWLINE# if subr . _flatten : #NEWLINE# #INDENT# program [ s ] = subr . _program #NEWLINE# offset += ( subr . length - len ( subr . _program ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# assert hasattr ( subr , '_position' ) , 'CandidateSubr without position in Subrs encountered' #NEWLINE# if subr . _global : #NEWLINE# #INDENT# operator = 'callgsubr' #NEWLINE# bias = gbias #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# assert ( len ( subr . _fdidx ) == 1 ) #NEWLINE# assert ( ( fdidx == None ) or ( subr . _fdidx [ 0 ] == offset ) ) #NEWLINE# operator = 'callsubr' #NEWLINE# bias = lbias_arr [ subr . _fdidx [ 0 ] ] #NEWLINE# #UNINDENT# program [ s ] = [ ( subr . _position - bias ) , operator ] #NEWLINE# offset += ( subr . length - 2 ) #NEWLINE# #UNINDENT# #UNINDENT# return program