72 lines
972 B
Go
72 lines
972 B
Go
package forge
|
|
|
|
// XT (execution token)
|
|
|
|
type XT interface {
|
|
Name() string
|
|
Fct() Callable
|
|
Code() fptr
|
|
}
|
|
|
|
func Register(voc *fvoc, it XT) XT {
|
|
voc.Register(it.Name(), it)
|
|
return it
|
|
}
|
|
|
|
// gofunc: XT consisting only of a function written in Go
|
|
|
|
type gofunc struct {
|
|
fct Callable
|
|
name string
|
|
}
|
|
|
|
func GoFunc(n string, fct Callable) XT {
|
|
return &gofunc{fct, n}
|
|
}
|
|
|
|
func (it *gofunc) Fct() Callable {
|
|
return it.fct
|
|
}
|
|
|
|
func (it *gofunc) Code() fptr {
|
|
return nil
|
|
}
|
|
|
|
func (it *gofunc) Name() string {
|
|
return string(it.name)
|
|
}
|
|
|
|
// acode (anonymous code), fcode: forge code
|
|
|
|
type acode struct {
|
|
code fptr
|
|
}
|
|
|
|
func AnonCode(c fptr) XT {
|
|
return &acode{c}
|
|
}
|
|
|
|
func (it *acode) Fct() Callable {
|
|
return doFCode
|
|
}
|
|
|
|
func (it *acode) Code() fptr {
|
|
return it.code
|
|
}
|
|
|
|
func (it *acode) Name() string {
|
|
return ""
|
|
}
|
|
|
|
type fcode struct {
|
|
acode
|
|
name string
|
|
}
|
|
|
|
func FCode(n string, c fptr) XT {
|
|
return &fcode{acode{c}, n}
|
|
}
|
|
|
|
func (it *fcode) Name() string {
|
|
return string(it.name)
|
|
}
|