Documentation
¶
Index ¶
- Variables
- func ConfigPath() string
- func IsFile(filename string) bool
- func ListFiles(dir, ext string) ([]string, error)
- 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, filename string) error
- func (fc *ForthCompiler) ParseFile(filename string) error
- func (fc *ForthCompiler) ParseTemplate(entry, str, filename string) error
- func (fc *ForthCompiler) ParseTemplateFile(entry, filename string) error
- func (fc *ForthCompiler) Preprocess() 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) Dec()
- 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) Str()
- func (fvm *ForthVM) StringToStack(str string)
- 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 MacroCompiler
- type MacroOptcode
- type MacroVM
- type Mc
- type Opcode
- type SliceStack
- type Stack
- func (s *Stack[T]) All() iter.Seq2[int, T]
- func (s *Stack[T]) Backward() iter.Seq2[int, T]
- func (s *Stack[T]) Contains(val T) bool
- func (s *Stack[T]) ContainsAny(values []T) bool
- func (s *Stack[T]) ExFetch() T
- func (s *Stack[T]) ExPop() T
- func (s *Stack[T]) Fetch() (T, bool)
- func (s *Stack[T]) Index(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]) Reset()
- func (s *Stack[T]) Reverse()
- func (s *Stack[T]) Values() iter.Seq[T]
- type StackIter
Constants ¶
This section is empty.
Variables ¶
var ( Magenta = color.HiMagentaString Cyan = color.HiCyanString Green = color.HiGreenString Blue = color.HiBlueString Yellow = color.HiYellowString Red = color.HiRedString Macro = color.BlueString )
var CAutoCompile = true
Compile automatically after C code generation
var CAutoExecute = true
Automatically execute the binary after compiling
var CBinaryName = "main"
The name of the binary
var CCodeName = "main.c"
The name of the C code file
var CCompiler = "cc"
The name of the C compiler
var COptimization = "-O2"
The optimization flag of the C compiler
var CVM []byte
The vm in C
var CellName = map[Opcode]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", DEC: "DEC", }
var Colored bool
Colored output
var MacroName = map[MacroOptcode]string{ M_L: "L", M_NUM_ARGS: "NUM_ARGS", M_DEPTH: "DEPTH", M_PUSH: "PUSH", M_GRI: "GRI", M_EQI: "EQI", M_NOT: "NOT", M_ADI: "ADI", M_LSI: "LSI", M_PRINT_STACK: "PRINT_STACK", M_JIN: "JIN", M_JMP: "JMP", M_NOP: "NOP", M_DUP: "DUP", M_DROP: "DROP", M_SWAP: "SWAP", M_PRS: "PRS", M_PRINT: "PRINT", M_STP: "STP", }
var Repl = Magenta("forth> ")
The prompt in StartREPL
var ShowByteCode bool
Show byte code in StartREPL
var ShowExecutionTime bool
Show execution time in vm.Run
Functions ¶
func ConfigPath ¶ added in v0.6.0
func ConfigPath() string
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, filename 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, filename string) error
func (*ForthCompiler) ParseTemplateFile ¶ added in v0.5.0
func (fc *ForthCompiler) ParseTemplateFile(entry, filename string) error
func (*ForthCompiler) Preprocess ¶ added in v0.6.0
func (fc *ForthCompiler) Preprocess() error
Preprocess the definitions of all words
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
ExitStatus int
// contains filtered or unexported fields
}
func NewForthVM ¶
func NewForthVM() *ForthVM
func (*ForthVM) PrepareRun ¶
Initializes the virtual machine. You should call the method before RunStep.
func (*ForthVM) RunStep ¶
Runs a single step of the virtual machine. Note: You must call PrepareRun once before calling RunStep for the first time
func (*ForthVM) StringToStack ¶ added in v0.6.0
Push str to the fvm stack
type Label ¶
type Label struct {
// contains filtered or unexported fields
}
func (*Label) CreateNewLabel ¶
func (*Label) CreateNewWord ¶
type MacroCompiler ¶ added in v0.6.0
type MacroCompiler struct {
// contains filtered or unexported fields
}
type MacroOptcode ¶ added in v0.6.0
type MacroOptcode int
const ( M_L MacroOptcode = iota M_STR M_NUM_ARGS M_DEPTH M_PUSH M_GRI M_LSI M_EQI M_NOT M_ADI M_PRINT_STACK M_JIN M_JMP M_NOP M_DUP M_DROP M_SWAP M_PRS M_PRINT M_STP )
type MacroVM ¶ added in v0.6.0
type MacroVM struct {
// contains filtered or unexported fields
}
func NewMacroVM ¶ added in v0.6.0
func NewMacroVM() *MacroVM
type Opcode ¶ added in v0.6.0
type Opcode int
const ( RDI Opcode = 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 DEC )
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]
