Documentation ¶
Overview ¶
TODO: look for ways to split this code up better.
Index ¶
- Variables
- func Asset(name string) ([]byte, error)
- func AssetDir(name string) ([]string, error)
- func AssetInfo(name string) (os.FileInfo, error)
- func AssetNames() []string
- func DumpToString(c codeSequence) string
- func IsLoopError(e error) bool
- func LoopShouldEnd(e error) bool
- func MustAsset(name string) []byte
- func RestoreAsset(dir, name string) error
- func RestoreAssets(dir, name string) error
- type Boolean
- type CodeList
- type CodePosition
- type CodeQuotation
- type Dict
- type Double
- type Error
- type GoFunc
- type GoWord
- type Integer
- type Lenable
- type Machine
- func (m *Machine) AddGoWordWithStack(name, stackEffect, docstring string, impl GoWord)
- func (m *Machine) AppendToHelpTopic(topic, content string)
- func (m *Machine) CallQuote(q *Quotation) error
- func (m *Machine) ExecuteQuotation() error
- func (m *Machine) ExecuteString(code string, pos CodePosition) (err error)
- func (m *Machine) ImportPISCAsset(assetkey string) error
- func (m *Machine) LoadModules(modules ...Module) error
- func (m *Machine) LogAndResetDispatchCount(w io.Writer, shouldLog bool)
- func (m *Machine) PopValue() StackEntry
- func (m *Machine) PushValue(entry StackEntry)
- type Module
- type PISCReader
- type Quotation
- type StackEntry
- type String
- type Symbol
- type Vector
Constants ¶
This section is empty.
Variables ¶
var ( EOF = fmt.Errorf("End of file") EncodingFault = fmt.Errorf("Encoding error!") ConditionalTypeError = fmt.Errorf("Expected a boolean value, but didn't find it.") WordDefParenExpectedError = fmt.Errorf("Word definitions require a stack effect comment!") QuotationTypeError = fmt.Errorf("Expected Quotation value, but didn't find it.") InvalidAddTypeError = fmt.Errorf("Expected two integer values, but didn't find them.") UnexpectedStackDashError = fmt.Errorf("Found unexpected -- in stack annotation") ParenBeforeStackDashError = fmt.Errorf("Found ) before -- in stack annotation") InvalidPrefixCharError = fmt.Errorf("Found invalid character in prefix definition") ExitingProgram = fmt.Errorf("User called `quit`, terminating program") )
var ErrAttemtToIncrementNonNumber = fmt.Errorf("Attempted to increment a non-integer")
var ErrBreakLoop = errors.New("Breaking out of a loop")
var ErrContinueLoop = errors.New("Early exit on a Loop")
var ErrLocalNotFound = fmt.Errorf("Local variable not found!")
var ErrMissingKey = Error{ // contains filtered or unexported fields }
var ErrNoLocals = fmt.Errorf("No locals to try!")
var ErrNoLocalsExist = fmt.Errorf("A local frame hasn't been allocated with get-locals!")
var InvalidIRCMessage = fmt.Errorf("IRC message formmated incorrectly")
var LocalFuncRun = fmt.Errorf("Nothing was wrong")
var ModBoolCore = Module{
Author: "Andrew Owen",
Name: "BoolCore",
License: "MIT",
DocString: "The 3 basic boolean operation, and/or and not",
Load: loadBoolCore,
}
var ModDebugCore = Module{
Author: "Andrew Owen",
Name: "DebugCore",
License: "MIT",
DocString: "The debug words used in PISC",
Load: loadDebugCore,
}
var ModDictionaryCore = Module{
Author: "Andrew Owen",
Name: "DictionaryCore",
License: "MIT",
Load: loadDictMod,
DocString: "Words for manipulating dictionaries",
}
var ModHelpCore = Module{
Author: "Andrew Owen",
Name: "HelpCore",
License: "MIT",
DocString: "A function to look up help for words",
Load: loadHelpCore,
}
TODO: Indicate modules that this one depends on?
var ModIOCore = Module{
Author: "Andrew Owen",
Name: "IOCore",
License: "MIT",
DocString: "Some File I/O bits",
Load: loadIOCore,
}
var ModIRCKit = Module{
Author: "Andrew Owen",
Name: "IRCKit",
License: "MIT",
DocString: "A wrapper around IRC, built to make it easy to write IRC bots",
Load: loadIRCKit,
}
var ModLocalsCore = Module{
Author: "Andrew Owen",
Name: "LocalsCore",
License: "MIT",
DocString: "Words for manipulating local variables",
Load: loadLocalCore,
}
var ModLoopCore = Module{
Author: "Andrew Owen",
Name: "LoopCore",
License: "MIT",
DocString: "Implements basic loops",
Load: loadLoopCore,
}
var ModMathCore = Module{
Author: "Andreb Owen",
Name: "MathCore",
License: "MIT",
DocString: `Basic math stuff.`,
Load: loadMathCore,
}
var ModMetaQuoation = Module{
Author: "Andrew Owen",
Name: "MetaQuotation",
License: "MIT",
DocString: "Words that manipulate Quotations. Use with care",
Load: loadQuotWords,
}
var ModPISCCore = Module{
Author: "Andrew Owen",
Name: "PISCCore",
License: "MIT",
DocString: "Eventally, the small batch of core PISC words",
Load: loadPISCCore,
}
var ModRandomCore = Module{
Author: "Andrew Owen",
Name: "RandomCore",
License: "MIT",
DocString: "Functions for random choice",
Load: loadRandy,
}
var ModStringsCore = Module{
Author: "Andrew Owen",
Name: "StringCore",
License: "MIT",
DocString: "Various string-related functions",
Load: loadStringCore,
}
var ModSymbolCore = Module{
Author: "Andrew Owen",
Name: "SymbolCore",
License: "MIT",
DocString: "Generate and compare symbols",
Load: loadSymbolCore,
}
var ModVectorCore = Module{
Author: "Andrew Owen",
Name: "VectorCore",
License: "MIT",
DocString: "Words for creating and manipulating vectors",
Load: loadVectorCore,
}
var NL = "\n"
var StandardModules = []Module{ ModErrorsCore, ModLoopCore, ModLocalsCore, ModDictionaryCore, ModHelpCore, ModStringsCore, ModMathCore, ModBoolCore, ModVectorCore, ModSymbolCore, ModRandomCore, ModPISCCore, }
These are the standard libraries that are currently trusted to not cause problems in general
var WordNotFound = fmt.Errorf("word was undefined")
Functions ¶
func Asset ¶
Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.
func AssetDir ¶
AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:
data/ foo.txt img/ a.png b.png
then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.
func AssetInfo ¶
AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.
func IsLoopError ¶
func LoopShouldEnd ¶
func MustAsset ¶
MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.
func RestoreAsset ¶
RestoreAsset restores an asset under the given directory
func RestoreAssets ¶
RestoreAssets restores an asset under the given directory recursively
Types ¶
type CodeList ¶
type CodeList struct { CodePosition Idx int Code string // This is for error handling purposes only, indicating where a given word defintion starts FileName string }
type CodePosition ¶
The plan is to hav the Source field indicate where this code came from. Potential values are currently stdin: file: db:
type CodeQuotation ¶
type CodeQuotation struct { Idx int Words []*word CodePositions []CodePosition }
type Dict ¶
type Dict map[string]StackEntry
Dict is the wrapper around dictionaries. TODO: Find a way to support dicts with arbitrary keys, not just strings
func MakeReader ¶
func MakeReader(reader PISCReader) Dict
type Machine ¶
type Machine struct { // TODO: add a stack pointer so that we can keep from re-allocating a lot. // stackPtr int Values []StackEntry // Keep a list of loaded modules names here, for doing some detection LoadedModules []Module // Keep a list of all the functions grouped by which module defined them ModuleFunctions map[string][]string // This is reallocated when locals are used Locals []map[string]StackEntry // A map from words to slices of words. DefinedWords map[string]*CodeQuotation // A map from prefixes to prefix words PrefixWords map[string]*CodeQuotation // A map from words to predefined words (words built in go) PredefinedWords map[string]GoWord // TODO: try to work this out later. DefinedStackComments map[string]string HelpDocs map[string]string // Each time we are asked for a symbol, supply the value here, then increment SymbolIncr int64 // Budgeting information NumDispatches int64 IsBudgeted bool DispatchBudget int64 DebugTrace string // Current code location CurrentPosition CodePosition // contains filtered or unexported fields }
func (*Machine) AddGoWordWithStack ¶
func (*Machine) AppendToHelpTopic ¶
func (*Machine) ExecuteString ¶
func (m *Machine) ExecuteString(code string, pos CodePosition) (err error)
func (*Machine) ImportPISCAsset ¶
func (*Machine) LoadModules ¶
LoadModules Load a bunch of modules into this instance of the VM
func (*Machine) LogAndResetDispatchCount ¶
func (*Machine) PopValue ¶
func (m *Machine) PopValue() StackEntry
func (*Machine) PushValue ¶
func (m *Machine) PushValue(entry StackEntry)
Append uses an allocation pattern via Go to amortize the number of allocations performed
type Module ¶
type Module struct { Author string Name string License string DocString string Load func(m *Machine) error }
Module The type for a function that extends PISC via adding words
type PISCReader ¶
type PISCReader interface { io.RuneReader io.ByteReader io.Reader ReadString(delim byte) (string, error) }
type Quotation ¶
type Quotation struct {
// contains filtered or unexported fields
}
This is a separate sematic from arrays.