type renamings: as private as possible
This commit is contained in:
parent
91322dae3a
commit
96a1bdb39f
2 changed files with 38 additions and 47 deletions
|
@ -2,11 +2,11 @@ package builtins
|
||||||
|
|
||||||
import "git.sr.ht/~cco/go-scopes/forge"
|
import "git.sr.ht/~cco/go-scopes/forge"
|
||||||
|
|
||||||
type FE = *forge.ForgeEnv
|
type FE = forge.FE
|
||||||
type XT = *forge.Item
|
type XT = forge.XT
|
||||||
|
|
||||||
type builtins struct {
|
type builtins struct {
|
||||||
Add, Lit forge.XT
|
Add, Lit XT
|
||||||
}
|
}
|
||||||
|
|
||||||
func Setup(f FE) *builtins {
|
func Setup(f FE) *builtins {
|
||||||
|
|
|
@ -10,49 +10,51 @@ import (
|
||||||
"git.sr.ht/~cco/go-scopes/common/voc"
|
"git.sr.ht/~cco/go-scopes/common/voc"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DataItem interface{}
|
type fitem interface{}
|
||||||
|
|
||||||
type Ptr = ptr.Ptr[DataItem]
|
type fptr = ptr.Ptr[fitem]
|
||||||
type Stack = stack.Stack[DataItem]
|
type fstack = stack.Stack[fitem]
|
||||||
type Voc = voc.Vocabulary[XT]
|
type fvoc = voc.Vocabulary[XT]
|
||||||
|
|
||||||
type Callable func(*ForgeEnv, XT)
|
type Callable func(*forgeEnv, XT)
|
||||||
|
|
||||||
type Item struct {
|
type xitem struct {
|
||||||
name string
|
name string
|
||||||
immediate bool
|
immediate bool
|
||||||
fct Callable
|
fct Callable
|
||||||
body Ptr
|
body fptr
|
||||||
}
|
}
|
||||||
|
|
||||||
type XT = *Item
|
type XT = *xitem
|
||||||
|
|
||||||
type ForgeEnv struct {
|
type forgeEnv struct {
|
||||||
ds, rs Stack
|
ds, rs fstack
|
||||||
cp, ip, dp Ptr
|
cp, ip, dp fptr
|
||||||
voc *Voc
|
voc *fvoc
|
||||||
latestXT XT
|
latestXT XT
|
||||||
cstate bool
|
cstate bool
|
||||||
output io.Writer
|
output io.Writer
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewVoc(parent *Voc) *Voc {
|
type FE = *forgeEnv
|
||||||
|
|
||||||
|
func NewVoc(parent *fvoc) *fvoc {
|
||||||
return voc.NewVoc[XT](parent)
|
return voc.NewVoc[XT](parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFE() *ForgeEnv {
|
func NewFE() *forgeEnv {
|
||||||
return newFE(NewVoc(nil))
|
return newFE(NewVoc(nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *ForgeEnv) ChildFE() *ForgeEnv {
|
func (f *forgeEnv) ChildFE() *forgeEnv {
|
||||||
return newFE(NewVoc(f.voc))
|
return newFE(NewVoc(f.voc))
|
||||||
}
|
}
|
||||||
|
|
||||||
func newFE(voc *Voc) *ForgeEnv {
|
func newFE(voc *fvoc) *forgeEnv {
|
||||||
return &ForgeEnv{
|
return &forgeEnv{
|
||||||
ds: stack.NewStack[DataItem](),
|
ds: stack.NewStack[fitem](),
|
||||||
rs: stack.NewStack[DataItem](),
|
rs: stack.NewStack[fitem](),
|
||||||
ip: ptr.NewSlice[DataItem](),
|
ip: ptr.NewSlice[fitem](),
|
||||||
voc: voc,
|
voc: voc,
|
||||||
output: os.Stdout,
|
output: os.Stdout,
|
||||||
}
|
}
|
||||||
|
@ -60,8 +62,8 @@ func newFE(voc *Voc) *ForgeEnv {
|
||||||
|
|
||||||
// basic functions and methods
|
// basic functions and methods
|
||||||
|
|
||||||
func Register(voc *Voc, name string, fct Callable) *Item {
|
func Register(voc *fvoc, name string, fct Callable) *xitem {
|
||||||
it := Item{
|
it := xitem{
|
||||||
name: name,
|
name: name,
|
||||||
fct: fct,
|
fct: fct,
|
||||||
}
|
}
|
||||||
|
@ -69,58 +71,47 @@ func Register(voc *Voc, name string, fct Callable) *Item {
|
||||||
return &it
|
return &it
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Item) IsImmediate() bool {
|
func (it *xitem) IsImmediate() bool {
|
||||||
return it.immediate
|
return it.immediate
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Item) Immediate() {
|
func (it *xitem) Immediate() {
|
||||||
it.immediate = true
|
it.immediate = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Item) Body() Ptr {
|
func (it *xitem) Body() fptr {
|
||||||
if it.body == nil {
|
if it.body == nil {
|
||||||
it.body = ptr.NewSlice[DataItem]()
|
it.body = ptr.NewSlice[fitem]()
|
||||||
}
|
}
|
||||||
return it.body
|
return it.body
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Item) Name() string {
|
func (it *xitem) Name() string {
|
||||||
return it.name
|
return it.name
|
||||||
}
|
}
|
||||||
|
|
||||||
// ForgeEnv methods
|
// ForgeEnv methods
|
||||||
|
|
||||||
func (f *ForgeEnv) Voc() *Voc {
|
func (f *forgeEnv) Voc() *fvoc {
|
||||||
return f.voc
|
return f.voc
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *ForgeEnv) IP() Ptr {
|
func (f *forgeEnv) IP() fptr {
|
||||||
return f.ip
|
return f.ip
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *ForgeEnv) Exec(items ...DataItem) {
|
func (f *forgeEnv) Exec(items ...fitem) {
|
||||||
f.ip = ptr.NewSlice[DataItem](items...)
|
f.ip = ptr.NewSlice[fitem](items...)
|
||||||
for f.ip.Next() != nil {
|
for f.ip.Next() != nil {
|
||||||
it := f.ip.Value().(XT)
|
it := f.ip.Value().(XT)
|
||||||
it.fct(f, it)
|
it.fct(f, it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *ForgeEnv) Push(it DataItem) {
|
func (f *forgeEnv) Push(it fitem) {
|
||||||
f.ds.Push(it)
|
f.ds.Push(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *ForgeEnv) Pop() DataItem {
|
func (f *forgeEnv) Pop() fitem {
|
||||||
return f.ds.Pop()
|
return f.ds.Pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
// dummy stuff for testing
|
|
||||||
|
|
||||||
var builtins = struct{ add, sub XT }{}
|
|
||||||
|
|
||||||
var work = struct{ square XT }{}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
builtins.add = &Item{}
|
|
||||||
builtins.sub = &Item{}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue