• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef META_HS_BIND_HPP
2 #define META_HS_BIND_HPP
3 
4 // Copyright Abel Sinkovics (abel@sinkovics.hu)  2012.
5 // Distributed under the Boost Software License, Version 1.0.
6 //    (See accompanying file LICENSE_1_0.txt or copy at
7 //          http://www.boost.org/LICENSE_1_0.txt)
8 
9 #include <lazy.hpp>
10 #include <ast.hpp>
11 
12 #include <boost/mpl/at.hpp>
13 #include <boost/mpl/insert.hpp>
14 #include <boost/mpl/pair.hpp>
15 
16 template <class AST, class TopEnv, class Env>
17 struct bind;
18 
19 template <class V, class TopEnv, class Env>
20 struct bind<ast::value<V>, TopEnv, Env>
21 {
22   typedef lazy::value<V> type;
23 };
24 
25 template <class Name, class TopEnv, class Env>
26 struct bind<ast::ref<Name>, TopEnv, Env> :
27   bind<typename boost::mpl::at<Env, Name>::type, TopEnv, Env>
28 {};
29 
30 template <class F, class Arg, class TopEnv, class Env>
31 struct bind<ast::application<F, Arg>, TopEnv, Env>
32 {
33   typedef
34     lazy::application<
35       typename bind<F, TopEnv, Env>::type,
36       typename bind<Arg, TopEnv, Env>::type
37     >
38     type;
39 };
40 
41 template <class F, class ArgName, class TopEnv, class Env>
42 struct bind<ast::lambda<F, ArgName>, TopEnv, Env>
43 {
44   typedef bind type;
45 
46   template <class ArgValue>
47   struct apply :
48     bind<
49       F,
50       TopEnv,
51       typename boost::mpl::insert<
52         Env,
53         boost::mpl::pair<ArgName, ast::value<ArgValue> >
54       >::type
55     >::type
56   {};
57 };
58 
59 template <class E, class TopEnv, class Env>
60 struct bind<ast::top_bound<E>, TopEnv, Env> : bind<E, TopEnv, TopEnv> {};
61 
62 #endif
63 
64