1/* 2 * gomacro - A Go interpreter with Lisp-like macros 3 * 4 * Copyright (C) 2017-2019 Massimiliano Ghilardi 5 * 6 * This Source Code Form is subject to the terms of the Mozilla Public 7 * License, v. 2.0. If a copy of the MPL was not distributed with this 8 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 * 10 * 11 * func0ret0.go 12 * 13 * Created on Apr 16, 2017 14 * Author Massimiliano Ghilardi 15 */ 16 17package fast 18 19import ( 20 r "reflect" 21 22 . "github.com/cosmos72/gomacro/base" 23 xr "github.com/cosmos72/gomacro/xreflect" 24) 25 26func (c *Comp) func0ret0(t xr.Type, m *funcMaker) func(env *Env) r.Value { 27 funcbody := m.funcbody 28 if funcbody == nil { 29 return func(env *Env) r.Value { 30 return valueOfNopFunc 31 } 32 } 33 var debugC *Comp 34 if c.Globals.Options&OptDebugger != 0 { 35 debugC = c 36 } 37 38 nbind := m.nbind 39 nintbind := m.nintbind 40 return func(env *Env) r.Value { 41 // function is closed over the env used to DECLARE it 42 env.MarkUsedByClosure() 43 return r.ValueOf(func() { 44 env := newEnv4Func(env, nbind, nintbind, debugC) 45 // execute the body 46 funcbody(env) 47 48 env.freeEnv4Func() 49 }) 50 } 51} 52