<commit_before>package tritium

import (
  "goprotobuf.googlecode.com/hg/proto"
)

func (ins *Instruction) Iterate(itFunc func(*Instruction)) {
	itFunc(ins)
	if ins.Children == nil {
		return
	}
	for _, child := range(ins.Children) {
		child.Iterate(itFunc)
	}
}



func ListInstructions(instrs ...*Instruction) []*Instruction {
  return append(make([]*Instruction, 0), instrs...)
}

func FoldLeft(funcName string, base *Instruction, seq []*Instruction) (acc *Instruction) {
  for acc = base; len(seq) > 0; seq = seq[1:] {
    acc = MakeFunctionCall(funcName, ListInstructions(acc, seq[0]), nil, *base.LineNumber)
  }
  return acc
}

func MakeText(text string, lineNum int32) *Instruction {
  return &Instruction {
    Type: NewInstruction_InstructionType(Instruction_TEXT),
    Value: proto.String(text),
    LineNumber: proto.Int32(lineNum),
  }
}

func MakePosition(pos string, lineNum int32) *Instruction {
  return &Instruction {
    Type: NewInstruction_InstructionType(Instruction_POSITION),
    Value: proto.String(pos),
    LineNumber: proto.Int32(lineNum),
  }
}

func MakeImport(path string, lineNum int32) *Instruction {
  return &Instruction {
    Type: NewInstruction_InstructionType(Instruction_IMPORT),
    Value: proto.String(path),
    LineNumber: proto.Int32(lineNum),
  }
}

func MakeLocalVar(name string, val *Instruction, block []*Instruction, lineNum int32) *Instruction {
  return &Instruction {
    Type: NewInstruction_InstructionType(Instruction_LOCAL_VAR),
    Value: proto.String(name),
    Arguments: ListInstructions(val),
    Children: block,
    LineNumber: proto.Int32(lineNum),
  }
}

func MakeFunctionCall(name string, args []*Instruction, block []*Instruction, lineNum int32) *Instruction {
  return &Instruction {
    Type: NewInstruction_InstructionType(Instruction_FUNCTION_CALL),
    Value: proto.String(name),
    Arguments: args,
    Children: block,
    LineNumber: proto.Int32(lineNum),
  }
}

func MakeBlock(children []*Instruction, lineNum int32) *Instruction {
  return &Instruction {
    Type: NewInstruction_InstructionType(Instruction_BLOCK),
    Children: children,<commit_msg>Fixed a bug in one of the helper functions.<commit_after>package tritium

import (
  "goprotobuf.googlecode.com/hg/proto"
)

func (ins *Instruction) Iterate(itFunc func(*Instruction)) {
	itFunc(ins)
	if ins.Children == nil {
		return
	}
	for _, child := range(ins.Children) {
		child.Iterate(itFunc)
	}
}



func ListInstructions(instrs ...*Instruction) []*Instruction {
  return append(make([]*Instruction, 0), instrs...)
}

func FoldLeft(funcName string, base *Instruction, seq []*Instruction) (acc *Instruction) {
  for acc = base; len(seq) > 0; seq = seq[1:] {
    acc = MakeFunctionCall(funcName, ListInstructions(acc, seq[0]), nil, *base.LineNumber)
  }
  return acc
}

func MakeText(text string, lineNum int32) *Instruction {
  return &Instruction {
    Type: NewInstruction_InstructionType(Instruction_TEXT),
    Value: proto.String(text),
    LineNumber: proto.Int32(lineNum),
  }
}

func MakePosition(pos string, lineNum int32) *Instruction {
  return &Instruction {
    Type: NewInstruction_InstructionType(Instruction_POSITION),
    Value: proto.String(pos),
    LineNumber: proto.Int32(lineNum),
  }
}

func MakeImport(path string, lineNum int32) *Instruction {
  return &Instruction {
    Type: NewInstruction_InstructionType(Instruction_IMPORT),
    Value: proto.String(path),
    LineNumber: proto.Int32(lineNum),
  }
}

func MakeLocalVar(name string, val *Instruction, block []*Instruction, lineNum int32) *Instruction {
  node := &Instruction {
    Type: NewInstruction_InstructionType(Instruction_LOCAL_VAR),
    Value: proto.String(name),
    Children: block,
    LineNumber: proto.Int32(lineNum),
  }
  if val == nil {
    node.Arguments = nil
  } else {
    node.Arguments = ListInstructions(val)
  }
  return node
}

func MakeFunctionCall(name string, args []*Instruction, block []*Instruction, lineNum int32) *Instruction {
  return &Instruction {
    Type: NewInstruction_InstructionType(Instruction_FUNCTION_CALL),
    Value: proto.String(name),
    Arguments: args,
    Children: block,
    LineNumber: proto.Int32(lineNum),
  }
}

func MakeBlock(children []*Instruction, lineNum int32) *Instruction {
  return &Instruction {
    Type: NewInstruction_InstructionType(Instruction_BLOCK),
    Children: children,
{'fraction_non_alphanumeric': 0.11933119560238205, 'fraction_numerical': 0.011910215300045808, 'mean_word_length': 4.822666666666667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4532373', 'n_tokens_mistral': 1373, 'n_tokens_neox': 1415, 'n_words': 311}