Documentation ¶
Index ¶
- Constants
- Variables
- func PrintError(err error)
- func PrintWarning(warning string)
- type Cell
- type Code
- type Compiler
- type ForthCompiler
- func (fc *ForthCompiler) ByteCode() string
- func (fc *ForthCompiler) Compile() error
- func (fc *ForthCompiler) CompileFile(str string) error
- func (fc *ForthCompiler) CompileScript(script string) error
- func (fc *ForthCompiler) CompileToC() error
- func (fc *ForthCompiler) Parse(str string) error
- func (fc *ForthCompiler) ParseFile(filename string) error
- func (fc *ForthCompiler) ParseTemplate(entry, str string) error
- func (fc *ForthCompiler) ParseTemplateFile(entry, filename string) error
- func (fc *ForthCompiler) ReadFile(filename string) ([]byte, error)
- func (fc *ForthCompiler) Run(prog string) error
- func (fc *ForthCompiler) RunFile(str string) error
- func (fc *ForthCompiler) StartREPL()
- type ForthVM
- func (fvm *ForthVM) Adf()
- func (fvm *ForthVM) Adi()
- func (fvm *ForthVM) And()
- func (fvm *ForthVM) Drp()
- func (fvm *ForthVM) Dup()
- func (fvm *ForthVM) Dvf()
- func (fvm *ForthVM) Dvi()
- func (fvm *ForthVM) Eqi()
- func (fvm *ForthVM) Fpop() float64
- func (fvm *ForthVM) Fpush(f float64)
- func (fvm *ForthVM) Fr()
- func (fvm *ForthVM) Gbl(name string)
- func (fvm *ForthVM) Gdef(name string)
- func (fvm *ForthVM) GetString() string
- func (fvm *ForthVM) Grf()
- func (fvm *ForthVM) Gri()
- func (fvm *ForthVM) Gset(name string)
- func (fvm *ForthVM) Inc()
- func (fvm *ForthVM) Jin() bool
- func (fvm *ForthVM) Lcl(name int)
- func (fvm *ForthVM) Lclr()
- func (fvm *ForthVM) Lctx()
- func (fvm *ForthVM) Ldef(name int)
- func (fvm *ForthVM) Lset(name int)
- func (fvm *ForthVM) Lsf()
- func (fvm *ForthVM) Lsi()
- func (fvm *ForthVM) Lv()
- func (fvm *ForthVM) Mlf()
- func (fvm *ForthVM) Mli()
- func (fvm *ForthVM) Not()
- func (fvm *ForthVM) Nrot()
- func (fvm *ForthVM) Or()
- func (fvm *ForthVM) Ovr()
- func (fvm *ForthVM) Pick()
- func (fvm *ForthVM) Pop() int64
- func (fvm *ForthVM) Pra()
- func (fvm *ForthVM) PrepareRun(codeStr string)
- func (fvm *ForthVM) Prf()
- func (fvm *ForthVM) Pri()
- func (fvm *ForthVM) Push(i int64)
- func (fvm *ForthVM) Qdp()
- func (fvm *ForthVM) Rdi()
- func (fvm *ForthVM) Rf()
- func (fvm *ForthVM) Rot()
- func (fvm *ForthVM) Rpop() int64
- func (fvm *ForthVM) Rpush(i int64)
- func (fvm *ForthVM) Run(codeStr string)
- func (fvm *ForthVM) RunStep() (bool, error)
- func (fvm *ForthVM) Sbf()
- func (fvm *ForthVM) Sbi()
- func (fvm *ForthVM) SetString(str string)
- func (fvm *ForthVM) Str()
- func (fvm *ForthVM) Swp()
- func (fvm *ForthVM) Sys()
- func (fvm *ForthVM) Tdp()
- func (fvm *ForthVM) Tfr()
- func (fvm *ForthVM) Tr()
- func (fvm *ForthVM) Trf()
- func (fvm *ForthVM) Ttr()
- func (fvm *ForthVM) Tvr()
- func (fvm *ForthVM) Twp()
- func (fvm *ForthVM) Xor()
- type Label
- type Local
- type SliceStack
- type Stack
- func (s *Stack[T]) Contains(val T) bool
- func (s *Stack[T]) Each(f func(value T))
- func (s *Stack[T]) ExFetch() T
- func (s *Stack[T]) ExPop() T
- func (s *Stack[T]) Fetch() (T, bool)
- func (s *Stack[T]) GetIndex(val T) int
- func (s *Stack[T]) IsEmpty() bool
- func (s *Stack[T]) Iter() *StackIter[T]
- func (s *Stack[T]) Len() int
- func (s *Stack[T]) Pop() (T, bool)
- func (s *Stack[T]) Push(val T)
- func (s *Stack[T]) Reverse() *Stack[T]
- type StackIter
Constants ¶
View Source
const ( RDI = iota PRI PRA DUP OVR TVR TWP QDP ROT TDP DRP SWP NOP JMP JIN ADI SBI DVI LSI GRI MLI ADF SBF MLF DVF PRF LSF GRF OR AND NOT EQI XOR LV L LF STR SYS STP SUB END MAIN GDEF GSET GBL LCTX LDEF LSET LCL LCLR CALL REF EXC PCK NRT TR // to r FR // from r RF // r fetch TTR // 2 to r TFR // 2 from r TRF // 2 r fetch INC )
Variables ¶
View Source
var ( Magenta = color.New(color.FgHiMagenta).SprintFunc() Cyan = color.New(color.FgHiCyan).SprintFunc() Green = color.New(color.FgHiGreen).SprintFunc() Blue = color.New(color.FgHiBlue).SprintFunc() Yellow = color.New(color.FgHiYellow).SprintFunc() Red = color.New(color.FgHiRed).SprintFunc() )
View Source
var CAutoCompile = true
Compile automatically after C code generation
View Source
var CAutoExecute = true
Automatically execute the binary after compiling
View Source
var CBinaryName = "main"
The name of the binary
View Source
var CCodeName = "main.c"
The name of the C code file
View Source
var CCompiler = "cc"
The name of the C compiler
View Source
var COptimization = "-O2"
The optimization flag of the C compiler
View Source
var CellName = map[int]string{ RDI: "RDI", PRI: "PRI", PRA: "PRA", DUP: "DUP", OVR: "OVR", TVR: "TVR", TWP: "TWP", QDP: "QDP", ROT: "ROT", TDP: "TDP", DRP: "DRP", SWP: "SWP", NOP: "NOP", JMP: "JMP", JIN: "JIN", ADI: "ADI", SBI: "SBI", DVI: "DVI", LSI: "LSI", GRI: "GRI", MLI: "MLI", ADF: "ADF", SBF: "SBF", MLF: "MLF", DVF: "DVF", PRF: "PRF", LSF: "LSF", GRF: "GRF", OR: "OR", AND: "AND", NOT: "NOT", EQI: "EQI", XOR: "XOR", LV: "LV", L: "L", LF: "LF", STR: "STR", SYS: "SYS", STP: "STP", SUB: "SUB", END: "END", MAIN: "MAIN", GDEF: "GDEF", GSET: "GSET", GBL: "GBL", LCTX: "LCTX", LDEF: "LDEF", LSET: "LSET", LCL: "LCL", LCLR: "LCLR", CALL: "CALL", REF: "REF", EXC: "EXC", PCK: "PCK", NRT: "NRT", TR: "TR", FR: "FR", RF: "RF", TTR: "TTR", TFR: "TFR", TRF: "TRF", INC: "INC", }
View Source
var Colored bool
Colored output
View Source
var Core string
The core words dictionary
View Source
var Repl = "forth> "
The prompt in StartREPL
View Source
var ShowByteCode bool
Show byte code in StartREPL
View Source
var ShowExecutionTime bool
Show execution time in vm.Run
Functions ¶
func PrintError ¶
func PrintError(err error)
func PrintWarning ¶ added in v0.5.0
func PrintWarning(warning string)
Types ¶
type Compiler ¶
type Compiler interface { Compile() error Parse(s string) error ParseFile(filename string) error StartREPL() RunFile(filename string) error Run(prog string) error }
This is the public API for ForthCompiler.
type ForthCompiler ¶
type ForthCompiler struct { Fvm *ForthVM // contains filtered or unexported fields }
func NewForthCompiler ¶
func NewForthCompiler() *ForthCompiler
func (*ForthCompiler) ByteCode ¶
func (fc *ForthCompiler) ByteCode() string
The ByteCode of the "main" word previously compiled with Compile().
func (*ForthCompiler) Compile ¶
func (fc *ForthCompiler) Compile() error
Compiles the word "main". Side effect: ByteCode() contains the result.
func (*ForthCompiler) CompileFile ¶ added in v0.2.0
func (fc *ForthCompiler) CompileFile(str string) error
func (*ForthCompiler) CompileScript ¶ added in v0.2.0
func (fc *ForthCompiler) CompileScript(script string) error
func (*ForthCompiler) CompileToC ¶ added in v0.2.0
func (fc *ForthCompiler) CompileToC() error
func (*ForthCompiler) Parse ¶
func (fc *ForthCompiler) Parse(str string) error
Parses the given Forth code and adds the word to the dictionary of the compiler.
func (*ForthCompiler) ParseFile ¶
func (fc *ForthCompiler) ParseFile(filename string) error
func (*ForthCompiler) ParseTemplate ¶ added in v0.5.0
func (fc *ForthCompiler) ParseTemplate(entry, str string) error
func (*ForthCompiler) ParseTemplateFile ¶ added in v0.5.0
func (fc *ForthCompiler) ParseTemplateFile(entry, filename string) error
func (*ForthCompiler) ReadFile ¶ added in v0.5.0
func (fc *ForthCompiler) ReadFile(filename string) ([]byte, error)
func (*ForthCompiler) Run ¶
func (fc *ForthCompiler) Run(prog string) error
func (*ForthCompiler) RunFile ¶
func (fc *ForthCompiler) RunFile(str string) error
func (*ForthCompiler) StartREPL ¶
func (fc *ForthCompiler) StartREPL()
type ForthVM ¶
type ForthVM struct { Vars map[string]int64 Mem []int64 Stack []int64 Rstack []int64 Sysfunc func(*ForthVM, int64) Out io.Writer CodeData *Code // contains filtered or unexported fields }
func NewForthVM ¶
func NewForthVM() *ForthVM
func (*ForthVM) PrepareRun ¶
Initializes the virtual machine. You should call the method before RunStep.
type Label ¶
type Label struct {
// contains filtered or unexported fields
}
func (*Label) CreateNewLabel ¶
func (*Label) CreateNewWord ¶
type SliceStack ¶
type SliceStack[T comparable] []*Stack[T]
func (*SliceStack[T]) Contains ¶
func (ss *SliceStack[T]) Contains(val T) bool
func (*SliceStack[T]) ExPop ¶
func (ss *SliceStack[T]) ExPop() *Stack[T]
func (*SliceStack[T]) IsEmpty ¶
func (ss *SliceStack[T]) IsEmpty() bool
func (*SliceStack[T]) Len ¶
func (ss *SliceStack[T]) Len() int
func (*SliceStack[T]) Pop ¶
func (ss *SliceStack[T]) Pop() (*Stack[T], bool)
func (*SliceStack[T]) Push ¶
func (ss *SliceStack[T]) Push(stk *Stack[T])
type Stack ¶
type Stack[T comparable] struct { // contains filtered or unexported fields }
func NewStack ¶
func NewStack[T comparable]() *Stack[T]
Click to show internal directories.
Click to hide internal directories.