initializer

package
v0.0.0-...-c8d6cdc Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 30 Imported by: 0

README

README for the initializer

The initializer package supplies an Initializer struct which contains the data and supplies the methods necessary to initialize a Pipefish script, by creating and directing a parser and a compiler to operate on a VM. The Initializer returns a Compiler capable of dealing with runtime compilation of requests from the REPL: the Initializer can then be discarded together with its data.

There is one Initializer per module, as with compilers and parsers: an Initializer can spawn further Intitializers recursively to initialize modules and external services.

The initializer package consists of:

  • deserializer.go, which is used to deserialize the APIs of external services.
  • initializer.go, the main file directing initialization.
  • getters.go, which supplies some miscellaneous utility functions for getting and transforming data.
  • gohandler.go which does housekeeping for the Go interop.
  • gogen.go which generates Golang source files.

Fields of note in the Initializer struct are its compiler (naturally); its parser (a shortcut to the parser of the compiler); Common, a bindle of data that all the initializers of all the modules need to share; and GoBucket, which is used to accumulate the miscellaneous data swept up during parsing that we need to generate Go source files.

Documentation

Index

Constants

View Source
const DUMMY = 4294967295

The maximum value of a `uint32`. Used as a dummy/sentinel value when `0` is not appropriate.

Variables

View Source
var BUILTIN_FUNCTION_CONVERTER = map[string](func(t uint32, v any) any){
	"bool":   func(t uint32, v any) any { return v.(bool) },
	"float":  func(t uint32, v any) any { return v.(float64) },
	"int":    func(t uint32, v any) any { return v.(int) },
	"rune":   func(t uint32, v any) any { return v.(rune) },
	"string": func(t uint32, v any) any { return v.(string) },
}

Maps for converting base types.

View Source
var BUILTIN_VALUE_CONVERTER = map[string]any{
	"bool":   (*bool)(nil),
	"float":  (*float64)(nil),
	"int":    (*int)(nil),
	"rune":   (*rune)(nil),
	"string": (*string)(nil),
}
View Source
var INTEROP_TOKEN = &token.Token{Source: "golang interop"}
View Source
var LINKING_TOKEN = &token.Token{Source: "Pipefish linker"}

Tokens to return when no token is available.

View Source
var PARSEABLE = []declarationType{cloneDeclaration, structDeclaration, constantDeclaration,
	variableDeclaration, functionDeclaration, commandDeclaration}

Having declared the names of the various types and functions of the namespaces, we can now parse the chunks of actual code in the function bodies, `given` blocks, assignments, validation.

Functions

func AsBling

func AsBling(s string) parser.TypeNode

func Do

func Do(host, service, line, username, password string) string

func MakeAstTypeFrom

func MakeAstTypeFrom(s string) parser.TypeNode

func NewCommonInitializerBindle

func NewCommonInitializerBindle(store *values.Map, services map[string]*compiler.Compiler) *commonInitializerBindle

Initializes the `CommonInitializerBindle`.

func StartCompiler

func StartCompiler(scriptFilepath, sourcecode string, hubServices map[string]*compiler.Compiler, store *values.Map) *compiler.Compiler

func StartCompilerFromFilepath

func StartCompilerFromFilepath(filepath string, svs map[string]*compiler.Compiler, store *values.Map) (*compiler.Compiler, error)

Initializes a compiler given the filepath.

func SummaryString

func SummaryString(dec tokenizedCode) string

TODO --- we could fiddle with the api() method of the tokenized chunks to get most of this done byt that too.

func Values

func Values(twa *parser.TypeWithArguments) []values.Value

TODO, we can probably replace the Arguments field with just this.

Types

type ExternalCallToHubHandler

type ExternalCallToHubHandler struct {
	Evaluator    func(line string) values.Value
	ProblemFn    func() bool
	SerializeApi func() string
}

func (ExternalCallToHubHandler) Evaluate

func (ex ExternalCallToHubHandler) Evaluate(line string) values.Value

func (ExternalCallToHubHandler) GetAPI

func (es ExternalCallToHubHandler) GetAPI() string

func (ExternalCallToHubHandler) Problem

func (es ExternalCallToHubHandler) Problem() *err.Error

type ExternalHttpCallHandler

type ExternalHttpCallHandler struct {
	Host         string
	Service      string
	Username     string
	Password     string
	Deserializer func(valAsString string) values.Value
}

func (ExternalHttpCallHandler) Evaluate

func (es ExternalHttpCallHandler) Evaluate(line string) values.Value

func (ExternalHttpCallHandler) GetAPI

func (es ExternalHttpCallHandler) GetAPI() string

func (ExternalHttpCallHandler) Problem

func (es ExternalHttpCallHandler) Problem() *err.Error

type Initializer

type Initializer struct {
	P *parser.Parser // The parser for the module being initialized.

	Common *commonInitializerBindle // The information all the initializers have in Common.
	// contains filtered or unexported fields
}

Definition of the Initializer type.

func NewInitializer

func NewInitializer(common *commonInitializerBindle) *Initializer

Makes a new initializer.

func (*Initializer) Add

func (iz *Initializer) Add(functionName string, f *parsedFunction) *parsedFunction

func (*Initializer) AddInOrder

func (iz *Initializer) AddInOrder(S []*parsedFunction, f *parsedFunction) ([]*parsedFunction, *parsedFunction)

func (*Initializer) ChunkConstOrVarDeclaration

func (iz *Initializer) ChunkConstOrVarDeclaration(isConst, private bool, docString string) (tokenizedCode, bool)

As with all the chunkers, this assumes that the p.curToken is the first token of the thing we're trying to slurp. It will end with the p.curTok being the EOF/NEWLINE terminating the declaration.

func (*Initializer) ChunkFunction

func (iz *Initializer) ChunkFunction(cmd, private bool, docString string) (*tokenizedFunctionDeclaration, bool)

As with all the chunkers, this assumes that the p.curToken is the first token of the thing we're trying to slurp. It will end with the p.curTok being the EOF/NEWLINE terminating the declaration.

func (*Initializer) ChunkFunctionSignature

func (iz *Initializer) ChunkFunctionSignature() (*tokenizedFunctionDeclaration, bool)

This wraps around chunkFunctionArguments and extracts the right name.

func (*Initializer) ChunkGolangDeclaration

func (iz *Initializer) ChunkGolangDeclaration(private bool) (tokenizedCode, bool)

func (*Initializer) ChunkImportOrExternalDeclaration

func (iz *Initializer) ChunkImportOrExternalDeclaration(isExternal, private bool, docString string) (tokenizedCode, bool)

As with all the chunkers, this assumes that the p.curToken is the first token of the thing we're trying to slurp. It will end with the p.curTok being the EOF/NEWLINE terminating the declaration.

func (*Initializer) ChunkTypeDeclaration

func (iz *Initializer) ChunkTypeDeclaration(private bool, docString string) (tokenizedCode, bool)

As with all the chunkers, this assumes that the p.curToken is the first token of the thing we're trying to slurp. It will end with the p.curTok being the EOF/NEWLINE terminating the declaration.

func (*Initializer) IsMandatoryImport

func (iz *Initializer) IsMandatoryImport(aT values.AbstractTypeInfo) bool

func (*Initializer) ParseEverythingFromFilePath

func (iz *Initializer) ParseEverythingFromFilePath(mc *vm.Vm, cpb *parser.CommonParserBindle, ccb *compiler.CommonCompilerBindle, scriptFilepath, namespacePath string) (*compiler.Compiler, error)

Just exists to wrap around the next function.

func (*Initializer) ParseEverythingFromSourcecode

func (iz *Initializer) ParseEverythingFromSourcecode(mc *vm.Vm, cpb *parser.CommonParserBindle, ccb *compiler.CommonCompilerBindle, scriptFilepath, sourcecode, namespacePath string) *compiler.Compiler

This initializes the initializer's compiler (which initializes its parser), and extracts the source code from the given file, and then calls the `parseEverything“ method, below.

func (*Initializer) SerializeApi

func (iz *Initializer) SerializeApi() string

For a description of the file format, see README-api-serialization.md

func (*Initializer) SerializedAPIToDeclarations

func (iz *Initializer) SerializedAPIToDeclarations(serializedAPI string, xserve uint32) string

TODO --- malformed data would crash the deserializer with e.g. indexing errors. We need to make this a method of the initializer so it can Throw.

Jump to

Keyboard shortcuts

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