provide 'Body' built-in for access to XT's code/data
This commit is contained in:
parent
025ac92c6f
commit
3866991b75
3 changed files with 10 additions and 5 deletions
|
@ -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 {
|
||||
|
@ -25,7 +25,10 @@ func setup(f FE) *builtins {
|
|||
return forge.Register(voc, forge.GoFunc(name, fct))
|
||||
}
|
||||
b := 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)) }),
|
||||
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()) }),
|
||||
|
|
|
@ -18,9 +18,9 @@ type fvoc = voc.Vocabulary[fitem]
|
|||
type Callable func(*forgeEnv, XT)
|
||||
|
||||
type forgeEnv struct {
|
||||
ds, rs fstack
|
||||
cp, ip, dp fptr
|
||||
voc *fvoc
|
||||
ds, rs fstack
|
||||
ip fptr
|
||||
voc *fvoc
|
||||
}
|
||||
|
||||
type FE = *forgeEnv
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue