compiler

package
v0.0.0-...-ca745db Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2026 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package compiler lowers the AST to bytecode (an ISeq tree).

Each method body and the program top level becomes one ISeq. Locals are resolved to flat slot indices here (Phase 0 has no closures, so each ISeq has a single flat local table; depth-addressed envs arrive with blocks in Phase 1, plan §6).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compile

func Compile(prog *ast.Program) (iseq *bytecode.ISeq, err error)

Compile lowers a Program into the top-level ISeq, treating string literals as UTF-8 (the default source encoding).

func CompileWithEncoding

func CompileWithEncoding(prog *ast.Program, srcEnc string) (iseq *bytecode.ISeq, err error)

CompileWithEncoding lowers a Program whose source declared srcEnc (a canonical encoding name, or "" for UTF-8) via a `# encoding:` magic comment, so string literals carry that encoding.

func CompileWithLocals

func CompileWithLocals(prog *ast.Program, localNames []string) (iseq *bytecode.ISeq, err error)

CompileWithLocals lowers prog for a Binding eval: it compiles in a child scope whose parent holds the binding's locals (by slot), so references to them resolve at depth 1 — reads and writes reach the binding's environment when the ISeq is run with that environment as the parent — while any new locals are scratch in the child frame.

func MagicSourceEncoding

func MagicSourceEncoding(src string) string

MagicSourceEncoding returns the canonical registry encoding name declared by a `# encoding:` / `# coding:` magic comment on the first line of src (or the second when the first is a shebang), or "" for UTF-8 or no declaration. Only the encodings the negotiation cares about are recognised by canonical spelling; anything else (including plain UTF-8) yields "" so literals keep the default.

Types

type Compiler

type Compiler struct {
	// contains filtered or unexported fields
}

Compiler walks the AST, maintaining a stack of builders.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL