<commit_before>package obj

import (
	"reflect"

	"github.com/polydawn/go-xlate/obj2/atlas"
)

/*
	A lovely mechanism to stash marshalMachine objects pre-allocated and avoid mallocs.
	Works together with the Atlas: the Atlas says what kind of machinery is needed;
	the marshalSlab "allocates" it and returns it upon your request.
*/
type marshalSlab struct {
	atlas atlas.Atlas
	rows  []marshalSlabRow
}

type marshalSlabRow struct {
	//	ptrDerefDelegateMarshalMachine
	//	marshalMachineLiteral
	//	marshalMachineMapWildcard
	//	marshalMachineSliceWildcard
	//	marshalMachineWildcard
	//	marshalMachineStructAtlas
}

/*
	Return a reference to a machine from the slab.
	*You must release() when done.*

	Errors -- including "no info in Atlas for this type" -- are expressed by
	returning a machine that is a constantly-erroring thunk.
*/
func (slab *marshalSlab) requisitionMachine(forThis reflect.Type) MarshalMachine {
	return nil // TODO
}<commit_msg>Implement the errThunk marshalmachine and return that when we can't find a machine.  (Currently, always in this package :) placeholders continue...)<commit_after>package obj

import (
	"fmt"
	"reflect"

	"github.com/polydawn/go-xlate/obj2/atlas"
	. "github.com/polydawn/go-xlate/tok"
)

/*
	A lovely mechanism to stash marshalMachine objects pre-allocated and avoid mallocs.
	Works together with the Atlas: the Atlas says what kind of machinery is needed;
	the marshalSlab "allocates" it and returns it upon your request.
*/
type marshalSlab struct {
	atlas atlas.Atlas
	rows  []marshalSlabRow
}

type marshalSlabRow struct {
	//	ptrDerefDelegateMarshalMachine
	//	marshalMachineLiteral
	//	marshalMachineMapWildcard
	//	marshalMachineSliceWildcard
	//	marshalMachineWildcard
	//	marshalMachineStructAtlas

	errThunkMarshalMachine
}

/*
	Return a reference to a machine from the slab.
	*You must release() when done.*

	Errors -- including "no info in Atlas for this type" -- are expressed by
	returning a machine that is a constantly-erroring thunk.
*/
func (slab *marshalSlab) requisitionMachine(forThis reflect.Type) MarshalMachine {
	off := len(slab.rows)
	slab.grow()
	row := &slab.rows[off]
	m := &row.errThunkMarshalMachine
	m.err = fmt.Errorf("no machine found")
	return m
}

func (s *marshalSlab) grow() {
	s.rows = append(s.rows, marshalSlabRow{})
}

func (s *marshalSlab) release() {
	s.rows = s.rows[0 : len(s.rows)-1]
}

type errThunkMarshalMachine struct {
	err error
}

func (m *errThunkMarshalMachine) Reset(_ *marshalSlab, _ reflect.Value, _ reflect.Type) error {
	return m.err
}
func (m *errThunkMarshalMachine) Step(d *MarshalDriver, s *marshalSlab, tok *Token) (done bool, err error) {
	return true, m.err
}
{'fraction_non_alphanumeric': 0.09440298507462687, 'fraction_numerical': 0.0014925373134328358, 'mean_word_length': 4.330019880715706, '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': '7015696', 'n_tokens_mistral': 913, 'n_tokens_neox': 865, 'n_words': 275}