minor simplifications, removal of unused code

This commit is contained in:
Helmut Merz 2023-07-23 16:51:03 +02:00
parent 8d8e13d8ed
commit 22e541f391
2 changed files with 11 additions and 33 deletions

View file

@ -20,8 +20,9 @@ func Get(f FE) *builtins {
} }
func setup(f FE) *builtins { func setup(f FE) *builtins {
voc := f.Voc()
r := func(name string, fct forge.Callable) XT { r := func(name string, fct forge.Callable) XT {
return forge.Register(f.Voc(), name, fct) return forge.Register(voc, name, fct)
} }
return &builtins{ return &builtins{
Add: r("+", func(f FE, _ XT) { f.Push(f.Pop().(int) + f.Pop().(int)) }), Add: r("+", func(f FE, _ XT) { f.Push(f.Pop().(int) + f.Pop().(int)) }),

View file

@ -2,9 +2,6 @@
package forge package forge
import ( import (
"io"
"os"
"git.sr.ht/~cco/go-scopes/common/ptr" "git.sr.ht/~cco/go-scopes/common/ptr"
"git.sr.ht/~cco/go-scopes/common/stack" "git.sr.ht/~cco/go-scopes/common/stack"
"git.sr.ht/~cco/go-scopes/common/voc" "git.sr.ht/~cco/go-scopes/common/voc"
@ -22,9 +19,6 @@ type forgeEnv struct {
ds, rs fstack ds, rs fstack
cp, ip, dp fptr cp, ip, dp fptr
voc *fvoc voc *fvoc
latestXT XT
cstate bool
output io.Writer
} }
type FE = *forgeEnv type FE = *forgeEnv
@ -43,7 +37,6 @@ func newFE(voc *fvoc) *forgeEnv {
rs: stack.NewStack[fitem](), rs: stack.NewStack[fitem](),
ip: ptr.NewSlice[fitem](), ip: ptr.NewSlice[fitem](),
voc: voc, voc: voc,
output: os.Stdout,
} }
} }
@ -55,7 +48,6 @@ var newPtr = ptr.NewSlice[fitem]
type xitem struct { type xitem struct {
name string name string
immediate bool
fct Callable fct Callable
body fptr body fptr
} }
@ -71,21 +63,6 @@ func Register(voc *fvoc, name string, fct Callable) *xitem {
return &it return &it
} }
func (it *xitem) IsImmediate() bool {
return it.immediate
}
func (it *xitem) Immediate() {
it.immediate = true
}
func (it *xitem) Body() fptr {
if it.body == nil {
it.body = newPtr()
}
return it.body
}
func (it *xitem) Name() string { func (it *xitem) Name() string {
return it.name return it.name
} }
@ -114,7 +91,7 @@ func (f *forgeEnv) Exec(items ...fitem) {
func (f *forgeEnv) Def(name string, items ...fitem) XT { func (f *forgeEnv) Def(name string, items ...fitem) XT {
xt := Register(f.voc, name, callDef) xt := Register(f.voc, name, callDef)
xt.Body().Append(f.Code(items...)) xt.body = newPtr(f.Code(items...)).Next()
return xt return xt
} }
@ -141,5 +118,5 @@ func (f *forgeEnv) Peek(d int) fitem {
// basic functions for executable items // basic functions for executable items
func callDef(f *forgeEnv, xt XT) { func callDef(f *forgeEnv, xt XT) {
f.Call(xt.Body().Value().(fptr)) f.Call(xt.body.Value().(fptr))
} }