mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-12 17:27:50 +08:00
a3f4384495
The elvdocs still use the old format (#elvdoc:fn or #elvdoc:var) for now, but will be changed to "fn" and "var" forms soon. Also remove the accidentally committed cmd/mvelvdoc. It has been used to perform the conversion automatically but is not supposed to be committed.
40 lines
595 B
Go
40 lines
595 B
Go
package eval
|
|
|
|
import (
|
|
"runtime"
|
|
|
|
"src.elv.sh/pkg/logutil"
|
|
"src.elv.sh/pkg/parse"
|
|
)
|
|
|
|
func init() {
|
|
addBuiltinFns(map[string]any{
|
|
"src": src,
|
|
"-gc": _gc,
|
|
"-stack": _stack,
|
|
"-log": _log,
|
|
})
|
|
}
|
|
|
|
func src(fm *Frame) parse.Source {
|
|
return fm.srcMeta
|
|
}
|
|
|
|
func _gc() {
|
|
runtime.GC()
|
|
}
|
|
|
|
func _stack(fm *Frame) error {
|
|
// TODO(xiaq): Dup with main.go.
|
|
buf := make([]byte, 1024)
|
|
for runtime.Stack(buf, true) == cap(buf) {
|
|
buf = make([]byte, cap(buf)*2)
|
|
}
|
|
_, err := fm.ByteOutput().Write(buf)
|
|
return err
|
|
}
|
|
|
|
func _log(fname string) error {
|
|
return logutil.SetOutputFile(fname)
|
|
}
|