source

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Log

func Log(msg string, loc SourcePos, severity Severity)

Log prints a located diagnostic: the path/line/column, the message, the offending source line, and an underline of the span, all colored by severity.

Diagnostics go to stderr, where the color detection already looks, so that a program's own output (show/write/peek, on stdout) can be redirected on its own without ANSI escapes and compiler noise landing in the file.

func ReportRuntimeError

func ReportRuntimeError(err *RuntimeError)

ReportRuntimeError prints a RuntimeError: the message (located at its source span when one is known) followed by the chain of bindings that led to it.

Types

type RuntimeError

type RuntimeError struct {
	Message string
	Pos     SourcePos
	HasPos  bool
	Trace   []string
}

A RuntimeError is raised (by panic) when a program cannot continue: a non-exhaustive match, applying a non-function, a non-number passed to an arithmetic primitive, a malformed argument to write. It carries what is needed to report the failure in the programmer's terms: a message, the source span of the offending expression (when known), and a reduction trace.

The trace is the closest thing a lazy language has to a stack trace. The Go call stack is useless here — a thunk is built in one place and forced in another, so the host stack does not mirror the program's logical call structure. Instead the machine records the names of the bindings (let / module / pattern) whose evaluation was in progress when the error happened; see collectTrace in machine.go. Anonymous intermediate thunks are skipped, leaving a readable skeleton like `while reducing: a → b → c`.

RuntimeError is recovered at the run boundary (Run in machine.go). Bare, non-RuntimeError panics are left to propagate with their Go stack trace: they indicate a compiler/machine bug, not a program error.

func (*RuntimeError) Error

func (e *RuntimeError) Error() string

type Severity

type Severity string
const (
	SeverityError Severity = "error"
	SeverityInfo  Severity = "info"
)

type Source

type Source struct {
	Path string
	Text string
}

A Source is one loaded source file: its path and full text. Spans (SourcePos) point into it.

type SourcePos

type SourcePos struct {
	File   *Source
	Start  int
	Length int
}

A SourcePos is a span within a source file: a start offset and length into File.Text. The zero value (nil File) means "no known location".

func (SourcePos) To

func (a SourcePos) To(b SourcePos) SourcePos

To returns the span from the start of a to the end of b. Both must be in the same file.

Jump to

Keyboard shortcuts

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