示例#1
0
文件: define.go 项目: ctliu3/Gosp
// This is a set manipulation.
func (self *Define) Eval(env *scope.Scope) value.Value {
	fmt.Println("Define#Eval")
	var_ := self.var_.(*Ident)
	val := self.expr.Eval(env)
	env.Insert(var_.Name, scope.NewObj(val))

	// Define does not have return val.
	return nil
}
示例#2
0
文件: letrec.go 项目: ctliu3/Gosp
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
}
示例#3
0
文件: set.go 项目: ctliu3/Gosp
// This is a set manipulation.
func (self *Set) Eval(env *scope.Scope) value.Value {
	fmt.Println("Set#Eval")
	var_ := self.var_.(*Ident)
	val := self.expr.Eval(env)
	if obj := env.Lookup(var_.Name, true); obj == nil {
		panic("set!: assignment disallowed.")
	}
	env.Insert(var_.Name, scope.NewObj(val))

	// Define does not have return val.
	return nil
}
示例#4
0
文件: letstar.go 项目: ctliu3/Gosp
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
}
示例#5
0
文件: call.go 项目: ctliu3/Gosp
func precedureCall(closure *value.Closure, args ...value.Value) value.Value {
	t := closure.Lambda.(*Lambda)

	env := closure.Env.(*scope.Scope)
	formals := t.Formals.(*Tuple)
	body := t.Body.(Node)

	nargs := len(formals.Nodes)
	if nargs != len(args) {
		panic(fmt.Errorf(
			`the expected number of arguments does not match the given number
        expected: %v
        given: %v`, len(formals.Nodes), nargs))
	}

	for i := 0; i < nargs; i++ {
		env.Insert(formals.Nodes[i].(*Ident).Name, scope.NewObj(args[i]))
	}
	return body.Eval(env)
}