// Evaluator func (vm *vm) EvaluateStringInContext(input string, context Value) (Value, error) { parser.Reset() lexer := parser.NewLexer(input) result := parser.RubyParse(lexer) if result != 0 { return nil, NewParseError(vm.currentFilename) } return vm.executeWithContext(context, parser.Statements...) }
func (vm *vm) EvaluateStringInContextAndNewStack(input string, context Value) (Value, error) { parser.Reset() lexer := parser.NewLexer(input) result := parser.RubyParse(lexer) if result != 0 { return nil, NewParseError(vm.currentFilename) } vm.localVariableStack.Unshift() defer vm.localVariableStack.Shift() return vm.executeWithContext(context, parser.Statements...) }
func (vm *vm) Run(input string) (Value, error) { parser.Reset() lexer := parser.NewLexer(input) result := parser.RubyParse(lexer) if result != 0 { return nil, NewParseError(vm.currentFilename) } main := vm.ObjectSpace["main"] vm.stack.Unshift("main", vm.currentFilename, 0) defer vm.stack.Shift() vm.localVariableStack.Unshift() defer vm.localVariableStack.Shift() return vm.executeWithContext(main, parser.Statements...) }