vm.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. // vm, the virtual low level machine that runs MUESLI.
  2. package muesli
  3. import "fmt"
  4. // Handler function
  5. type Handler func(vm *VM, arguments ...Value) []Value
  6. func (handler *Handler) Call(vm *VM, arguments ...Value) []Value {
  7. return (*handler)(vm, arguments...)
  8. }
  9. // A callable Value must implement the Caller interface
  10. type Caller interface {
  11. Call(vm *VM, arguments ...Value) []Value
  12. }
  13. // A helper Value has a help text available.
  14. // This help text can be set as well.
  15. type Helper interface {
  16. HelperName() string
  17. Help() string
  18. SetHelp(string) string
  19. }
  20. // Callable value types
  21. type CallableValue struct {
  22. // Name of the callable
  23. Name string
  24. // Help string for the callable.
  25. HelpText string
  26. }
  27. // Implement Helper interface
  28. func (val CallableValue) Help() string {
  29. return val.HelpText
  30. }
  31. // Implement Helper interface
  32. func (val * CallableValue) SetHelp(help string) string {
  33. val.HelpText = help
  34. return val.HelpText
  35. }
  36. // Implement Helper interface
  37. func (val CallableValue) HelperName() string {
  38. return val.Name
  39. }
  40. // AppendHelp appends help to an existing helper.
  41. func AppendHelp(helper Helper, extra string) string {
  42. return helper.SetHelp( helper.Help() + extra)
  43. }
  44. // ClearHelp rresets the help text to an empty string.
  45. func ClearHelp(helper Helper, extra string) string {
  46. return helper.SetHelp("")
  47. }
  48. func (val CallableValue) String() string {
  49. return val.Name
  50. }
  51. func (val CallableValue) Type() TypeValue {
  52. return TypeValue("Callable")
  53. }
  54. func (from CallableValue) Convert(to interface{}) error {
  55. return NewErrorValuef("Cannot convert the callable value %v to %v", from, to)
  56. }
  57. func (val *CallableValue) Call(vm *VM, arguments ...Value) []Value {
  58. panic("Not implemented")
  59. }
  60. // A struct to store a built in function
  61. type BuiltinValue struct {
  62. CallableValue
  63. Handler
  64. }
  65. func NewCallableValue(name string) CallableValue {
  66. return CallableValue{name, ""}
  67. }
  68. func NewBuiltinValue(name string, handler Handler) *BuiltinValue {
  69. result := &BuiltinValue{}
  70. result.Name = name
  71. result.Handler = handler
  72. return result
  73. }
  74. func (builtin *BuiltinValue) Call(vm *VM, arguments ...Value) []Value {
  75. return vm.CallBuiltin(builtin.Handler, arguments...)
  76. }
  77. // A block in a script.
  78. type BlockValue struct {
  79. CallableValue
  80. Ast *Ast
  81. }
  82. func NewBlockValue(definition *Ast) *BlockValue {
  83. result := &BlockValue{}
  84. result.Name = fmt.Sprintf("<block:%s>", definition.String())
  85. result.Ast = definition
  86. return result
  87. }
  88. func (block *BlockValue) Call(vm *VM, arguments ...Value) []Value {
  89. res := vm.CallBlock(block.Ast, arguments...)
  90. return res
  91. }
  92. /* Parameters for a defined value */
  93. type Parameter struct {
  94. Name WordValue
  95. Type TypeValue
  96. }
  97. // A script defined function
  98. type DefinedValue struct {
  99. CallableValue
  100. Body *BlockValue
  101. Parameters []*Parameter
  102. }
  103. func NewDefinedValue(name string, params []*Parameter, body *BlockValue) *DefinedValue {
  104. result := &DefinedValue{}
  105. result.Name = name
  106. result.Body = body
  107. result.Parameters = params
  108. return result
  109. }
  110. func (defined *DefinedValue) Call(vm *VM, arguments ...Value) []Value {
  111. defer vm.PopFrame()
  112. defer vm.PopScope()
  113. vm.PushNewFrame()
  114. vm.PushNewScope()
  115. for i , arg := range arguments {
  116. if i >= len(defined.Parameters) {
  117. break
  118. }
  119. param := defined.Parameters[i]
  120. expectedType := param.Type
  121. if !expectedType.IsMatch(arg.Type()) {
  122. return Fail(NewErrorValuef("Argument %d type mismatch: %s<->%s", i, expectedType, arg.Type()))
  123. }
  124. vm.Register(param.Name.String(), arg)
  125. }
  126. res := defined.Body.Call(vm, arguments...)
  127. return res
  128. }
  129. func (defined *DefinedValue) Help() string {
  130. help := defined.CallableValue.Help()
  131. extra := "["
  132. for _, parameter := range defined.Parameters {
  133. extra = fmt.Sprintf("%s %s %s", extra, parameter.Name, parameter.Type)
  134. }
  135. extra = extra + "]:"
  136. return extra + help
  137. }
  138. /*
  139. Amount of types that will be considered inside a signature.
  140. Limited mosty to allow hashability.
  141. */
  142. const TypesInSignature = 8
  143. /* A signature describes the desired types of an overloaded function call. */
  144. type Signature struct {
  145. Types [TypesInSignature]TypeValue
  146. }
  147. func CalculateSignature(arguments ...Value) Signature {
  148. signature := Signature{}
  149. for i := 0; i < len(signature.Types); i++ {
  150. if i < len(arguments) {
  151. signature.Types[i] = arguments[i].Type()
  152. } else {
  153. signature.Types[i] = AnyTypeValue
  154. }
  155. }
  156. return signature
  157. }
  158. func (tv TypeValue) IsMatch(other TypeValue) bool {
  159. if tv == AnyTypeValue || other == AnyTypeValue {
  160. return true
  161. }
  162. if tv == ZeroTypeValue || other == ZeroTypeValue {
  163. return true
  164. }
  165. return tv == other
  166. }
  167. func (signature Signature) IsMatch(other Signature) bool {
  168. for i, kind := range signature.Types {
  169. t1 := kind
  170. t2 := other.Types[i]
  171. if !t1.IsMatch(t2) {
  172. return false
  173. }
  174. }
  175. return true
  176. }
  177. /* An overload is an overloaded value that can be called. */
  178. type Overload struct {
  179. Caller
  180. }
  181. /* A cover is a callable that dispatches to other callables depending on
  182. the types of the arguments, in particular the first one. The individual
  183. callable functions are the overloads
  184. */
  185. type CoverValue struct {
  186. CallableValue
  187. Overloads map[Signature]Overload
  188. }
  189. func (cv CoverValue) String() string {
  190. res := fmt.Sprintf("cover %s [ ", cv.Name)
  191. for k, v := range cv.Overloads {
  192. res = fmt.Sprintf("%s [%v] %v", res, k, v.Caller)
  193. }
  194. res = fmt.Sprintf("%s].", res)
  195. return res;
  196. }
  197. func NewCoverValue(name string) *CoverValue {
  198. result := &CoverValue{}
  199. result.Name = name
  200. result.Overloads = make(map[Signature]Overload)
  201. return result
  202. }
  203. func (cover *CoverValue) Help() string {
  204. help := cover.CallableValue.Help()
  205. extra := ""
  206. for signature, _ := range cover.Overloads {
  207. extra = fmt.Sprintf("%s overloads: %v\n", extra, signature)
  208. }
  209. return extra + help
  210. }
  211. func (cover *CoverValue) Call(vm *VM, arguments ...Value) []Value {
  212. signature := CalculateSignature(arguments...)
  213. if overload, ok := cover.Overloads[signature]; ok {
  214. return overload.Call(vm, arguments...)
  215. } else {
  216. for overloadSignature, overload := range cover.Overloads {
  217. if signature.IsMatch(overloadSignature) {
  218. return overload.Call(vm, arguments...)
  219. }
  220. }
  221. }
  222. vm.Fail()
  223. return Fail(NewErrorValuef("Could not match cover %s with arguments: %s<->%v", cover.String(), signature))
  224. }
  225. const (
  226. CoverTypeValue = TypeValue("Cover")
  227. BuiltinTypeValue = TypeValue("Builtin")
  228. DefinedTypeValue = TypeValue("Defined")
  229. BlockTypeValue = TypeValue("Block")
  230. )
  231. func (v CoverValue) Type() TypeValue { return CoverTypeValue }
  232. func (v BuiltinValue) Type() TypeValue { return BuiltinTypeValue }
  233. func (v DefinedValue) Type() TypeValue { return DefinedTypeValue }
  234. func (v BlockValue) Type() TypeValue { return BlockTypeValue }
  235. func (from CoverValue) Convert(to interface{}) error {
  236. return NewErrorValuef("Cannot convert the cover value %v to %v", from, to)
  237. }
  238. func (from BuiltinValue) Convert(to interface{}) error {
  239. return NewErrorValuef("Cannot convert the builtin value %v to %v", from, to)
  240. }
  241. func (from DefinedValue) Convert(to interface{}) error {
  242. return NewErrorValuef("Cannot convert the defined value %v to %v", from, to)
  243. }
  244. func (from BlockValue) Convert(to interface{}) error {
  245. if toValue, isOk := to.(*BlockValue) ; isOk {
  246. (*toValue) = from
  247. return nil
  248. }
  249. return NewErrorValuef("Cannot convert the block value %v to %v", from, to)
  250. }
  251. func (cv * CoverValue) AddOverload(callable Caller, tv ... TypeValue) error {
  252. // fmt.Printf("AddOverload: %v\n", tv)
  253. signature := Signature{}
  254. length := len(tv)
  255. if length > len(signature.Types) {
  256. length = len(signature.Types)
  257. }
  258. for i := 0; i < length; i++ {
  259. signature.Types[i] = tv[i]
  260. }
  261. cv.Overloads[signature] = Overload { callable }
  262. // fmt.Printf("Overloads: %v\n", cv.Overloads)
  263. return nil
  264. }
  265. func (vm * VM) AddOverload(from, target string, tv... TypeValue) error {
  266. var cover *CoverValue
  267. var callable Caller
  268. var ok bool
  269. lookup := vm.Lookup(from)
  270. if lookup == nil {
  271. cover = vm.RegisterCover(from)
  272. } else if cover, ok = lookup.(*CoverValue) ; !ok {
  273. return fmt.Errorf("%s exists and is not a cover value", from)
  274. }
  275. // fmt.Printf("AddOverload: %v %v\n", lookup, cover)
  276. lookup = vm.Lookup(target)
  277. if lookup == nil {
  278. return fmt.Errorf("target %s is not defined", target)
  279. }
  280. // fmt.Printf("AddOverload lookup: %v\n", lookup)
  281. if callable, ok = lookup.(Caller) ; !ok {
  282. return fmt.Errorf("%s is not a callable value", target)
  283. }
  284. res := cover.AddOverload(callable, tv...)
  285. // fmt.Printf("AddOverload: %v %v\n", lookup, cover)
  286. return res
  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) Parent(level int) *Scope {
  310. if level < 1 {
  311. return scope
  312. }
  313. parent := scope.parent
  314. for parent != nil && level > 1 {
  315. level--
  316. parent = parent.parent
  317. }
  318. return parent
  319. }
  320. func (scope *Scope) Lookup(name string) Value {
  321. value, ok := scope.symbols[name]
  322. if ok {
  323. return value
  324. }
  325. if scope.parent != nil {
  326. return scope.parent.Lookup(name)
  327. }
  328. return NilValue
  329. }
  330. func (scope *Scope) Register(name string, value Value) Value {
  331. scope.symbols[name] = value
  332. return value
  333. }
  334. func (scope * Scope) Known(filter func(string, Value) bool) map[string]Value {
  335. res := make(map[string]Value)
  336. if scope.parent != nil {
  337. res = scope.parent.Known(filter)
  338. }
  339. for k, v := range scope.symbols {
  340. if (filter == nil) || filter(k, v) {
  341. res[k] = v
  342. }
  343. }
  344. return res
  345. }
  346. func (scope * Scope) ForEachDefined(do func(string, Value) (bool, error)) (bool, error) {
  347. var res bool = true
  348. var err error
  349. if (do == nil) {
  350. return false, fmt.Errorf("do may not be nil")
  351. }
  352. if scope.parent != nil {
  353. res, err = scope.parent.ForEachDefined(do)
  354. }
  355. if res == false || err != nil {
  356. return res, err
  357. }
  358. for k, v := range scope.symbols {
  359. res, err = do(k, v)
  360. if res == false || err != nil {
  361. return res, err
  362. }
  363. }
  364. return res, err
  365. }
  366. func (scope* Scope) DefinedHelpers() []Helper {
  367. res := []Helper{}
  368. scope.ForEachDefined(func (k string, v Value) (bool, error) {
  369. helper, hok := v.(Helper)
  370. if hok {
  371. fmt.Printf("Helper: %s\n", helper.HelperName())
  372. res = append(res, helper)
  373. } else {
  374. fmt.Printf("NOT Helper: %s\n", v.String())
  375. }
  376. return true, nil
  377. })
  378. return res
  379. }
  380. // Frame of execution of a function
  381. type Frame struct {
  382. parent *Frame
  383. arguments []Value
  384. results []Value
  385. failed bool
  386. }
  387. func NewFrame(parent *Frame) *Frame {
  388. return &Frame{parent, EmptyValueArray(), EmptyValueArray(), false}
  389. }
  390. type Tracer interface {
  391. Trace(vm VM, ast Ast, values ...Value) bool
  392. }
  393. // Virtual machine
  394. type VM struct {
  395. TopScope *Scope // Top level scope
  396. TopFrame *Frame // Top level scope
  397. *Scope // Current Scope
  398. *Frame // Current frame
  399. Tracer // Tracer to emit tracing info to, could be used for logging or debugging
  400. ExitStatus int
  401. }
  402. func NewVM() *VM {
  403. vm := &VM{NewScope(nil), NewFrame(nil), nil, nil, nil, 0}
  404. vm.Scope = vm.TopScope
  405. vm.Frame = vm.TopFrame
  406. return vm
  407. }
  408. func (vm *VM) PushNewFrame() *Frame {
  409. frame := NewFrame(vm.Frame)
  410. vm.Frame = frame
  411. return frame
  412. }
  413. func (vm *VM) PushNewScope() *Scope {
  414. scope := NewScope(vm.Scope)
  415. vm.Scope = scope
  416. return scope
  417. }
  418. func (vm *VM) PopFrame() *Frame {
  419. if (vm.Frame != vm.TopFrame) && (vm.Frame.parent != nil) {
  420. frame := vm.Frame
  421. vm.Frame = frame.parent
  422. return frame
  423. }
  424. return nil
  425. }
  426. func (vm *VM) PopScope() *Scope {
  427. if (vm.Scope != vm.TopScope) && (vm.Scope.parent != nil) {
  428. scope := vm.Scope
  429. vm.Scope = scope.parent
  430. return scope
  431. }
  432. return nil
  433. }
  434. func (vm *VM) CallDefined(ast *Ast, arguments ...Value) []Value {
  435. arr := ast.Run(vm, NewListValue(arguments...))
  436. return arr
  437. }
  438. func (vm *VM) CallBlock(ast *Ast, arguments ...Value) []Value {
  439. arr := vm.RunChildren(*ast, arguments...)
  440. return arr
  441. }
  442. func (vm *VM) CallBuiltin(handler Handler, arguments ...Value) []Value {
  443. return handler.Call(vm, arguments...)
  444. }
  445. func (vm *VM) CallCover(cover * CoverValue, arguments ...Value) []Value {
  446. return cover.Call(vm, arguments...)
  447. }
  448. func (vm *VM) CallNamed(name string, arguments ...Value) []Value {
  449. value := vm.Lookup(name)
  450. switch toCall := value.(type) {
  451. case *BuiltinValue:
  452. return vm.CallBuiltin(toCall.Handler, arguments...)
  453. case *DefinedValue:
  454. return vm.CallDefined(toCall.Body.Ast, arguments...)
  455. case *CoverValue:
  456. return vm.CallCover(toCall, arguments...)
  457. case *BlockValue:
  458. return vm.CallBlock(toCall.Ast, arguments...)
  459. default:
  460. return ReturnError(NewErrorValuef("Cannot call %s: %v", name, value))
  461. }
  462. }
  463. /*
  464. func (vm * VM) CallNamedFramed(name string, arguments ...) []Value {
  465. frame := vm.PushNewFrame()
  466. }
  467. */
  468. func (vm *VM) Register(name string, value Value) Value {
  469. return vm.Scope.Register(name, value)
  470. }
  471. func (vm *VM) RegisterCover(name string) *CoverValue {
  472. value := NewCoverValue(name)
  473. vm.Register(name, value)
  474. return value
  475. }
  476. func (vm *VM) RegisterBuiltin(name string, handler Handler) Value {
  477. value := NewBuiltinValue(name, handler)
  478. return vm.Register(name, value)
  479. }
  480. func (vm *VM) RegisterDefined(name string, params []*Parameter, block *BlockValue) Value {
  481. value := NewDefinedValue(name, params, block)
  482. return vm.Register(name, value)
  483. }
  484. // RegisterBuiltinWithHelp
  485. func (vm *VM) RegisterBuiltinWithHelp(name string, handler Handler, help string) Value {
  486. res := vm.RegisterBuiltin(name, handler)
  487. vm.SetHelp(name, help)
  488. return res
  489. }
  490. func (vm *VM) Fail() {
  491. vm.Frame.failed = true
  492. }
  493. func (vm *VM) RunChildren(ast Ast, args ...Value) []Value {
  494. if ast.CountChildren() < 1 {
  495. return ReturnEmpty()
  496. }
  497. /* if ast.CountChildren() == 1 {
  498. return ast.Child(0).Run(vm, args)
  499. }
  500. */
  501. result := []Value{}
  502. for _, child := range ast.Children() {
  503. val := child.Run(vm, args...)
  504. // skip empty results
  505. if len(val) < 1 {
  506. continue
  507. }
  508. first := val[0]
  509. if _, isEmpty := first.(EmptyValue); isEmpty {
  510. continue
  511. }
  512. last := val[len(val) -1]
  513. // errors in the results at the last position take precendence and are propagated upwards.
  514. if _, isErr := last.(ErrorValue); isErr {
  515. return val
  516. }
  517. result = append(result, val...)
  518. }
  519. return result
  520. }
  521. func (vm *VM) RunChildrenLastResult(ast Ast, args ...Value) Value {
  522. var result Value = EmptyValue{}
  523. for _, child := range ast.Children() {
  524. val := child.Run(vm, args...)
  525. // skip empty results
  526. if len(val) < 1 {
  527. continue
  528. }
  529. first := val[0]
  530. if _, isEmpty := first.(EmptyValue); isEmpty {
  531. continue
  532. }
  533. last := val[len(val) -1]
  534. // errors in the results at the last position take precendence and are propagated upwards.
  535. if _, isErr := last.(ErrorValue); isErr {
  536. return last
  537. }
  538. result = last
  539. }
  540. // The last non empty result is the result of this function.
  541. return result
  542. }
  543. func (vm *VM) RunChildrenFirstResult(ast Ast, args ...Value) Value {
  544. var result Value = EmptyValue{}
  545. for _, child := range ast.Children() {
  546. val := child.Run(vm, args...)
  547. // skip empty results
  548. if len(val) < 1 {
  549. continue
  550. }
  551. first := val[0]
  552. if _, isEmpty := first.(EmptyValue); isEmpty {
  553. continue
  554. }
  555. // otherwise if non empty return the result.
  556. return first
  557. }
  558. return result
  559. }
  560. func (vm *VM) RunAst(ast Ast, args ...Value) []Value {
  561. return ast.Run(vm, args...)
  562. }
  563. func (vm *VM) DefinedHelpers() []Helper {
  564. return vm.Scope.DefinedHelpers()
  565. }
  566. /*
  567. func (vm *VM) RunProgram(ast *BasicAst) ListValue {
  568. return vm.RunChildren(ast, (*VM).RunStatements)
  569. }
  570. func (vm *VM) RunStatements(ast *BasicAst) ListValue {
  571. return vm.RunChildren(ast, (*VM).RunStatement)
  572. }
  573. func (vm *VM) RunStatement(ast *BasicAst) ListValue {
  574. return NewListValue()
  575. }
  576. func (vm *VM) RunSet(ast *BasicAst) ListValue { return NewListValue() }
  577. func (vm *VM) RunGet(ast *BasicAst) ListValue { return NewListValue() }
  578. func (vm *VM) RunTarget(ast *BasicAst) ListValue { return NewListValue() }
  579. func (vm *VM) RunCommand(ast *BasicAst) ListValue { return NewListValue() }
  580. func (vm *VM) RunArguments(ast *BasicAst) ListValue { return NewListValue() }
  581. func (vm *VM) RunArgument(ast *BasicAst) ListValue { return NewListValue() }
  582. func (vm *VM) RunExpression(ast *BasicAst) ListValue { return NewListValue() }
  583. func (vm *VM) RunBlock(ast *BasicAst) ListValue { return NewListValue() }
  584. func (vm *VM) RunParenthesis(ast *BasicAst) ListValue { return NewListValue() }
  585. func (vm *VM) RunList(ast *BasicAst) ListValue { return NewListValue() }
  586. func (vm *VM) RunCapture(ast *BasicAst) ListValue { return NewListValue() }
  587. func (vm *VM) RunWordValue(ast *BasicAst) ListValue { return NewListValue() }
  588. func (vm *VM) RunWord(ast *BasicAst) ListValue { return NewListValue() }
  589. func (vm *VM) RunType(ast *BasicAst) ListValue { return NewListValue() }
  590. func (vm *VM) RunValue(ast *BasicAst) ListValue { return NewListValue() }
  591. func (vm *VM) RunEnd(ast *BasicAst) ListValue { return NewListValue() }
  592. func (vm *VM) RunError(ast *BasicAst) ListValue { return NewListValue() }
  593. func (vm *VM) Run(ast *BasicAst) ListValue {
  594. switch ast.AstKind {
  595. case AstKindProgram:
  596. return vm.RunProgram(ast)
  597. case AstKindStatements:
  598. return vm.RunStatements(ast)
  599. case AstKindStatement:
  600. return vm.RunStatement(ast)
  601. case AstKindSet:
  602. return vm.RunSet(ast)
  603. case AstKindGet:
  604. return vm.RunGet(ast)
  605. case AstKindTarget:
  606. return vm.RunTarget(ast)
  607. case AstKindCommand:
  608. return vm.RunCommand(ast)
  609. case AstKindArguments:
  610. return vm.RunArguments(ast)
  611. case AstKindArgument:
  612. return vm.RunArgument(ast)
  613. case AstKindExpression:
  614. return vm.RunExpression(ast)
  615. case AstKindBlock:
  616. return vm.RunBlock(ast)
  617. case AstKindParenthesis:
  618. return vm.RunParenthesis(ast)
  619. case AstKindList:
  620. return vm.RunList(ast)
  621. case AstKindCapture:
  622. return vm.RunCapture(ast)
  623. case AstKindWordValue:
  624. return vm.RunWordValue(ast)
  625. case AstKindWord:
  626. return vm.RunWord(ast)
  627. case AstKindType:
  628. return vm.RunType(ast)
  629. case AstKindValue:
  630. return vm.RunValue(ast)
  631. case AstKindEnd:
  632. return vm.RunEnd(ast)
  633. case AstKindError:
  634. return vm.RunError(ast)
  635. default:
  636. return ListValue{[]Value{NewErrorValuef("Unknown ast node type: %d", ast.AstKind)}}
  637. }
  638. }
  639. */