<commit_before>package zog

import (
	"errors"
	"fmt"
	"strconv"
	"strings"
)

type Zog struct {
	mem *Memory
	reg Registers

	/* In the Z80 CPU, there is
	   an interrupt enable flip-flop (IFF) that is set or reset by the programmer using the Enable
	   Interrupt (EI) and Disable Interrupt (DI) instructions. When the IFF is reset, an interrupt
	   cannot be accepted by the CPU.
	*/
	iff1          bool
	iff2          bool
	interruptMode int

	outputHandlers map[uint16]func(n byte)
	inputHandlers  map[uint16]func() byte

	traces   Regions
	watch16s map[Loc16]uint16
}

func New(memSize uint16) *Zog {
	z := &Zog{
		mem:            NewMemory(memSize),
		outputHandlers: make(map[uint16]func(n byte)),
		inputHandlers:  make(map[uint16]func() byte),
		watch16s:       make(map[Loc16]uint16),
	}
	z.Clear()
	return z
}

type Region struct {
	start uint16
	end   uint16
}
type Regions []Region

func NewRegion(start, end uint16) Region {
	return Region{start: start, end: end}
}

func ParseRegions(s string) (Regions, error) {
	var regions Regions
	startEnds := strings.Split(s, ",")
	for _, startEnd := range startEnds {
		bits := strings.Split(startEnd, "-")
		start, err := strconv.ParseInt(bits[0], 16, 16)
		if err != nil {
			return regions, err
		}
		end, err := strconv.ParseInt(bits[1], 16, 16)
		if err != nil {
			return regions, err
		}
		region := NewRegion(uint16(start), uint16(end))
		regions.add(Regions{region})
	}
	return regions, nil
}

func (rs *Regions) contains(addr uint16) bool {
	for _, r := range *rs {
		if r.contains(addr) {
			return true
		}
	}
	return false
}

func (rs *Regions) add(regions Regions) {
	*rs = append(*rs, regions...)
}

func (r *Region) contains(addr uint16) bool {
	return r.start <= addr && addr <= r.end
}

func (z *Zog) TraceRegions(regions Regions) error {<commit_msg>add string repr for regions<commit_after>package zog

import (
	"errors"
	"fmt"
	"strconv"
	"strings"
)

type Zog struct {
	mem *Memory
	reg Registers

	/* In the Z80 CPU, there is
	   an interrupt enable flip-flop (IFF) that is set or reset by the programmer using the Enable
	   Interrupt (EI) and Disable Interrupt (DI) instructions. When the IFF is reset, an interrupt
	   cannot be accepted by the CPU.
	*/
	iff1          bool
	iff2          bool
	interruptMode int

	outputHandlers map[uint16]func(n byte)
	inputHandlers  map[uint16]func() byte

	traces   Regions
	watch16s map[Loc16]uint16
}

func New(memSize uint16) *Zog {
	z := &Zog{
		mem:            NewMemory(memSize),
		outputHandlers: make(map[uint16]func(n byte)),
		inputHandlers:  make(map[uint16]func() byte),
		watch16s:       make(map[Loc16]uint16),
	}
	z.Clear()
	return z
}

type Region struct {
	start uint16
	end   uint16
}
type Regions []Region

func NewRegion(start, end uint16) Region {
	return Region{start: start, end: end}
}

func ParseRegions(s string) (Regions, error) {
	var regions Regions
	s = strings.TrimSpace(s)
	if s == "" {
		return regions, nil
	}
	startEnds := strings.Split(s, ",")
	for _, startEnd := range startEnds {
		bits := strings.Split(startEnd, "-")
		start, err := strconv.ParseInt(bits[0], 16, 16)
		if err != nil {
			return regions, err
		}
		end, err := strconv.ParseInt(bits[1], 16, 16)
		if err != nil {
			return regions, err
		}
		region := NewRegion(uint16(start), uint16(end))
		regions.add(Regions{region})
	}
	return regions, nil
}

func (rs *Regions) contains(addr uint16) bool {
	for _, r := range *rs {
		if r.contains(addr) {
			return true
		}
	}
	return false
}

func (rs *Regions) add(regions Regions) {
	*rs = append(*rs, regions...)
}

func (rs Regions) String() string {
	var strs []string
	for _, r := range rs {
		strs = append(strs, r.String())
	}
	return strings.Join(strs, ",")
}

func (r *Region) contains(addr uint16) bool {
	return r.start <= addr && addr <= r.end
}

func (r *Region) String() string {
	return fmt.Sprintf("%04X-%04X", r.start, r.end)
}

func (z *Zog) TraceRegions(regions Regions) error {
{'fraction_non_alphanumeric': 0.1274287156194802, 'fraction_numerical': 0.02624274539490285, 'mean_word_length': 3.5251141552511416, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5458501', 'n_tokens_mistral': 1562, 'n_tokens_neox': 1435, 'n_words': 433}