class_docstr: Standalone class that applies Instruction rewrite/filtering rules.
  
  This significantly simplifies subsequent parsing by injecting
  synthetic POLARS_EXPRESSION ops into the Instruction stream for
  easy identification/translation and separates the parsing logic
  from the identification of expression translation opportunities.
class_docstr_tok: ["Standalone","class","that","applies","Instruction","rewrite\/filtering","rules",".","This","significantly","simplifies","subsequent","parsing","by","injecting","synthetic","POLARS_EXPRESSION","ops","into","the","Instruction","stream","for","easy","identification\/translation","and","separates","the","parsing","logic","from","the","identification","of","expression","translation","opportunities","."]
docstr: Replace function calls with a synthetic POLARS_EXPRESSION op.
code: def _rewrite_functions(
      self, idx: int, updated_instructions: list[Instruction]
  ) -> int:
      """Replace function calls with a synthetic POLARS_EXPRESSION op."""
      for function_kind in _FUNCTION_KINDS:
          opnames: list[AbstractSet[str]] = [
              {"LOAD_GLOBAL", "LOAD_DEREF"},
              *function_kind["module_opname"],
              *function_kind["attribute_opname"],
              *function_kind["argument_1_opname"],
              *function_kind["argument_1_unary_opname"],
              *function_kind["argument_2_opname"],
              OpNames.CALL,
          ]
          if matching_instructions := self._matches(
              idx,
              opnames=opnames,
              argvals=[
                  *function_kind["module_name"],
                  *function_kind["attribute_name"],
                  *function_kind["function_name"],
              ],
          ):
              attribute_count = len(function_kind["attribute_name"])
              inst1, inst2, inst3 = matching_instructions[
                  attribute_count : 3 + attribute_count
              ]
              if inst1.argval == "json":
                  expr_name = "str.json_decode"
              elif inst1.argval == "datetime":
                  fmt = matching_instructions[
                      attribute_count + 3
                  ].argval
                  expr_name = f'str.to_datetime(format="{fmt}")'
                  if not self._is_stdlib_datetime(
                      inst1.argval,
                      matching_instructions[0].argval,
                      fmt,
                      attribute_count,
                  ):
                      return 0
              else:
                  expr_name = inst2.argval
              synthetic_call = inst1._replace(
                  opname="POLARS_EXPRESSION",
                  argval=expr_name,
                  argrepr=expr_name,
                  offset=inst3.offset,
              )
              # POLARS_EXPRESSION is mapped as a unary op, so switch instruction order
              operand = inst3._replace(offset=inst1.offset)
              updated_instructions.extend(
                  (
                      operand,
                      matching_instructions[3 + attribute_count],
                      synthetic_call,
                  )
                  if function_kind["argument_1_unary_opname"]
                  else (operand, synthetic_call)
              )
              return len(matching_instructions)
  
      return 0
  
imports: from __future__ import annotations
  import datetime
  import dis
  import inspect
  import re
  import sys
  import warnings
  from bisect import bisect_left
  from collections import defaultdict
  from dis import get_instructions
  from inspect import signature
  from itertools import count, zip_longest
  from pathlib import Path
  from typing import TYPE_CHECKING, AbstractSet, Any, Callable, ClassVar, Iterator, Literal, NamedTuple, Union
label_desc: Use image node_id 8 for calling the RewrittenInstructions obj's underlying member method code with example usage: obj._rewrite_functions(idx, updated_instructions) and returns: int, len, int