A Writer is an encoder for GC programs.
The typical use of a Writer is to call Init, maybe call Debug, make a sequence of Ptr, Advance, Repeat, and Append calls to describe the data type, and then finally call End.
type Writer struct {
// contains filtered or unexported fields
}
func (w *Writer) Append(prog []byte, n int64)
Append emits the given GC program into the current output. The caller asserts that the program emits n bits (describes n words), and Append panics if that is not true.
func (w *Writer) BitIndex() int64
BitIndex returns the number of bits written to the bit stream so far.
func (w *Writer) Debug(out io.Writer)
Debug causes the writer to print a debugging trace to out during future calls to methods like Ptr, Advance, and End. It also enables debugging checks during the encoding.
func (w *Writer) End()
End marks the end of the program, writing any remaining bytes.
func (w *Writer) Init(writeByte func(byte))
Init initializes w to write a new GC program by calling writeByte for each byte in the program.
func (w *Writer) Ptr(index int64)
Ptr emits a 1 into the bit stream at the given bit index. that is, it records that the index'th word in the object memory is a pointer. Any bits between the current index and the new index are set to zero, meaning the corresponding words are scalars.
func (w *Writer) Repeat(n, c int64)
Repeat emits an instruction to repeat the description of the last n words c times (including the initial description, c+1 times in total).
func (w *Writer) ShouldRepeat(n, c int64) bool
ShouldRepeat reports whether it would be worthwhile to use a Repeat to describe c elements of n bits each, compared to just emitting c copies of the n-bit description.
func (w *Writer) ZeroUntil(index int64)
ZeroUntil adds zeros to the bit stream until reaching the given index; that is, it records that the words from the most recent pointer until the index'th word are scalars. ZeroUntil is usually called in preparation for a call to Repeat, Append, or End.