Esempio n. 1
0
// 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...)
}
Esempio n. 2
0
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...)
}
Esempio n. 3
0
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...)
}