<commit_before>macro inline(method)
  #block/&param must be re-varified if used more than once
  #lvar defns in block should be scoped to just the block
  #maybe block should always remain a proc, rather than inlining it?

  #some things aren't supported in inline methods (yet)
  #return|redo|retry|yield keywords, & parameter, and optional args are disallowed
  fail if method.rfind{|n| RedParse::KWCallNode===n and /^(?:return|redo|retry|yield)$/===n.ident }
  if params=method.params
    fail if RedParse::UnaryAmpNode===params.last
    last_non_star=params.last
    last_non_star=params[-2] if RedParse::UnaryStarNode===last_non_star
    fail if RedParse::AssignNode===last_non_star
  end

  result=:(:(inline_self=^receiver; begin end))
  pre=result.val
  body=result.val[-1]

  #copy method innards to begin node
  body.body=method.body
  body.rescues=method.rescues
  body.ensure=method.ensure
  body.else=method.else

  #make a list of known params to inline method
#  params={}
  #params should be re-varified to ensure theyre evaled exactly once
  #without hygienic macros, param names (+inline_self) leak into the caller!
  method.params.each{|param|
    case param
    when RedParse::VarNode
#      params[param.name]=1
      pre[0]+= :( :((^^param)=^param) )
    when RedParse::UnaryStarNode,RedParse::UnAmpNode
      param=param.val
#      params[param.name]=1
      pre[0]+= :( :((^^param)=^param) )
    when RedParse::AssignNode
      default=param.right
      param=param.left
#      params[param.name]=1
      pre[0]+= :( :((^^param)=^param||^default) )
    end
  } if method.params

  inline_self=RedParse::VarNode["inline_self"]

  result.walk{|parent,i,subi,node|
    newnode=nil
    case node
=begin
    when RedParse::VarNode
      #search method for params and escape them
      if params[node.name]
        newnode=FormEscapeNode[node]
      end
=end

    #what to do with receiver? implicit and explicit refs must be replaced
    when RedParse::VarLikeNode
      newnode=inline_self if node.name=="self"
    when RedParse::CallNode
      node.receiver||=inline_self 

    end
    if newnode
      if subi
        parent[i][subi]=newnode
      else
        parent[i]=newnode
      end
    end
  }
<commit_msg>get parameter escaping of inline methods working<commit_after>macro inline(method)
  #block/&param must be re-varified if used more than once
  #lvar defns in block should be scoped to just the block
  #maybe block should always remain a proc, rather than inlining it?

  #some things aren't supported in inline methods (yet)
  #return|redo|retry|yield keywords, & parameter, and optional args are disallowed
  fail if method.rfind{|n| RedParse::KWCallNode===n and /^(?:return|redo|retry|yield)$/===n.ident }
  if params=method.params
    fail if RedParse::UnaryAmpNode===params.last
    last_non_star=params.last
    last_non_star=params[-2] if RedParse::UnaryStarNode===last_non_star
    fail if RedParse::AssignNode===last_non_star
  end

  result=:(:(inline_self=^receiver; begin end))
  pre=result.val
  body=result.val[-1]

  #copy method innards to begin node
  body.body=method.body
  body.rescues=method.rescues
  body.ensure=method.ensure
  body.else=method.else

  #make a list of known params to inline method
  params={}
  #params should be re-varified to ensure theyre evaled exactly once
  #without hygienic macros, param names (+inline_self) leak into the caller!
  method.params.each{|param|
    case param
    when RedParse::VarNode
      params[param.name]=1
#      pre[0]+= :( :((^^param)=^param) )
    when RedParse::UnaryStarNode,RedParse::UnAmpNode
      param=param.val
      params[param.name]=1
#      pre[0]+= :( :((^^param)=^param) )
    when RedParse::AssignNode
      default=param.right
      param=param.left
      params[param.name]=1
#      pre[0]+= :( :((^^param)=^param||^default) )
    end
  } if method.params

  inline_self=RedParse::VarNode["inline_self"]

  result.walk{|parent,i,subi,node|
    newnode=nil
    case node
    when RedParse::VarNode
      #search method for params and escape them
      if params[node.name]
        newnode=FormEscapeNode[node]
      end

    #what to do with receiver? implicit and explicit refs must be replaced
    when RedParse::VarLikeNode
      newnode=inline_self if node.name=="self"
    when RedParse::CallNode
      node.receiver||=inline_self 

    end
    if newnode
      if subi
        parent[i][subi]=newnode
      else
        parent[i]=newnode
      end
    end
  }

{'fraction_non_alphanumeric': 0.1128673196794301, 'fraction_numerical': 0.003561887800534283, 'mean_word_length': 3.5707019328585963, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4249119', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1451, 'n_words': 378}