Example #1
0
func (self *LetStar) Eval(env *scope.Scope) value.Value {
	fmt.Println("#LetStar#Eval")
	local := scope.NewScope(env)
	for _, bind := range self.bindings.Bindings {
		local.Insert(bind.var_, scope.NewObj(bind.init.Eval(local)))
	}

	var ret value.Value
	for _, node := range self.body {
		ret = node.Eval(local)
	}
	return ret
}
Example #2
0
func (self *Letrec) Eval(env *scope.Scope) value.Value {
	local := scope.NewScope(env)
	nbind := len(self.bindings.Bindings)

	for i := 0; i < nbind; i++ {
		bind := self.bindings.Bindings[i]
		local.Insert(bind.var_, scope.NewObj(bind.init.Eval(local)))
	}
	for i := nbind - 1; i >= 0; i-- {
		bind := self.bindings.Bindings[i]
		local.Insert(bind.var_, scope.NewObj(bind.init.Eval(local)))
	}

	var ret value.Value
	for _, node := range self.body {
		ret = node.Eval(local)
	}
	return ret
}
Example #3
0
File: eval.go Project: ctliu3/Gosp
func Eval(expr string) string {
	nodes := parser.ParseFromString(expr)
	fmt.Printf("#AST = %d\n", len(nodes))

	env := scope.NewScope(nil)
	var result []string
	for _, node := range nodes {
		switch node.(type) {
		case *ast.Import:
			expr := node.Eval(env)
			EvalImport(expr.String(), env)
		default:
			if val := node.Eval(env); val != nil {
				result = append(result, val.String())
			}
		}
	}

	return strings.Join(result, " ")
}