func()

in internal/compile/serial.go [96:138]


func (prog *Program) Encode() []byte {
	var e encoder
	e.p = append(e.p, magic...)
	e.p = append(e.p, "????"...) // string data offset; filled in later
	e.int(Version)
	e.string(prog.Toplevel.Pos.Filename())
	e.bindings(prog.Loads)
	e.int(len(prog.Names))
	for _, name := range prog.Names {
		e.string(name)
	}
	e.int(len(prog.Constants))
	for _, c := range prog.Constants {
		switch c := c.(type) {
		case string:
			e.int(0)
			e.string(c)
		case Bytes:
			e.int(1)
			e.string(string(c))
		case int64:
			e.int(2)
			e.int64(c)
		case float64:
			e.int(3)
			e.uint64(math.Float64bits(c))
		case *big.Int:
			e.int(4)
			e.string(c.Text(10))
		}
	}
	e.bindings(prog.Globals)
	e.function(prog.Toplevel)
	e.int(len(prog.Functions))
	for _, fn := range prog.Functions {
		e.function(fn)
	}

	// Patch in the offset of the string data section.
	binary.LittleEndian.PutUint32(e.p[4:8], uint32(len(e.p)))

	return append(e.p, e.s...)
}