1use crate::type_id::*;
2use crate::space_info::*;
3use crate::func_impl::*;
4use crate::function_space_info::*;
5use crate::feature_space_info::*;
6use crate::primitive_directory::*;
7use crate::primitive_term_pointer::*;
8
9pub struct Context {
15 pub type_info_directory : TypeInfoDirectory,
16 pub space_info_directory : SpaceInfoDirectory,
17 pub primitive_directory : PrimitiveDirectory
18}
19
20impl Context {
21 pub fn get_primitive(&self, primitive_term_pointer : PrimitiveTermPointer) -> &dyn FuncImpl {
25 self.primitive_directory.get_primitive(primitive_term_pointer)
26 }
27
28 pub fn get_feature_space_info(&self, type_id : TypeId) -> &FeatureSpaceInfo {
32 self.space_info_directory.get_feature_space_info(type_id)
33 }
34
35 pub fn build_function_space_info(&self, arg_type_id : TypeId, ret_type_id : TypeId) -> FunctionSpaceInfo {
38 let arg_feat_info = self.get_feature_space_info(arg_type_id);
39 let ret_feat_info = self.get_feature_space_info(ret_type_id);
40 FunctionSpaceInfo {
41 in_feat_info : arg_feat_info,
42 out_feat_info : ret_feat_info
43 }
44 }
45 pub fn get_function_space_info(&self, func_type_id : TypeId) -> FunctionSpaceInfo {
47 let func_type = self.get_type(func_type_id);
48 match (func_type) {
49 Type::FuncType(arg_type_id, ret_type_id) => {
50 let arg_feat_info = self.get_feature_space_info(arg_type_id);
51 let ret_feat_info = self.get_feature_space_info(ret_type_id);
52 FunctionSpaceInfo {
53 in_feat_info : arg_feat_info,
54 out_feat_info : ret_feat_info
55 }
56 },
57 Type::VecType(_) => {
58 panic!();
59 }
60 }
61 }
62
63 pub fn get_func_type_id(&self, arg_type_id : TypeId, ret_type_id : TypeId) -> TypeId {
67 self.type_info_directory.get_func_type_id(arg_type_id, ret_type_id)
68 }
69 pub fn get_type(&self, id : TypeId) -> Type {
71 self.type_info_directory.get_type(id)
72 }
73 pub fn has_func_type(&self, arg_type_id : TypeId, ret_type_id : TypeId) -> bool {
76 self.type_info_directory.has_func_type(arg_type_id, ret_type_id)
77 }
78 pub fn get_application_type_ids(&self, id : TypeId) -> Vec::<(TypeId, TypeId)> {
81 self.type_info_directory.get_application_type_ids(id)
82 }
83 pub fn get_total_num_types(&self) -> usize {
85 self.type_info_directory.get_total_num_types()
86 }
87 pub fn get_dimension(&self, vec_type_id : TypeId) -> usize {
90 self.type_info_directory.get_dimension(vec_type_id)
91 }
92 pub fn get_arg_type_id(&self, func_type_id : TypeId) -> TypeId {
95 self.type_info_directory.get_arg_type_id(func_type_id)
96 }
97 pub fn get_ret_type_id(&self, func_type_id : TypeId) -> TypeId {
100 self.type_info_directory.get_ret_type_id(func_type_id)
101 }
102 pub fn is_vector_type(&self, id : TypeId) -> bool {
105 self.type_info_directory.is_vector_type(id)
106 }
107}