compiler

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExternDirective    src.Directive = "extern"
	BindDirective      src.Directive = "bind"
	AutoportsDirective src.Directive = "autoports"
)

Variables

This section is empty.

Functions

func JSONDump

func JSONDump(v any) string

JSONDump is for debugging purposes only!

func ParseRef

func ParseRef(ref string) src.EntityRef

ParseRef assumes string-ref has form of <pkg_name>.<entity_name≥ or just <entity_name>.

func Pointer

func Pointer[T any](v T) *T

Pointer allows to avoid creating of temporary variables just to take pointers.

Types

type Analyzer

type Analyzer interface {
	AnalyzeExecutableBuild(mod src.Build, mainPkgName string) (src.Build, *Error)
}

type Backend

type Backend interface {
	GenerateTarget(*ir.Program) ([]byte, error)
}

type Compiler

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

func New

func New(
	parser Parser,
	desugarer Desugarer,
	analyzer Analyzer,
	irgen IRGenerator,
	backend Backend,
) Compiler

New creates new Compiler instance. You can omit irgen and backend if all you need is Analyze method.

func (Compiler) Compile

func (c Compiler) Compile(
	ctx context.Context,
	rawBuild RawBuild,
	workdirPath string,
	mainPkgName string,
) ([]byte, error)

func (Compiler) CompileToIR

func (c Compiler) CompileToIR(
	ctx context.Context,
	rawBuild RawBuild,
	workdirPath string,
	mainPkgName string,
) (*ir.Program, *Error)

type Desugarer

type Desugarer interface {
	Desugar(build src.Build) (src.Build, *Error)
}

type Error

type Error struct {
	Err      error
	Location *src.Location
	Meta     *src.Meta
}

Error represents end-user error that preserves not only message but also location in sourcecode where error occurred. It must be properly used by all compiler's dependencies so user face human-readable error.

func (Error) Error

func (e Error) Error() string

Error simply implements error interface.

func (Error) Merge

func (e Error) Merge(child *Error) *Error

Merge merges e (parent) Error with the child Error, every data child has is preferred to the parent's. Parent provides broad location while child provide more accurate. Ideally there's no need to wrap errors the old fashioned way by imitating stack-trace. Location should provide that.

type IRGenerator

type IRGenerator interface {
	Generate(ctx context.Context, build src.Build, mainPkgName string) (*ir.Program, *Error)
}

type Parser

type Parser interface {
	ParseModules(rawMods map[src.ModuleRef]RawModule) (map[src.ModuleRef]src.Module, *Error)
}

type RawBuild

type RawBuild struct {
	EntryModRef src.ModuleRef
	Modules     map[src.ModuleRef]RawModule
}

type RawModule

type RawModule struct {
	Manifest src.ModuleManifest    // Manifest must be parsed by builder before passing into compiler
	Packages map[string]RawPackage // Packages themselves on the other hand can be parsed by compiler
}

type RawPackage

type RawPackage map[string][]byte

type STDLib

type STDLib interface {
	Emitter() src.Interface
	Destructor() src.Interface
	Blocker() src.Interface
}

Directories

Path Synopsis
Package analyzer implements source code static semantic analysis.
Package analyzer implements source code static semantic analysis.
backend
Package irgen implements IR generation from source code.
Package irgen implements IR generation from source code.
Package parser implements source code parsing.
Package parser implements source code parsing.

Jump to

Keyboard shortcuts

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