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 XT = forge.XT
|
||||||
|
|
||||||
type builtins struct {
|
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 {
|
func Get(f FE) *builtins {
|
||||||
|
@ -26,6 +26,9 @@ func setup(f FE) *builtins {
|
||||||
}
|
}
|
||||||
b := builtins{
|
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)) }),
|
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()) }),
|
Get: r("@", func(f FE, _ XT) { f.Push(f.Pop().(forge.FPtr).Value()) }),
|
||||||
Lit: r("lit", func(f FE, _ XT) { f.Push(f.Literal()) }),
|
Lit: r("lit", func(f FE, _ XT) { f.Push(f.Literal()) }),
|
||||||
|
|
|
@ -19,7 +19,7 @@ type Callable func(*forgeEnv, XT)
|
||||||
|
|
||||||
type forgeEnv struct {
|
type forgeEnv struct {
|
||||||
ds, rs fstack
|
ds, rs fstack
|
||||||
cp, ip, dp fptr
|
ip fptr
|
||||||
voc *fvoc
|
voc *fvoc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,4 +32,6 @@ func CoreTest(t *testing.T) {
|
||||||
fe.Exec(5, myvar, b.Put)
|
fe.Exec(5, myvar, b.Put)
|
||||||
fe.Exec(seven, myvar, b.Get, b.Mult)
|
fe.Exec(seven, myvar, b.Get, b.Mult)
|
||||||
t.AssertEqual(fe.Pop(), 35)
|
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