diff options
Diffstat (limited to 'frontend')
-rw-r--r-- | frontend/convertcases.icl | 71 |
1 files changed, 38 insertions, 33 deletions
diff --git a/frontend/convertcases.icl b/frontend/convertcases.icl index 147bd6d..a43878e 100644 --- a/frontend/convertcases.icl +++ b/frontend/convertcases.icl @@ -70,7 +70,8 @@ where = (BackendBody [ { bb_args = map FP_Variable tb_args, bb_rhs = tb_rhs }], cs) eliminate_code_sharing_in_function dcl_functions common_defs (TransformedBody body=:{tb_rhs}) (collected_imports, cs=:{cs_expr_heap,cs_var_heap}) - # {rcs_var_heap, rcs_expr_heap, rcs_imports} = weightedRefCount {rci_dcl_functions=dcl_functions, rci_common_defs=common_defs, rci_main_dcl_module_n=main_dcl_module_n, rci_depth=1} tb_rhs + # {rcs_var_heap, rcs_expr_heap, rcs_imports} + = weightedRefCount {rci_imported={cii_dcl_functions=dcl_functions, cii_common_defs=common_defs, cii_main_dcl_module_n=main_dcl_module_n}, rci_depth=1} tb_rhs { rcs_var_heap = cs_var_heap, rcs_expr_heap = cs_expr_heap, rcs_free_vars = [], rcs_imports = collected_imports} // ---> ("eliminate_code_sharing_in_function (weightedRefCount)", tb_rhs) (tb_rhs, {di_lets,di_var_heap,di_expr_heap}) = distributeLets 1 tb_rhs { di_lets = [], di_var_heap = rcs_var_heap, di_expr_heap = rcs_expr_heap} @@ -93,10 +94,14 @@ where */ +:: CheckImportedInfo = + { cii_dcl_functions :: !{# {# FunType} } + , cii_common_defs :: !{# CommonDefs} + , cii_main_dcl_module_n :: !Int + } + :: RCInfo = - { rci_dcl_functions :: !{# {# FunType} } - , rci_common_defs :: !{# CommonDefs} - , rci_main_dcl_module_n :: !Int + { rci_imported :: !CheckImportedInfo , rci_depth :: !Int } @@ -237,28 +242,28 @@ weightedRefCountOfCase rci=:{rci_depth} this_case=:{case_expr, case_guards, case = { rcs_info & rcs_var_heap = rcs_var_heap, rcs_expr_heap = rcs_expr_heap, rcs_free_vars = rcs_free_vars } // ---> ("weightedRefCountOfCase", ptrToInt case_info_ptr, case_expr) where - weighted_ref_count_in_default rci=:{rci_main_dcl_module_n} (Yes expr) info - = weightedRefCountInPatternExpr rci_main_dcl_module_n rci expr info + weighted_ref_count_in_default rci (Yes expr) info + = weightedRefCountInPatternExpr rci expr info weighted_ref_count_in_default rci No info = ([], info) weighted_ref_count_in_case_patterns rci (AlgebraicPatterns type patterns) collected_imports var_heap expr_heap = mapSt (weighted_ref_count_in_algebraic_pattern rci) patterns ([], collected_imports, var_heap, expr_heap) where - weighted_ref_count_in_algebraic_pattern rci=:{rci_common_defs, rci_main_dcl_module_n} {ap_expr,ap_symbol={glob_module, glob_object={ds_index}}} wrcs_state + weighted_ref_count_in_algebraic_pattern rci=:{rci_imported={cii_main_dcl_module_n, cii_common_defs}} {ap_expr,ap_symbol={glob_module, glob_object={ds_index}}} wrcs_state # (free_vars_with_rc, (all_free_vars, collected_imports, var_heap, expr_heap)) - = weightedRefCountInPatternExpr rci_main_dcl_module_n rci ap_expr wrcs_state - | glob_module <> rci_main_dcl_module_n - # {cons_type_ptr} = rci_common_defs.[glob_module].com_cons_defs.[ds_index] + = weightedRefCountInPatternExpr rci ap_expr wrcs_state + | glob_module <> cii_main_dcl_module_n + # {cons_type_ptr} = cii_common_defs.[glob_module].com_cons_defs.[ds_index] (collected_imports, var_heap) = checkImportedSymbol (SK_Constructor {glob_module = glob_module, glob_object = ds_index}) cons_type_ptr (collected_imports, var_heap) = (free_vars_with_rc, (all_free_vars, collected_imports, var_heap, expr_heap)) = (free_vars_with_rc, (all_free_vars, collected_imports, var_heap, expr_heap)) - weighted_ref_count_in_case_patterns rci=:{rci_main_dcl_module_n} (BasicPatterns type patterns) collected_imports var_heap expr_heap - = mapSt (\{bp_expr} -> weightedRefCountInPatternExpr rci_main_dcl_module_n rci bp_expr) patterns ([], collected_imports, var_heap, expr_heap) - weighted_ref_count_in_case_patterns rci=:{rci_main_dcl_module_n} (DynamicPatterns patterns) collected_imports var_heap expr_heap - = mapSt (\{dp_rhs} -> weightedRefCountInPatternExpr rci_main_dcl_module_n rci dp_rhs) patterns ([], collected_imports, var_heap, expr_heap) + weighted_ref_count_in_case_patterns rci (BasicPatterns type patterns) collected_imports var_heap expr_heap + = mapSt (\{bp_expr} -> weightedRefCountInPatternExpr rci bp_expr) patterns ([], collected_imports, var_heap, expr_heap) + weighted_ref_count_in_case_patterns rci (DynamicPatterns patterns) collected_imports var_heap expr_heap + = mapSt (\{dp_rhs} -> weightedRefCountInPatternExpr rci dp_rhs) patterns ([], collected_imports, var_heap, expr_heap) weightedRefCountOfCase rci=:{rci_depth} this_case=:{case_expr, case_guards, case_default, case_info_ptr} (EI_CaseTypeAndRefCounts case_type {rcc_all_variables}) rcs_info=:{ rcs_var_heap, rcs_expr_heap, rcs_imports } @@ -269,16 +274,16 @@ weightedRefCountOfCase rci=:{rci_depth} this_case=:{case_expr, case_guards, case instance weightedRefCount Selection where - weightedRefCount rci=:{rci_dcl_functions, rci_common_defs, rci_main_dcl_module_n} (ArraySelection {glob_module,glob_object={ds_index}} _ index_expr) rcs_info + weightedRefCount rci=:{rci_imported} (ArraySelection {glob_module,glob_object={ds_index}} _ index_expr) rcs_info # rcs_info = weightedRefCount rci index_expr rcs_info - = checkImportOfDclFunction rci_dcl_functions rci_common_defs rci_main_dcl_module_n glob_module ds_index rcs_info + = checkImportOfDclFunction rci_imported glob_module ds_index rcs_info weightedRefCount rci (DictionarySelection _ selectors _ index_expr) rcs_info # rcs_info = weightedRefCount rci index_expr rcs_info = weightedRefCount rci selectors rcs_info - weightedRefCount rci=:{rci_common_defs, rci_main_dcl_module_n} (RecordSelection selector _) rcs_info - = checkRecordSelector rci_common_defs rci_main_dcl_module_n selector rcs_info + weightedRefCount rci=:{rci_imported} (RecordSelection selector _) rcs_info + = checkRecordSelector rci_imported selector rcs_info -weightedRefCountInPatternExpr main_dcl_module_n rci=:{rci_depth} pattern_expr (previous_free_vars, collected_imports, var_heap, expr_heap) +weightedRefCountInPatternExpr rci=:{rci_depth} pattern_expr (previous_free_vars, collected_imports, var_heap, expr_heap) # {rcs_free_vars,rcs_var_heap,rcs_imports,rcs_expr_heap} = weightedRefCount rci pattern_expr { rcs_var_heap = var_heap, rcs_expr_heap = expr_heap, rcs_free_vars = [], rcs_imports = collected_imports} (free_vars_with_rc, rcs_var_heap) = mapSt get_ref_count rcs_free_vars rcs_var_heap @@ -315,16 +320,16 @@ where */ -checkImportOfDclFunction dcl_functions common_defs main_dcl_module_n mod_index fun_index rcs_info=:{rcs_imports, rcs_var_heap} +checkImportOfDclFunction {cii_main_dcl_module_n, cii_dcl_functions} mod_index fun_index rcs_info=:{rcs_imports, rcs_var_heap} // | mod_index <> cIclModIndex - | mod_index <> main_dcl_module_n - # {ft_type_ptr} = dcl_functions.[mod_index].[fun_index] + | mod_index <> cii_main_dcl_module_n + # {ft_type_ptr} = cii_dcl_functions.[mod_index].[fun_index] (rcs_imports, rcs_var_heap) = checkImportedSymbol (SK_Function {glob_module=mod_index,glob_object=fun_index}) ft_type_ptr (rcs_imports, rcs_var_heap) = { rcs_info & rcs_imports = rcs_imports, rcs_var_heap = rcs_var_heap } = rcs_info -checkRecordSelector common_defs main_dcl_module_n {glob_module, glob_object={ds_index}} rcs_info=:{rcs_imports,rcs_var_heap} - | glob_module <> main_dcl_module_n - # {com_selector_defs,com_cons_defs,com_type_defs} = common_defs.[glob_module] +checkRecordSelector {cii_main_dcl_module_n, cii_common_defs} {glob_module, glob_object={ds_index}} rcs_info=:{rcs_imports,rcs_var_heap} + | glob_module <> cii_main_dcl_module_n + # {com_selector_defs,com_cons_defs,com_type_defs} = cii_common_defs.[glob_module] {sd_type_index} = com_selector_defs.[ds_index] {td_rhs = RecordType {rt_constructor={ds_index=cons_index}, rt_fields}} = com_type_defs.[sd_type_index] {cons_type_ptr} = com_cons_defs.[cons_index] @@ -337,19 +342,19 @@ checkRecordSelector common_defs main_dcl_module_n {glob_module, glob_object={ds_ instance weightedRefCount App where - weightedRefCount rci=:{rci_dcl_functions, rci_common_defs, rci_main_dcl_module_n} {app_symb,app_args} rcs_info + weightedRefCount rci=:{rci_imported} {app_symb,app_args} rcs_info # rcs_info = weightedRefCount rci app_args rcs_info - = check_import rci_dcl_functions rci_common_defs rci_main_dcl_module_n app_symb rcs_info + = check_import rci_imported app_symb rcs_info where - check_import dcl_functions common_defs main_dcl_module_n {symb_kind=SK_Function {glob_module,glob_object}} rcs_info=:{rcs_imports, rcs_var_heap} - = checkImportOfDclFunction dcl_functions common_defs main_dcl_module_n glob_module glob_object rcs_info - check_import dcl_functions common_defs main_dcl_module_n {symb_name,symb_kind=symb_kind=:(SK_Constructor {glob_module,glob_object})} rcs_info=:{rcs_imports, rcs_var_heap} - | glob_module <> main_dcl_module_n - # {cons_type_ptr} = common_defs.[glob_module].com_cons_defs.[glob_object] + check_import cci {symb_kind=SK_Function {glob_module,glob_object}} rcs_info=:{rcs_imports, rcs_var_heap} + = checkImportOfDclFunction cci glob_module glob_object rcs_info + check_import cci=:{cii_dcl_functions, cii_common_defs, cii_main_dcl_module_n} {symb_name,symb_kind=symb_kind=:(SK_Constructor {glob_module,glob_object})} rcs_info=:{rcs_imports, rcs_var_heap} + | glob_module <> cii_main_dcl_module_n + # {cons_type_ptr} = cii_common_defs.[glob_module].com_cons_defs.[glob_object] (rcs_imports, rcs_var_heap) = checkImportedSymbol symb_kind cons_type_ptr (rcs_imports, rcs_var_heap) = { rcs_info & rcs_imports = rcs_imports, rcs_var_heap = rcs_var_heap } = rcs_info - check_import dcl_functions common_defs _ _ rcs_info + check_import _ _ rcs_info = rcs_info |