| 
									
										
										
										
											2020-05-25 21:20:41 -07:00
										 |  |  | #pragma once
 | 
					
						
							|  |  |  | #include <map>
 | 
					
						
							|  |  |  | #include <string>
 | 
					
						
							| 
									
										
										
										
											2020-05-30 16:40:27 -07:00
										 |  |  | #include <set>
 | 
					
						
							| 
									
										
										
										
											2020-05-25 21:20:41 -07:00
										 |  |  | #include "type.hpp"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct type_env; | 
					
						
							|  |  |  | using type_env_ptr = std::shared_ptr<type_env>; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-31 00:34:12 -07:00
										 |  |  | enum class visibility { global,local }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-25 21:20:41 -07:00
										 |  |  | struct type_env { | 
					
						
							| 
									
										
										
										
											2020-05-31 00:34:12 -07:00
										 |  |  |     struct variable_data { | 
					
						
							|  |  |  |         type_scheme_ptr type; | 
					
						
							|  |  |  |         visibility vis; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         variable_data() | 
					
						
							|  |  |  |             : variable_data(nullptr, visibility::local) {} | 
					
						
							|  |  |  |         variable_data(type_scheme_ptr t, visibility v) | 
					
						
							|  |  |  |             : type(std::move(t)), vis(v) {} | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-25 21:20:41 -07:00
										 |  |  |     type_env_ptr parent; | 
					
						
							| 
									
										
										
										
											2020-05-31 00:34:12 -07:00
										 |  |  |     std::map<std::string, variable_data> names; | 
					
						
							| 
									
										
										
										
											2020-05-25 21:20:41 -07:00
										 |  |  |     std::map<std::string, type_ptr> type_names; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     type_env(type_env_ptr p) : parent(std::move(p)) {} | 
					
						
							|  |  |  |     type_env() : type_env(nullptr) {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-30 16:40:27 -07:00
										 |  |  |     void find_free(const type_mgr& mgr, std::set<std::string>& into) const; | 
					
						
							|  |  |  |     void find_free_except(const type_mgr& mgr, const std::string& avoid, | 
					
						
							|  |  |  |             std::set<std::string>& into) const; | 
					
						
							| 
									
										
										
										
											2020-05-25 21:20:41 -07:00
										 |  |  |     type_scheme_ptr lookup(const std::string& name) const; | 
					
						
							| 
									
										
										
										
											2020-05-31 18:52:52 -07:00
										 |  |  |     bool is_global(const std::string& name) const; | 
					
						
							| 
									
										
										
										
											2020-05-25 21:20:41 -07:00
										 |  |  |     type_ptr lookup_type(const std::string& name) const; | 
					
						
							| 
									
										
										
										
											2020-05-31 00:34:12 -07:00
										 |  |  |     void bind(const std::string& name, type_ptr t, | 
					
						
							|  |  |  |             visibility v = visibility::local); | 
					
						
							|  |  |  |     void bind(const std::string& name, type_scheme_ptr t, | 
					
						
							|  |  |  |             visibility v = visibility::local); | 
					
						
							| 
									
										
										
										
											2020-05-25 21:20:41 -07:00
										 |  |  |     void bind_type(const std::string& type_name, type_ptr t); | 
					
						
							|  |  |  |     void generalize(const std::string& name, type_mgr& mgr); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type_env_ptr type_scope(type_env_ptr parent); |