Exemplo n.º 1
0
// 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
}
Exemplo n.º 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
}
Exemplo n.º 3
0
Arquivo: set.go Projeto: 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
}
Exemplo n.º 4
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
}
Exemplo n.º 5
0
Arquivo: call.go Projeto: 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)
}