vm.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. // vm, the virtual low level machine that runs MUESLI.
  2. package muesli
  3. import (
  4. "fmt"
  5. "strings"
  6. "io"
  7. )
  8. // Handler function
  9. type Handler func(vm *VM, arguments ...Value) []Value
  10. func (handler *Handler) Call(vm *VM, arguments ...Value) []Value {
  11. return (*handler)(vm, arguments...)
  12. }
  13. // A callable Value must implement the Callable interface
  14. type Callable interface {
  15. // Callable can be called
  16. Call(vm *VM, arguments ...Value) []Value
  17. // Position is the source code position where it was defined. Needed for tracebacks.
  18. Position() *Position
  19. // Signature are the types of the parameters of this function.
  20. Signature() Signature
  21. }
  22. // A helper Value has a help text available.
  23. // This help text can be set as well.
  24. type Helper interface {
  25. HelperName() string
  26. Help() string
  27. SetHelp(string) string
  28. }
  29. // BasicCallable is an embeddable struct that makes it easier to
  30. // implement the Caller and Helper interface.
  31. type BasicCallable struct {
  32. // Name of the callable
  33. Name string
  34. // Help string for the callable.
  35. HelpText string
  36. // Signature of the callable for type checking.
  37. signature Signature
  38. // Position where the callable is defined.
  39. position Position
  40. }
  41. func (val BasicCallable) Signature() Signature {
  42. return val.signature
  43. }
  44. // Implement Helper interface
  45. func (val BasicCallable) Help() string {
  46. return val.HelpText
  47. }
  48. // Implement Helper interface
  49. func (val * BasicCallable) SetHelp(help string) string {
  50. val.HelpText = help
  51. return val.HelpText
  52. }
  53. // Implement Helper interface
  54. func (val BasicCallable) HelperName() string {
  55. return val.Name
  56. }
  57. // AppendHelp appends help to an existing helper.
  58. func AppendHelp(helper Helper, extra string) string {
  59. return helper.SetHelp( helper.Help() + extra)
  60. }
  61. // ClearHelp rresets the help text to an empty string.
  62. func ClearHelp(helper Helper, extra string) string {
  63. return helper.SetHelp("")
  64. }
  65. func (bc * BasicCallable) Takes(arguments ...TypeValue) *BasicCallable {
  66. bc.signature.SetParameters(arguments...)
  67. return bc
  68. }
  69. func (bc * BasicCallable) Returns(arguments ...TypeValue) *BasicCallable {
  70. bc.signature.SetReturns(arguments...)
  71. return bc
  72. }
  73. func (val BasicCallable) String() string {
  74. return val.Name
  75. }
  76. func (val BasicCallable) Type() TypeValue {
  77. return TypeValue("Callable")
  78. }
  79. func (from BasicCallable) Convert(to interface{}) error {
  80. return NewErrorValuef("Cannot convert the callable value %v to %v: Not implemented.", from, to)
  81. }
  82. func (val *BasicCallable) Call(vm *VM, arguments ...Value) []Value {
  83. panic("Not implemented")
  84. }
  85. // A struct to store a built in function
  86. type BuiltinValue struct {
  87. BasicCallable
  88. Handler
  89. }
  90. func NewBasicCallable(name string) BasicCallable {
  91. return BasicCallable{name, "", NoSignature(), Position{name, 1, 1}}
  92. }
  93. func NewBuiltinValue(name string, handler Handler) *BuiltinValue {
  94. result := &BuiltinValue{}
  95. result.Name = name
  96. result.Handler = handler
  97. return result
  98. }
  99. // A block in a script.
  100. type BlockValue struct {
  101. BasicCallable
  102. Ast *Ast
  103. }
  104. func NewBlockValue(definition *Ast) *BlockValue {
  105. result := &BlockValue{}
  106. result.Name = fmt.Sprintf("<block:%s>", definition.String())
  107. result.Ast = definition
  108. return result
  109. }
  110. func (block * BlockValue) Position() *Position {
  111. if block == nil {
  112. return nil
  113. }
  114. if block.Ast == nil {
  115. return nil
  116. }
  117. pos := block.Ast.Token().Position
  118. return &pos
  119. }
  120. func (defined * DefinedValue) Position() *Position {
  121. if defined == nil {
  122. return nil
  123. }
  124. if defined.Body == nil {
  125. return nil
  126. }
  127. return defined.Body.Position()
  128. }
  129. func (cv BasicCallable) Position() *Position {
  130. return &cv.position
  131. }
  132. // A script defined function
  133. type DefinedValue struct {
  134. BasicCallable
  135. Body *BlockValue
  136. }
  137. func NewDefinedValue(name string, signature Signature, body *BlockValue) *DefinedValue {
  138. result := &DefinedValue{}
  139. result.Name = name
  140. result.Body = body
  141. result.signature = signature
  142. return result
  143. }
  144. func (defined *DefinedValue) Call(vm *VM, arguments ...Value) []Value {
  145. vm.Trace("Call defined value: %v %v %v", defined, defined.signature, arguments)
  146. for i , arg := range arguments {
  147. if i >= len(defined.signature.Parameters) {
  148. break
  149. }
  150. param := defined.signature.Parameters[i]
  151. expectedType := param.Type
  152. vm.Trace("Signature check: %d %v", i, param)
  153. if !expectedType.IsMatch(arg.Type()) {
  154. return Fail(NewErrorValuef("Argument %d type mismatch: %s<->%s", i, expectedType, arg.Type()))
  155. }
  156. vm.Register(param.Name.String(), arg)
  157. vm.Trace("DefinedValue.Call: vm.Register: %v %v", param.Name.String(), arg)
  158. }
  159. res := defined.Body.Call(vm, arguments...)
  160. return res
  161. }
  162. func (defined *DefinedValue) Help() string {
  163. help := defined.BasicCallable.Help()
  164. extra := "["
  165. for _, parameter := range defined.signature.Parameters {
  166. extra = fmt.Sprintf("%s %s %s", extra, parameter.Name, parameter.Type)
  167. }
  168. extra = extra + "]:"
  169. return extra + help
  170. }
  171. // Assert that DefinedValue is callable.
  172. var _ Callable = &DefinedValue{}
  173. const (
  174. CoverTypeValue = TypeValue("Cover")
  175. BuiltinTypeValue = TypeValue("Builtin")
  176. DefinedTypeValue = TypeValue("Defined")
  177. BlockTypeValue = TypeValue("Block")
  178. )
  179. func (v CoverValue) Type() TypeValue { return CoverTypeValue }
  180. func (v BuiltinValue) Type() TypeValue { return BuiltinTypeValue }
  181. func (v DefinedValue) Type() TypeValue { return DefinedTypeValue }
  182. func (v BlockValue) Type() TypeValue { return BlockTypeValue }
  183. func (from CoverValue) Convert(to interface{}) error {
  184. return NewErrorValuef("Cannot convert the cover value %v to %v", from, to)
  185. }
  186. func (from BuiltinValue) Convert(to interface{}) error {
  187. return NewErrorValuef("Cannot convert the builtin value %v to %v", from, to)
  188. }
  189. func (from DefinedValue) Convert(to interface{}) error {
  190. return NewErrorValuef("Cannot convert the defined value %v to %v", from, to)
  191. }
  192. func (from BlockValue) Convert(to interface{}) error {
  193. if toValue, isOk := to.(*BlockValue) ; isOk {
  194. (*toValue) = from
  195. return nil
  196. }
  197. return NewErrorValuef("Cannot convert the block value %v to %v", from, to)
  198. }
  199. func (cv * CoverValue) AddOverloadWithSignature(name string, callable Callable, signature Signature) Overload {
  200. ov := Overload { Name: name, Callable: callable }
  201. cv.Overloads[signature] = ov
  202. return ov
  203. }
  204. func (cv * CoverValue) AddOverloadCallable(name string, callable Callable) Overload {
  205. return cv.AddOverloadWithSignature(name, callable, callable.Signature())
  206. }
  207. func (cv * CoverValue) AddOverload(name string, callable Callable, tv ... TypeValue) error {
  208. signature := Signature{}
  209. length := len(tv)
  210. if length > len(signature.Parameters) {
  211. length = len(signature.Parameters)
  212. }
  213. for i := 0; i < length; i++ {
  214. signature.Parameters[i].Type = tv[i]
  215. }
  216. cv.AddOverloadWithSignature(name, callable, signature)
  217. return nil
  218. }
  219. func (vm * VM) AddOverloadCallable(from, target string, level int, callable Callable) error {
  220. var cover *CoverValue
  221. var ok bool
  222. lookup := vm.Lookup(from)
  223. if lookup == nil {
  224. cover = vm.RegisterCover(from, level)
  225. } else if cover, ok = lookup.(*CoverValue) ; !ok {
  226. return fmt.Errorf("%s exists and is not a cover value", from)
  227. }
  228. cover.AddOverloadCallable(target, callable)
  229. return nil
  230. }
  231. func (vm *VM) LookupCallable(target string) (Callable, error) {
  232. var callable Callable
  233. var ok bool
  234. lookup := vm.Lookup(target)
  235. if lookup == nil {
  236. return nil, fmt.Errorf("%s is not defined", target)
  237. }
  238. if callable, ok = lookup.(Callable) ; !ok {
  239. return nil, fmt.Errorf("%s is not a callable value", target)
  240. }
  241. return callable, nil
  242. }
  243. // AddOverloadByName overloads the from command to call the target command
  244. // if the argument list matches the signature based on the given type values
  245. func (vm * VM) AddOverload(from, target string, level int, tv... TypeValue) error {
  246. var cover *CoverValue
  247. var callable Callable
  248. var ok bool
  249. var err error
  250. lookup := vm.Lookup(from)
  251. if lookup == nil {
  252. cover = vm.RegisterCover(from, level)
  253. } else if cover, ok = lookup.(*CoverValue) ; !ok {
  254. return fmt.Errorf("%s exists and is not a cover value", from)
  255. }
  256. callable, err = vm.LookupCallable(target)
  257. if err != nil {
  258. return err
  259. }
  260. return cover.AddOverload(target, callable, tv...)
  261. }
  262. // AddOverloadByName overloads the from command to call the target command
  263. // if the argment lists matches the signature of the target command.
  264. func (vm * VM) AddOverloadByName(from, target string, level int) error {
  265. callable, err := vm.LookupCallable(target)
  266. if err != nil {
  267. return err
  268. }
  269. return vm.AddOverloadCallable(from, target, level, callable)
  270. }
  271. type OverloadDescription struct {
  272. Target string
  273. Types []TypeValue
  274. Level int
  275. }
  276. func (vm * VM) AddOverloads(from string, descriptions ... OverloadDescription) error {
  277. for _, od := range descriptions {
  278. err := vm.AddOverload(from, od.Target, od.Level, od.Types...)
  279. if err != nil {
  280. panic(fmt.Errorf("internal error: could not register overloads: %s", err))
  281. }
  282. }
  283. return nil
  284. }
  285. func Over(target string, level int, types ... TypeValue) OverloadDescription {
  286. return OverloadDescription { Target: target, Level: level, Types: types}
  287. }
  288. func (vm * VM) SetHelp(target, help string) error {
  289. var helper Helper
  290. var ok bool
  291. lookup := vm.Lookup(target)
  292. if lookup == nil {
  293. return fmt.Errorf("%s not found", target)
  294. } else if helper, ok = lookup.(Helper) ; !ok {
  295. return fmt.Errorf("%s exists but cannot set help text.", target)
  296. }
  297. helper.SetHelp(help)
  298. return nil
  299. }
  300. // Scope of symbols defined in the VM, hierarchical
  301. type Scope struct {
  302. parent *Scope
  303. children []*Scope
  304. symbols map[string]Value
  305. }
  306. func NewScope(parent *Scope) *Scope {
  307. return &Scope{parent, make([]*Scope, 0), make(map[string]Value)}
  308. }
  309. func (scope *Scope) Lookup(name string) Value {
  310. value, ok := scope.symbols[name]
  311. if ok {
  312. return value
  313. }
  314. if scope.parent != nil {
  315. return scope.parent.Lookup(name)
  316. }
  317. return NilValue
  318. }
  319. func (scope *Scope) Register(name string, value Value) Value {
  320. scope.symbols[name] = value
  321. return value
  322. }
  323. func (scope * Scope) Known(filter func(string, Value) bool) map[string]Value {
  324. res := make(map[string]Value)
  325. if scope.parent != nil {
  326. res = scope.parent.Known(filter)
  327. }
  328. for k, v := range scope.symbols {
  329. if (filter == nil) || filter(k, v) {
  330. res[k] = v
  331. }
  332. }
  333. return res
  334. }
  335. func (scope * Scope) ForEachDefined(do func(string, Value) (bool, error)) (bool, error) {
  336. var res bool = true
  337. var err error
  338. if (do == nil) {
  339. return false, fmt.Errorf("do may not be nil")
  340. }
  341. if scope.parent != nil {
  342. res, err = scope.parent.ForEachDefined(do)
  343. }
  344. if res == false || err != nil {
  345. return res, err
  346. }
  347. for k, v := range scope.symbols {
  348. res, err = do(k, v)
  349. if res == false || err != nil {
  350. return res, err
  351. }
  352. }
  353. return res, err
  354. }
  355. func (scope* Scope) DefinedHelpers() []Helper {
  356. res := []Helper{}
  357. scope.ForEachDefined(func (k string, v Value) (bool, error) {
  358. helper, hok := v.(Helper)
  359. if hok {
  360. res = append(res, helper)
  361. }
  362. return true, nil
  363. })
  364. return res
  365. }
  366. // Frame of execution of a function
  367. type Frame struct {
  368. parent *Frame
  369. arguments []Value
  370. results []Value
  371. failed bool
  372. returned bool
  373. position *Position
  374. }
  375. func NewFrame(parent *Frame, position *Position) *Frame {
  376. return &Frame{parent, EmptyValueArray(), EmptyValueArray(), false, false, position}
  377. }
  378. type Tracer interface {
  379. Trace(vm VM, fmt string, args ... interface{}) bool
  380. }
  381. // Virtual machine
  382. type VM struct {
  383. TopScope *Scope // Top level scope
  384. TopFrame *Frame // Top level scope
  385. *Scope // Current Scope
  386. *Frame // Current frame
  387. Tracer // Tracer to emit tracing info to, could be used for logging or debugging
  388. Output io.Writer // Writer to which command output should be written.
  389. Input io.Reader // Reader from which command input should be read.
  390. ExitStatus int
  391. }
  392. func NewVM() *VM {
  393. vm := &VM{NewScope(nil), NewFrame(nil, nil), nil, nil, nil, nil, nil, 0}
  394. vm.Scope = vm.TopScope
  395. vm.Frame = vm.TopFrame
  396. return vm
  397. }
  398. func (vm *VM) Trace(fm string, args ... interface{}) {
  399. if vm.Tracer != nil {
  400. vm.Tracer.Trace(*vm, fm, args...)
  401. }
  402. }
  403. func (vm *VM) PushNewFrame(position *Position) *Frame {
  404. frame := NewFrame(vm.Frame, position)
  405. vm.Trace("PushFrame %v->%v\n", vm.Frame, frame)
  406. vm.Frame = frame
  407. return frame
  408. }
  409. func (vm *VM) PushNewScope() *Scope {
  410. scope := NewScope(vm.Scope)
  411. vm.Scope = scope
  412. return scope
  413. }
  414. func (vm *VM) Return(results ...Value) []Value {
  415. return results
  416. }
  417. func (vm *VM) PopFrame() *Frame {
  418. oldFrame := vm.Frame
  419. vm.Trace("PopFrame %v->%v\n", vm.Frame, vm.Frame.parent)
  420. if (vm.Frame != vm.TopFrame) && (vm.Frame.parent != nil) {
  421. frame := vm.Frame
  422. vm.Frame = frame.parent
  423. // Copy frame results up.
  424. vm.Frame.returned = oldFrame.returned
  425. vm.Frame.failed = oldFrame.failed
  426. vm.Frame.results = oldFrame.results
  427. return frame
  428. }
  429. return nil
  430. }
  431. func (vm *VM) PopScope() *Scope {
  432. if (vm.Scope != vm.TopScope) && (vm.Scope.parent != nil) {
  433. scope := vm.Scope
  434. vm.Scope = scope.parent
  435. return scope
  436. }
  437. return nil
  438. }
  439. func (block * BlockValue) Call(vm *VM, arguments ...Value) []Value {
  440. ast := block.Ast
  441. // Now, don't run the block itself but the Statements node
  442. // that should be in it.
  443. children := ast.Children()
  444. if len(children) < 1 {
  445. return Fail(fmt.Errorf("Block has no statements."))
  446. }
  447. if len(children) > 1 {
  448. return Fail(fmt.Errorf("Block has too many statements."))
  449. }
  450. statements := children[0]
  451. arr := vm.RunAst(*statements, arguments...)
  452. return arr
  453. }
  454. func (builtin * BuiltinValue) Call(vm *VM, arguments ...Value) []Value {
  455. err := builtin.signature.TypeCheck(arguments...)
  456. if err != nil {
  457. return Fail(ErrorValue{err})
  458. }
  459. handler := builtin.Handler
  460. return handler.Call(vm, arguments...)
  461. }
  462. func (vm *VM) AddTrace(err error) error {
  463. res := ""
  464. for frame := vm.Frame; frame != nil; frame = frame.parent {
  465. if frame.position == nil {
  466. res = fmt.Sprintf("%s\nIn frame %v", res, frame)
  467. } else {
  468. res = fmt.Sprintf("%s\nIn %s", res, frame.position.String())
  469. }
  470. }
  471. return fmt.Errorf("%s: %s", res, err)
  472. }
  473. func (vm *VM) CallCallable(callable Callable, arguments ...Value) []Value {
  474. defer vm.PopScope()
  475. defer vm.PopFrame()
  476. vm.PushNewFrame(callable.Position())
  477. vm.PushNewScope()
  478. result := callable.Call(vm, arguments...)
  479. return result
  480. }
  481. func (vm *VM) CallNamed(name string, arguments ...Value) []Value {
  482. value := vm.Lookup(name)
  483. if value == nil {
  484. return ReturnError(vm.AddTrace(NewErrorValuef("Cannot call %s: not found.", name)))
  485. }
  486. if callable, ok := value.(Callable) ; ok {
  487. return vm.CallCallable(callable, arguments...)
  488. } else {
  489. return ReturnError(vm.AddTrace(NewErrorValuef("Cannot call %s: %v. Not callable", name, value)))
  490. }
  491. }
  492. /*
  493. func (vm * VM) CallNamedFramed(name string, arguments ...) []Value {
  494. frame := vm.PushNewFrame()
  495. }
  496. */
  497. // ScopeUp Returns the levelth scope up from the current one where 0 is the
  498. // current scope. Returns the toplevel scope if l is greater than the current
  499. // scope stack depth.
  500. func (vm * VM) ScopeUp(level int) *Scope {
  501. scope := vm.Scope
  502. for now := 0; now < level; now++ {
  503. if scope.parent == nil {
  504. return scope
  505. }
  506. scope = scope.parent
  507. }
  508. return scope
  509. }
  510. // RegisterTop registers a value at top level scope.
  511. func (vm *VM) RegisterTop(name string, value Value) Value {
  512. scope := vm.TopScope
  513. return scope.Register(name, value)
  514. }
  515. // RegisterUp registers in level scopes up from the current scope,
  516. // or at toplevel if the level is greater than the total depth
  517. func (vm *VM) RegisterUp(name string, value Value, level int) Value {
  518. scope := vm.ScopeUp(level)
  519. return scope.Register(name, value)
  520. }
  521. func (vm *VM) Register(name string, value Value) Value {
  522. return vm.Scope.Register(name, value)
  523. }
  524. func (vm *VM) RegisterCover(name string, level int) *CoverValue {
  525. value := NewCoverValue(name)
  526. vm.RegisterUp(name, value, level)
  527. return value
  528. }
  529. func (vm *VM) RegisterBuiltin(name string, handler Handler) *BuiltinValue {
  530. value := NewBuiltinValue(name, handler)
  531. vm.Register(name, value)
  532. return value
  533. }
  534. func (vm *VM) RegisterDefined(name string, signature Signature, block *BlockValue, level int) *DefinedValue {
  535. value := NewDefinedValue(name, signature, block)
  536. vm.RegisterUp(name, value, level)
  537. return value
  538. }
  539. // RegisterBuiltinWithHelp
  540. func (vm *VM) RegisterBuiltinWithHelp(name string, handler Handler, help string) *BuiltinValue {
  541. res := vm.RegisterBuiltin(name, handler)
  542. vm.SetHelp(name, help)
  543. return res
  544. }
  545. func (vm *VM) Fail() {
  546. vm.Frame.failed = true
  547. }
  548. func (vm *VM) RunAst(ast Ast, args ...Value) []Value {
  549. var result []Value
  550. /*pos := ast.Token().Position
  551. vm.PushNewFrame(&pos)
  552. defer vm.PopFrame()
  553. */
  554. // vm.Logf("RunAst: %s\n", ast.Kind().String())
  555. // Leaf nodes, both declared and in practice are self evaluating.
  556. if ast.Kind().IsLeaf() || ast.CountChildren() < 1 {
  557. result = ast.Eval(vm)
  558. if vm.Frame.returned || vm.Frame.failed {
  559. result = vm.Frame.results
  560. vm.Frame.returned = false
  561. vm.Frame.failed = false
  562. }
  563. } else {
  564. var subResult = []Value{}
  565. // Depth first recursion.
  566. for i, child := range ast.Children() {
  567. sub := vm.RunAst(*child)
  568. subResult = append(subResult, sub...)
  569. vm.Trace("RunAst: %d %v %v %v\n", i, child, sub, vm.Frame)
  570. /*
  571. if frame.failed && frame.parent != nil {
  572. // XXX failures are like panics and propagate up the call tree
  573. * // Or should they?
  574. frame.parent.failed = true
  575. frame.parent.results = frame.results
  576. }
  577. */
  578. if vm.Frame.returned || vm.Frame.failed {
  579. subResult = vm.Frame.results
  580. vm.Frame.returned = false
  581. vm.Frame.failed = false
  582. break;
  583. }
  584. }
  585. // vm.Logf("RunAst subResult: %v\n", subResult)
  586. result = ast.Eval(vm, subResult...)
  587. }
  588. // vm.Logf("RunAst result: %v\n", result)
  589. return result
  590. }
  591. func (vm *VM) DefinedHelpers() []Helper {
  592. return vm.Scope.DefinedHelpers()
  593. }
  594. func (vm * VM) BackTraceFrames() []*Frame {
  595. bt := []*Frame{}
  596. for frame := vm.Frame ; frame.parent != nil ; frame = frame.parent {
  597. bt = append(bt, frame)
  598. }
  599. return bt
  600. }
  601. func (vm * VM) BackTracePositions() []*Position {
  602. bt := []*Position{}
  603. for frame := vm.Frame ; frame.parent != nil ; frame = frame.parent {
  604. bt = append(bt, frame.position)
  605. }
  606. return bt
  607. }
  608. func (vm * VM) BackTraceStrings() []string {
  609. bt := []string{}
  610. for frame := vm.Frame ; frame.parent != nil ; frame = frame.parent {
  611. bt = append(bt, frame.position.String())
  612. }
  613. return bt
  614. }
  615. func (vm * VM) BackTrace() string {
  616. return strings.Join(vm.BackTraceStrings(), "\n")
  617. }