gcprog

Imports

Imports #

"fmt"
"io"

Constants & Variables

progMaxLiteral const #

const progMaxLiteral = 127

Structs

Writer struct #

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 {
writeByte func(byte)
index int64
b [progMaxLiteral]byte
nb int
debug io.Writer
debugBuf []byte
}

Functions

Append method #

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) Append(prog []byte, n int64)

BitIndex method #

BitIndex returns the number of bits written to the bit stream so far.

func (w *Writer) BitIndex() int64

Debug method #

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) Debug(out io.Writer)

End method #

End marks the end of the program, writing any remaining bytes.

func (w *Writer) End()

Init method #

Init initializes w to write a new GC program by calling writeByte for each byte in the program.

func (w *Writer) Init(writeByte func(byte))

Ptr method #

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) Ptr(index int64)

Repeat method #

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) Repeat(n int64, c int64)

ShouldRepeat method #

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) ShouldRepeat(n int64, c int64) bool

ZeroUntil method #

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.

func (w *Writer) ZeroUntil(index int64)

byte method #

byte writes the byte x to the output.

func (w *Writer) byte(x byte)

flushlit method #

flushlit flushes any pending literal bits.

func (w *Writer) flushlit()

lit method #

lit adds a single literal bit to w.

func (w *Writer) lit(x byte)

progbits function #

progbits returns the length of the bit stream encoded by the program p.

func progbits(p []byte) int64

readvarint function #

readvarint reads a varint from p, returning the value and the remainder of p.

func readvarint(p []byte) (int64, []byte)

varint method #

varint emits the varint encoding of x.

func (w *Writer) varint(x int64)

Generated with Arrow