provide 'Body' built-in for access to XT's code/data

This commit is contained in:
Helmut Merz 2023-07-30 16:12:55 +02:00
parent 025ac92c6f
commit 3866991b75
3 changed files with 10 additions and 5 deletions

View file

@ -6,7 +6,7 @@ type FE = forge.FE
type XT = forge.XT
type builtins struct {
Add, Dup, Get, Lit, Mult, Put, Reg XT
Add, Body, Dup, Get, Lit, Mult, Put, Reg XT
}
func Get(f FE) *builtins {
@ -26,6 +26,9 @@ func setup(f FE) *builtins {
}
b := builtins{
Add: r("+", func(f FE, _ XT) { f.Push(f.Pop().(int) + f.Pop().(int)) }),
Body: r("body", func(f FE, _ XT) {
f.Push(f.Pop().(forge.XT).Code().New().Next())
}),
Dup: r("dup", func(f FE, _ XT) { f.Push(f.Peek(0)) }),
Get: r("@", func(f FE, _ XT) { f.Push(f.Pop().(forge.FPtr).Value()) }),
Lit: r("lit", func(f FE, _ XT) { f.Push(f.Literal()) }),

View file

@ -19,7 +19,7 @@ type Callable func(*forgeEnv, XT)
type forgeEnv struct {
ds, rs fstack
cp, ip, dp fptr
ip fptr
voc *fvoc
}

View file

@ -32,4 +32,6 @@ func CoreTest(t *testing.T) {
fe.Exec(5, myvar, b.Put)
fe.Exec(seven, myvar, b.Get, b.Mult)
t.AssertEqual(fe.Pop(), 35)
fe.Exec(9, b.Lit, seven, b.Body, b.Put)
t.AssertEqual(fe.Exec(seven).Pop(), 9)
}