Documentation ¶
Overview ¶
Copyright 2024-2025 Blake Felt blake.w.felt@gmail.com
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
Copyright 2024-2025 Blake Felt blake.w.felt@gmail.com
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
Copyright 2024-2025 Blake Felt blake.w.felt@gmail.com
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
Copyright 2024-2025 Blake Felt blake.w.felt@gmail.com
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
Copyright 2024-2025 Blake Felt blake.w.felt@gmail.com
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
Copyright 2024-2025 Blake Felt blake.w.felt@gmail.com
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
Copyright 2024-2025 Blake Felt blake.w.felt@gmail.com
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
Copyright 2024-2025 Blake Felt blake.w.felt@gmail.com
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
Copyright 2024-2025 Blake Felt blake.w.felt@gmail.com
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
Copyright 2024-2025 Blake Felt blake.w.felt@gmail.com
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
Copyright 2024-2025 Blake Felt blake.w.felt@gmail.com
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
Copyright 2024-2025 Blake Felt blake.w.felt@gmail.com
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
Copyright 2024-2025 Blake Felt blake.w.felt@gmail.com
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
Index ¶
- Constants
- func EntryError(entry *DictionaryEntry, format string, a ...interface{}) error
- func JoinEntryError(err error, entry *DictionaryEntry, format string, a ...interface{}) error
- func PopError(err error, entry *DictionaryEntry) error
- func PrimitiveSetup(vm *VirtualMachine) error
- func PushError(err error, entry *DictionaryEntry) error
- type Cell
- type CellAddress
- func (c CellAddress) AddToList(u *Ulp) error
- func (c CellAddress) BuildExecution(u *Ulp) (string, error)
- func (c CellAddress) Execute(vm *VirtualMachine) error
- func (c CellAddress) IsRecursive(check *WordForth) bool
- func (c CellAddress) OutputReference(u *Ulp) (string, error)
- func (c CellAddress) String() string
- type CellBranch
- func (c *CellBranch) AddToList(u *Ulp) error
- func (c *CellBranch) BuildExecution(u *Ulp) (string, error)
- func (c *CellBranch) Execute(vm *VirtualMachine) error
- func (c *CellBranch) IsRecursive(check *WordForth) bool
- func (c *CellBranch) OutputReference(u *Ulp) (string, error)
- func (c *CellBranch) String() string
- type CellBranch0
- func (c *CellBranch0) AddToList(u *Ulp) error
- func (c *CellBranch0) BuildExecution(u *Ulp) (string, error)
- func (c *CellBranch0) Execute(vm *VirtualMachine) error
- func (c *CellBranch0) IsRecursive(check *WordForth) bool
- func (c *CellBranch0) OutputReference(u *Ulp) (string, error)
- func (c *CellBranch0) String() string
- type CellDestination
- func (c *CellDestination) AddToList(u *Ulp) error
- func (c *CellDestination) BuildExecution(u *Ulp) (string, error)
- func (c *CellDestination) Execute(vm *VirtualMachine) error
- func (c *CellDestination) IsRecursive(check *WordForth) bool
- func (c *CellDestination) OutputReference(u *Ulp) (string, error)
- func (c *CellDestination) String() string
- type CellLiteral
- func (c CellLiteral) AddToList(u *Ulp) error
- func (c CellLiteral) BuildExecution(u *Ulp) (string, error)
- func (c CellLiteral) Execute(vm *VirtualMachine) error
- func (c CellLiteral) IsRecursive(check *WordForth) bool
- func (c CellLiteral) OutputReference(u *Ulp) (string, error)
- func (c CellLiteral) String() string
- type CellNumber
- func (c CellNumber) AddToList(u *Ulp) error
- func (c CellNumber) BuildExecution(u *Ulp) (string, error)
- func (c CellNumber) Execute(vm *VirtualMachine) error
- func (c CellNumber) IsRecursive(check *WordForth) bool
- func (c CellNumber) OutputReference(u *Ulp) (string, error)
- func (c CellNumber) String() string
- type CellTailCall
- func (c *CellTailCall) AddToList(u *Ulp) error
- func (c *CellTailCall) BuildExecution(u *Ulp) (string, error)
- func (c *CellTailCall) Execute(vm *VirtualMachine) error
- func (c *CellTailCall) IsRecursive(check *WordForth) bool
- func (c *CellTailCall) OutputReference(u *Ulp) (string, error)
- func (c *CellTailCall) String() string
- type Dictionary
- type DictionaryEntry
- type DictionaryEntryError
- type Flag
- type Optimizer
- type ParseArea
- type PrimitiveGo
- type PrimitiveUlp
- type PrimitiveUlpSrt
- type Stack
- type State
- type StateType
- type TokenNextType
- type Ulp
- type UlpCompileTarget
- type UlpCompileType
- type VMNumber
- type VirtualMachine
- func (vm *VirtualMachine) BuiltinEsp32() error
- func (vm *VirtualMachine) Execute(b []byte) error
- func (vm *VirtualMachine) ExecuteFile(f fs.File) error
- func (vm *VirtualMachine) ReplClose() error
- func (vm *VirtualMachine) ReplRun() error
- func (vm *VirtualMachine) ReplSetup() error
- func (vm *VirtualMachine) Reset() error
- func (vm *VirtualMachine) Setup() error
- type Word
- type WordForth
- type WordPrimitive
Constants ¶
const ( UlpCompileTargetToken = iota UlpCompileTargetSubroutine )
Variables ¶
This section is empty.
Functions ¶
func EntryError ¶
func EntryError(entry *DictionaryEntry, format string, a ...interface{}) error
func JoinEntryError ¶
func JoinEntryError(err error, entry *DictionaryEntry, format string, a ...interface{}) error
func PopError ¶
func PopError(err error, entry *DictionaryEntry) error
func PrimitiveSetup ¶
func PrimitiveSetup(vm *VirtualMachine) error
func PushError ¶
func PushError(err error, entry *DictionaryEntry) error
Types ¶
type Cell ¶
type Cell interface { Execute(*VirtualMachine) error // Compile(*Ulp) (string, error) // The compiled string for the output assembly. AddToList(*Ulp) error // Build the assembly necessary to execute this cell. BuildExecution(*Ulp) (string, error) // The string reference for this cell, used for literals // and when the cell is stored as data. OutputReference(*Ulp) (string, error) // If this cell in some way refers to the input word, return true. IsRecursive(*WordForth) bool }
A Cell is the smallest unit of address within Forth. Cells are what constitute words, stack entries, etc.
type CellAddress ¶
type CellAddress struct { Entry *DictionaryEntry // The dictionary entry with the address. Offset int // The offset within that entry. UpperByte bool // If we're aligned to the upper byte. }
A Cell representing an address in the dictionary. Used for pointers such as return addresses.
func (CellAddress) AddToList ¶
func (c CellAddress) AddToList(u *Ulp) error
func (CellAddress) BuildExecution ¶
func (c CellAddress) BuildExecution(u *Ulp) (string, error)
func (CellAddress) Execute ¶
func (c CellAddress) Execute(vm *VirtualMachine) error
func (CellAddress) IsRecursive ¶
func (c CellAddress) IsRecursive(check *WordForth) bool
func (CellAddress) OutputReference ¶
func (c CellAddress) OutputReference(u *Ulp) (string, error)
func (CellAddress) String ¶
func (c CellAddress) String() string
type CellBranch ¶
type CellBranch struct {
// contains filtered or unexported fields
}
A definite branch.
func (*CellBranch) AddToList ¶
func (c *CellBranch) AddToList(u *Ulp) error
func (*CellBranch) BuildExecution ¶
func (c *CellBranch) BuildExecution(u *Ulp) (string, error)
func (*CellBranch) Execute ¶
func (c *CellBranch) Execute(vm *VirtualMachine) error
func (*CellBranch) IsRecursive ¶
func (c *CellBranch) IsRecursive(check *WordForth) bool
func (*CellBranch) OutputReference ¶
func (c *CellBranch) OutputReference(u *Ulp) (string, error)
func (*CellBranch) String ¶
func (c *CellBranch) String() string
type CellBranch0 ¶
type CellBranch0 struct {
// contains filtered or unexported fields
}
A conditional branch.
func (*CellBranch0) AddToList ¶
func (c *CellBranch0) AddToList(u *Ulp) error
func (*CellBranch0) BuildExecution ¶
func (c *CellBranch0) BuildExecution(u *Ulp) (string, error)
func (*CellBranch0) Execute ¶
func (c *CellBranch0) Execute(vm *VirtualMachine) error
func (*CellBranch0) IsRecursive ¶
func (c *CellBranch0) IsRecursive(check *WordForth) bool
func (*CellBranch0) OutputReference ¶
func (c *CellBranch0) OutputReference(u *Ulp) (string, error)
func (*CellBranch0) String ¶
func (c *CellBranch0) String() string
type CellDestination ¶
type CellDestination struct { Addr CellAddress // the address of this destination // contains filtered or unexported fields }
A destination to branch to. Only used during compilation.
func (*CellDestination) AddToList ¶
func (c *CellDestination) AddToList(u *Ulp) error
func (*CellDestination) BuildExecution ¶
func (c *CellDestination) BuildExecution(u *Ulp) (string, error)
func (*CellDestination) Execute ¶
func (c *CellDestination) Execute(vm *VirtualMachine) error
func (*CellDestination) IsRecursive ¶
func (c *CellDestination) IsRecursive(check *WordForth) bool
func (*CellDestination) OutputReference ¶
func (c *CellDestination) OutputReference(u *Ulp) (string, error)
func (*CellDestination) String ¶
func (c *CellDestination) String() string
type CellLiteral ¶
type CellLiteral struct {
// contains filtered or unexported fields
}
A Cell that places the underlying cell on the stack. Used for execution tokens.
func (CellLiteral) AddToList ¶
func (c CellLiteral) AddToList(u *Ulp) error
func (CellLiteral) BuildExecution ¶
func (c CellLiteral) BuildExecution(u *Ulp) (string, error)
func (CellLiteral) Execute ¶
func (c CellLiteral) Execute(vm *VirtualMachine) error
func (CellLiteral) IsRecursive ¶
func (c CellLiteral) IsRecursive(check *WordForth) bool
func (CellLiteral) OutputReference ¶
func (c CellLiteral) OutputReference(u *Ulp) (string, error)
func (CellLiteral) String ¶
func (c CellLiteral) String() string
type CellNumber ¶
type CellNumber struct {
Number uint16 // The unsigned number that this cell represents.
}
A Cell representing a number.
func GetCellNumber ¶
func GetCellNumber(c Cell) (CellNumber, error)
func (CellNumber) AddToList ¶
func (c CellNumber) AddToList(u *Ulp) error
func (CellNumber) BuildExecution ¶
func (c CellNumber) BuildExecution(u *Ulp) (string, error)
func (CellNumber) Execute ¶
func (c CellNumber) Execute(vm *VirtualMachine) error
func (CellNumber) IsRecursive ¶
func (c CellNumber) IsRecursive(check *WordForth) bool
func (CellNumber) OutputReference ¶
func (c CellNumber) OutputReference(u *Ulp) (string, error)
func (CellNumber) String ¶
func (c CellNumber) String() string
type CellTailCall ¶
type CellTailCall struct {
// contains filtered or unexported fields
}
Used during an optimization pass to add tail calls.
func (*CellTailCall) AddToList ¶
func (c *CellTailCall) AddToList(u *Ulp) error
func (*CellTailCall) BuildExecution ¶
func (c *CellTailCall) BuildExecution(u *Ulp) (string, error)
func (*CellTailCall) Execute ¶
func (c *CellTailCall) Execute(vm *VirtualMachine) error
func (*CellTailCall) IsRecursive ¶
func (c *CellTailCall) IsRecursive(check *WordForth) bool
func (*CellTailCall) OutputReference ¶
func (c *CellTailCall) OutputReference(u *Ulp) (string, error)
func (*CellTailCall) String ¶
func (c *CellTailCall) String() string
type Dictionary ¶
type Dictionary struct { Entries []*DictionaryEntry // contains filtered or unexported fields }
The Forth Dictionary. This architecture uses individual entries representing words rather than a flat cell structure.
func (*Dictionary) AddEntry ¶
func (d *Dictionary) AddEntry(entry *DictionaryEntry) error
func (*Dictionary) FindName ¶
func (d *Dictionary) FindName(name string) (*DictionaryEntry, error)
func (*Dictionary) LastForthWord ¶
func (d *Dictionary) LastForthWord() (*WordForth, error)
func (*Dictionary) Setup ¶
func (d *Dictionary) Setup(vm *VirtualMachine) error
Set up the empty dictionary.
type DictionaryEntry ¶
type DictionaryEntry struct { Name string NameLower string Word Word Flag Flag // contains filtered or unexported fields }
A Dictionary entry. Contains the name, the word itself, and the flags.
func (*DictionaryEntry) AddToList ¶
func (d *DictionaryEntry) AddToList(u *Ulp) error
func (*DictionaryEntry) BodyLabel ¶
func (d *DictionaryEntry) BodyLabel() string
func (*DictionaryEntry) ClearVisited ¶
func (d *DictionaryEntry) ClearVisited()
func (DictionaryEntry) Details ¶
func (d DictionaryEntry) Details() string
func (DictionaryEntry) String ¶
func (d DictionaryEntry) String() string
type DictionaryEntryError ¶
type DictionaryEntryError struct { Entry *DictionaryEntry Format string Args []interface{} }
func (DictionaryEntryError) Error ¶
func (e DictionaryEntryError) Error() string
type Flag ¶
type Flag struct { Hidden bool // This word is hidden from being found. Immediate bool // This word should be executed immediately. Data bool // This Forth word is data and should not be optimized. GlobalData bool // This data word should be marked as .global in the output. // contains filtered or unexported fields }
Flags associated with each word
type ParseArea ¶
type ParseArea struct {
// contains filtered or unexported fields
}
The input parse area.
type PrimitiveGo ¶
type PrimitiveGo func(*VirtualMachine, *DictionaryEntry) error
The Go code for a primitive Word.
type PrimitiveUlp ¶
type PrimitiveUlp struct { Asm []string Next TokenNextType }
The ULP assembly for a primitive Word that uses token threading. type PrimitiveUlp []string
type PrimitiveUlpSrt ¶
type PrimitiveUlpSrt struct { Asm []string // the assembly, not including NEXT if standard NonStandardNext bool // this word uses a nonstandard NEXT ending }
The ULP assembly for a primitive Word that uses subroutine threading
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
The structure for stacks.
type State ¶
type State struct {
// contains filtered or unexported fields
}
func (*State) Setup ¶
func (m *State) Setup(vm *VirtualMachine) error
type TokenNextType ¶
type TokenNextType int
const ( // update the constants in 11_misc.f if this list changes TokenNextNonstandard TokenNextType = iota TokenNextNormal TokenNextSkipR2 TokenNextSkipLoad )
type Ulp ¶
type Ulp struct {
// contains filtered or unexported fields
}
func (*Ulp) BuildAssembly ¶
func (u *Ulp) BuildAssembly(vm *VirtualMachine, word string) (string, error)
Build the assembly using the word passed in as the main function. Note that the virtual machine will be unusable after this.
func (*Ulp) BuildAssemblySrt ¶
func (u *Ulp) BuildAssemblySrt(vm *VirtualMachine, word string) (string, error)
type UlpCompileType ¶
type UlpCompileType int
The type of information that we are currently cross-compiling.
const ( UlpCompileProgram UlpCompileType = iota UlpCompileData )
type VirtualMachine ¶
type VirtualMachine struct { Dictionary Dictionary // The Forth dictionary. Stack Stack // The data stack. ReturnStack Stack // The return stack. ControlFlowStack Stack // The control flow stack. DoStack Stack // A stack for compiling DO loops. ParseArea ParseArea // The input parse area. State VMNumber // The execution state for the virtual machine. Convert to type State when using. IP *CellAddress // The interpreter pointer. Base VMNumber // The number base. Out io.Writer // The output for the vm. // contains filtered or unexported fields }
The Forth virtual machine.
func (*VirtualMachine) BuiltinEsp32 ¶
func (vm *VirtualMachine) BuiltinEsp32() error
BuiltinEsp32 runs the files intended for accessing esp32 hardware.
func (*VirtualMachine) Execute ¶
func (vm *VirtualMachine) Execute(b []byte) error
Execute the given bytes.
func (*VirtualMachine) ExecuteFile ¶
func (vm *VirtualMachine) ExecuteFile(f fs.File) error
func (*VirtualMachine) ReplClose ¶ added in v0.0.4
func (vm *VirtualMachine) ReplClose() error
Close the Repl.
func (*VirtualMachine) ReplRun ¶ added in v0.0.4
func (vm *VirtualMachine) ReplRun() error
Run the read-eval-print loop.
func (*VirtualMachine) ReplSetup ¶ added in v0.0.4
func (vm *VirtualMachine) ReplSetup() error
Set up the Repl. Should be closed with ReplClose().
func (*VirtualMachine) Reset ¶
func (vm *VirtualMachine) Reset() error
type Word ¶
type Word interface { Execute(*VirtualMachine) error // Execute the word. AddToList(*Ulp) error BuildAssembly(*Ulp) (string, error) IsRecursive(*WordForth) bool }
An executable Forth Word.
type WordForth ¶
type WordForth struct { Cells []Cell // The cells that constitute this word. Entry *DictionaryEntry // The associated dictionary entry. }
A Word built using other Forth words/numbers.
func (*WordForth) Execute ¶
func (w *WordForth) Execute(vm *VirtualMachine) error
func (*WordForth) ExecuteOffset ¶
func (w *WordForth) ExecuteOffset(vm *VirtualMachine, offset int) error
func (*WordForth) IsRecursive ¶
type WordPrimitive ¶
type WordPrimitive struct { Go PrimitiveGo // The Go function to be executed. Ulp PrimitiveUlp // The ULP assembly to be compiled. UlpSrt PrimitiveUlpSrt // The ULP assembly using subroutine threading to be compiled. Entry *DictionaryEntry // The associated dictionary entry. }
A Word defined using Go and ULP assembly.
func (*WordPrimitive) AddToList ¶
func (w *WordPrimitive) AddToList(u *Ulp) error
func (*WordPrimitive) BuildAssembly ¶
func (w *WordPrimitive) BuildAssembly(u *Ulp) (string, error)
func (*WordPrimitive) Execute ¶
func (w *WordPrimitive) Execute(vm *VirtualMachine) error
func (*WordPrimitive) IsRecursive ¶
func (w *WordPrimitive) IsRecursive(check *WordForth) bool