pisc

package module
Version: v0.0.0-...-6c51501 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2018 License: MIT Imports: 21 Imported by: 0

README

PISC

Position Independent Source Code. A small, stack-based, concatenative language.

About

PISC's source and documentation are hosted at https://pisc.junglecoder.com/ . A quick starter can be found at PISC in Y Minutes

Building

PISC requires go 1.9+ to build. Installation instructions here

Once go is installed, you'll (currently) need to run git clone https://github.com/yumaikas/PISC-mirror "$GOPATH/src/pisc" Running cd $GOPATH/src/pisc && go get -u && go build -o pisc will fetch depenencies and get you a PISC executable. You can launch a REPL with pisc -i and play with it there.

Playground

PISC has a playground at https://pisc.junglecoder.com/playground/

Flags

Running pisc help will dump out current information about avaiable flags

Documentation

Overview

TODO: look for ways to split this code up better.

Index

Constants

This section is empty.

Variables

View Source
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")
)
View Source
var ErrAttemtToIncrementNonNumber = fmt.Errorf("Attempted to increment a non-integer")
View Source
var ErrBreakLoop = errors.New("Breaking out of a loop")
View Source
var ErrContinueLoop = errors.New("Early exit on a Loop")
View Source
var ErrLocalNotFound = fmt.Errorf("Local variable not found!")
View Source
var ErrMissingKey = Error{
	// contains filtered or unexported fields
}
View Source
var ErrNoLocals = fmt.Errorf("No locals to try!")
View Source
var ErrNoLocalsExist = fmt.Errorf("A local frame hasn't been allocated with get-locals!")
View Source
var InvalidIRCMessage = fmt.Errorf("IRC message formmated incorrectly")
View Source
var LocalFuncRun = fmt.Errorf("Nothing was wrong")
View Source
var ModBoolCore = Module{
	Author:    "Andrew Owen",
	Name:      "BoolCore",
	License:   "MIT",
	DocString: "The 3 basic boolean operation, and/or and not",
	Load:      loadBoolCore,
}
View Source
var ModDebugCore = Module{
	Author:    "Andrew Owen",
	Name:      "DebugCore",
	License:   "MIT",
	DocString: "The debug words used in PISC",
	Load:      loadDebugCore,
}
View Source
var ModDictionaryCore = Module{
	Author:    "Andrew Owen",
	Name:      "DictionaryCore",
	License:   "MIT",
	Load:      loadDictMod,
	DocString: "Words for manipulating dictionaries",
}
View Source
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?

View Source
var ModIOCore = Module{
	Author:    "Andrew Owen",
	Name:      "IOCore",
	License:   "MIT",
	DocString: "Some File I/O bits",
	Load:      loadIOCore,
}
View Source
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,
}
View Source
var ModLocalsCore = Module{
	Author:    "Andrew Owen",
	Name:      "LocalsCore",
	License:   "MIT",
	DocString: "Words for manipulating local variables",
	Load:      loadLocalCore,
}
View Source
var ModLoopCore = Module{
	Author:    "Andrew Owen",
	Name:      "LoopCore",
	License:   "MIT",
	DocString: "Implements basic loops",
	Load:      loadLoopCore,
}
View Source
var ModMathCore = Module{
	Author:    "Andreb Owen",
	Name:      "MathCore",
	License:   "MIT",
	DocString: `Basic math stuff.`,
	Load:      loadMathCore,
}
View Source
var ModMetaQuoation = Module{
	Author:    "Andrew Owen",
	Name:      "MetaQuotation",
	License:   "MIT",
	DocString: "Words that manipulate Quotations. Use with care",
	Load:      loadQuotWords,
}
View Source
var ModPISCCore = Module{
	Author:    "Andrew Owen",
	Name:      "PISCCore",
	License:   "MIT",
	DocString: "Eventally, the small batch of core PISC words",
	Load:      loadPISCCore,
}
View Source
var ModRandomCore = Module{
	Author:    "Andrew Owen",
	Name:      "RandomCore",
	License:   "MIT",
	DocString: "Functions for random choice",
	Load:      loadRandy,
}
View Source
var ModStringsCore = Module{
	Author:    "Andrew Owen",
	Name:      "StringCore",
	License:   "MIT",
	DocString: "Various string-related functions",
	Load:      loadStringCore,
}
View Source
var ModSymbolCore = Module{
	Author:    "Andrew Owen",
	Name:      "SymbolCore",
	License:   "MIT",
	DocString: "Generate and compare symbols",
	Load:      loadSymbolCore,
}
View Source
var ModVectorCore = Module{
	Author:    "Andrew Owen",
	Name:      "VectorCore",
	License:   "MIT",
	DocString: "Words for creating and manipulating vectors",
	Load:      loadVectorCore,
}
View Source
var NL = "\n"

These are the standard libraries that are currently trusted to not cause problems in general

View Source
var WordNotFound = fmt.Errorf("word was undefined")

Functions

func Asset

func Asset(name string) ([]byte, error)

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

func AssetDir(name string) ([]string, error)

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

func AssetInfo(name string) (os.FileInfo, error)

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 AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func DumpToString

func DumpToString(c codeSequence) string

TODO: See about this...

func IsLoopError

func IsLoopError(e error) bool

func LoopShouldEnd

func LoopShouldEnd(e error) bool

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

Types

type Boolean

type Boolean bool

Boolean is the PISC wrapper around bools

func (Boolean) String

func (b Boolean) String() string

func (Boolean) Type

func (b Boolean) Type() string

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

type CodePosition struct {
	LineNumber int
	Offset     int
	Source     string
}

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

func (Dict) Length

func (dict Dict) Length() int

func (Dict) String

func (dict Dict) String() string

func (Dict) Type

func (dict Dict) Type() string

type Double

type Double float64

Double is the PISC wrapper aroudn float64

func (Double) Add

func (d Double) Add(n number) number

func (Double) Divide

func (d Double) Divide(n number) number

func (Double) LessThan

func (d Double) LessThan(n number) Boolean

func (Double) Multiply

func (d Double) Multiply(n number) number

func (Double) Negate

func (d Double) Negate() number

func (Double) String

func (d Double) String() string

func (Double) Type

func (d Double) Type() string

type Error

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

func (Error) Error

func (e Error) Error() string

type GoFunc

type GoFunc GoWord

func (GoFunc) String

func (g GoFunc) String() string

func (GoFunc) Type

func (g GoFunc) Type() string

type GoWord

type GoWord func(*Machine) error

GoWord a wrapper for functions that implement pieces of PISC

var CommentImpl GoWord = func(m *Machine) error {
	return nil
}

func NilWord

func NilWord(f func(*Machine)) GoWord

NilWord a wrapper for GoWords that should never fail

type Integer

type Integer int

Integer is the PISC wrapper around ints

func (Integer) Add

func (i Integer) Add(n number) number

func (Integer) Divide

func (i Integer) Divide(n number) number

func (Integer) LessThan

func (i Integer) LessThan(n number) Boolean

func (Integer) Multiply

func (i Integer) Multiply(n number) number

func (Integer) Negate

func (i Integer) Negate() number

func (Integer) String

func (i Integer) String() string

func (Integer) Type

func (i Integer) Type() string

type Lenable

type Lenable interface {
	Length() int
}

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 (m *Machine) AddGoWordWithStack(name, stackEffect, docstring string, impl GoWord)

func (*Machine) AppendToHelpTopic

func (m *Machine) AppendToHelpTopic(topic, content string)

func (*Machine) CallQuote

func (m *Machine) CallQuote(q *Quotation) error

func (*Machine) ExecuteQuotation

func (m *Machine) ExecuteQuotation() error

Used for call word.

func (*Machine) ExecuteString

func (m *Machine) ExecuteString(code string, pos CodePosition) (err error)

func (*Machine) ImportPISCAsset

func (m *Machine) ImportPISCAsset(assetkey string) error

func (*Machine) LoadModules

func (m *Machine) LoadModules(modules ...Module) error

LoadModules Load a bunch of modules into this instance of the VM

func (*Machine) LogAndResetDispatchCount

func (m *Machine) LogAndResetDispatchCount(w io.Writer, shouldLog bool)

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.

func (*Quotation) String

func (q *Quotation) String() string

func (*Quotation) Type

func (q *Quotation) Type() string

type StackEntry

type StackEntry interface {
	String() string
	Type() string
}

type String

type String string

String is the PISC wrapper around strings

func (String) Length

func (s String) Length() int

func (String) String

func (s String) String() string

func (String) Type

func (s String) Type() string

type Symbol

type Symbol int64

Symbol is used for unique symboles

func (Symbol) String

func (s Symbol) String() string

func (Symbol) Type

func (s Symbol) Type() string

type Vector

type Vector struct {
	Elements []StackEntry
}

Vectors are mutable pointers to slices.

func (*Vector) Length

func (v *Vector) Length() int

func (*Vector) String

func (v *Vector) String() string

func (*Vector) Type

func (v *Vector) Type() string

Directories

Path Synopsis
cmd
libs

Jump to

Keyboard shortcuts

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