Commit 6ab1fed8 authored by John van Groningen's avatar John van Groningen

change order of functions in groups/components before type checking, move...

change order of functions in groups/components before type checking, move specified generic functions before instances, insert derived generic functions between generic functions and instances, derived generic functions have group numbers >=500000000 & <1000000000, instances >= 1000000000, this makes it posssible to call generic functions from instances (does not yet happen, to be added)
parent 680e7b98
......@@ -2867,7 +2867,7 @@ check_module2 mod_ident mod_modification_time mod_imported_objects mod_imports m
# (predef_symbols_for_transform, cs_predef_symbols) = get_predef_symbols_for_transform cs_predef_symbols
(groups, icl_functions, macro_defs, var_heap, expr_heap, cs_symbol_table, cs_error)
= partitionateAndLiftFunctions (icl_global_functions_ranges++icl_instances_ranges++icl_generic_ranges++icl_type_fun_ranges)
= partitionateAndLiftFunctions (icl_global_functions_ranges++icl_generic_ranges) (icl_instances_ranges++icl_type_fun_ranges)
main_dcl_module_n predef_symbols_for_transform icl_mod.icl_functions macro_defs
heaps.hp_var_heap heaps.hp_expression_heap cs_symbol_table cs_error
......
......@@ -95,7 +95,6 @@ FIELD_NewType_Mask:==8;
, gs_dcl_modules :: !*DclModules
, gs_td_infos :: !*TypeDefInfos
, gs_funs :: !*{#FunDef}
, gs_groups :: {!Group}
// non-unique, read only
, gs_predefs :: !PredefinedSymbolsData
, gs_main_module :: !Index
......@@ -150,18 +149,16 @@ convertGenerics main_dcl_module_n used_module_numbers modules groups funs td_inf
, gs_avarh = th_attrs
, gs_error = error
, gs_funs = funs
, gs_groups = groups
, gs_predefs = {psd_predefs_a=predefs,psd_generic_newtypes=generic_newtypes}
, gs_main_module = main_dcl_module_n
, gs_used_modules = used_module_numbers
}
# (dcl_macros, gs) = convert_generics dcl_macros gs
# (groups, dcl_macros, gs) = convert_generics groups dcl_macros gs
# { gs_modules = modules, gs_symtab, gs_dcl_modules = dcl_modules, gs_td_infos = td_infos,
gs_genh = hp_generic_heap, gs_varh = hp_var_heap, gs_tvarh = th_vars, gs_avarh = th_attrs,
gs_exprh = hp_expression_heap,
gs_error = error, gs_funs = funs, gs_groups = groups,
gs_exprh = hp_expression_heap, gs_error = error, gs_funs = funs,
gs_predefs = predefs, gs_main_module = main_dcl_module_n, gs_used_modules = used_module_numbers} = gs
#! hash_table = { hash_table & hte_symbol_heap = gs_symtab }
#! heaps =
......@@ -172,20 +169,29 @@ convertGenerics main_dcl_module_n used_module_numbers modules groups funs td_inf
}
= (modules, groups, funs, td_infos, heaps, hash_table, u_predefs, dcl_modules, dcl_macros, error)
where
convert_generics :: !*DclMacros !*GenericState -> (!*DclMacros, !*GenericState)
convert_generics dcl_macros gs
# (bimap_functions, gs) = buildGenericRepresentations gs
| not gs.gs_error.ea_ok = (dcl_macros, gs)
convert_generics :: !{!Group} !*DclMacros !*GenericState -> (!{!Group}, !*DclMacros, !*GenericState)
convert_generics groups dcl_macros gs
# (bimap_functions,new_groups,group_index,gs) = buildGenericRepresentations 500000000 gs
| not gs.gs_error.ea_ok
# (groups,gs_funs) = add_groups new_groups groups (group_index-500000000) gs.gs_funs
= (groups,dcl_macros, {gs & gs_funs=gs_funs})
# gs = buildClasses gs
| not gs.gs_error.ea_ok = (dcl_macros, gs)
| not gs.gs_error.ea_ok
# (groups,gs_funs) = add_groups new_groups groups (group_index-500000000) gs.gs_funs
= (groups,dcl_macros, {gs & gs_funs=gs_funs})
# (dcl_macros, gs) = convertGenericCases bimap_functions dcl_macros gs
| not gs.gs_error.ea_ok = (dcl_macros, gs)
# (new_groups, group_index, dcl_macros, gs) = convertGenericCases bimap_functions new_groups group_index dcl_macros gs
# (groups,gs_funs) = add_groups new_groups groups (group_index-500000000) gs.gs_funs
# gs & gs_funs=gs_funs
| not gs.gs_error.ea_ok
= (groups,dcl_macros, gs)
#! gs = convertGenericTypeContexts gs
= (dcl_macros, gs)
= (groups, dcl_macros, gs)
determine_generic_newtypes :: !{#PredefinedSymbol} !{#CommonDefs} -> Int
determine_generic_newtypes predefs_a modules_cd
......@@ -289,12 +295,35 @@ instance_has_derived_member member_i ins_members gs_funs
= instance_has_derived_member (member_i+1) ins_members gs_funs
= False
add_groups :: ![Group] !{!Group} !Int !*{#FunDef} -> (!{!Group},!*{#FunDef})
add_groups new_groups gs_groups n_new_groups gs_funs
| n_new_groups==0
= (gs_groups,gs_funs)
# groups = createArray (size gs_groups+n_new_groups) {group_members=[]}
#! insert_group_i = find_first_group_with_index_ge_1000000000 0 gs_groups gs_funs
# groups & [i] = gs_groups.[i] \\ i<-[0..insert_group_i-1]
# groups = copy_new_groups new_groups (insert_group_i+n_new_groups-1) groups
# groups & [i+n_new_groups] = gs_groups.[i] \\ i<-[insert_group_i..size gs_groups-1]
= (groups,gs_funs)
where
find_first_group_with_index_ge_1000000000 :: !Int !{!Group} !{#FunDef} -> Int
find_first_group_with_index_ge_1000000000 i groups funs
| i<size groups
# [fun_i:_] = groups.[i].group_members
| funs.[fun_i].fun_info.fi_group_index>=1000000000
= i
= find_first_group_with_index_ge_1000000000 (i+1) groups funs
= i
copy_new_groups :: [Group] !Int !*{!Group} -> *{!Group}
copy_new_groups [g:gs] group_i groups = copy_new_groups gs (group_i-1) {groups & [group_i]=g}
copy_new_groups [] group_i groups = groups
// generic representation is built for each type argument of
// generic cases of the current module
buildGenericRepresentations :: !*GenericState -> (!BimapFunctions,!*GenericState)
buildGenericRepresentations gs=:{gs_main_module, gs_modules, gs_funs, gs_groups}
buildGenericRepresentations :: !Int !*GenericState -> (!BimapFunctions,![Group],!Int,!*GenericState)
buildGenericRepresentations group_index gs=:{gs_main_module, gs_modules, gs_funs}
#! size_funs = size gs_funs
#! size_groups = size gs_groups
#! ({com_gencase_defs,com_instance_defs}, gs) = gs!gs_modules.[gs_main_module]
# undefined_function_and_ident = {fii_index = -1,fii_ident = undef}
......@@ -304,18 +333,16 @@ buildGenericRepresentations gs=:{gs_main_module, gs_modules, gs_funs, gs_groups}
bimap_to_function = undefined_function_and_ident,
bimap_from_function = undefined_function_and_ident
}
funs_and_groups = {fg_fun_index=size_funs, fg_group_index=size_groups, fg_funs=[], fg_groups=[],fg_bimap_functions=bimap_functions}
funs_and_groups = {fg_fun_index=size_funs, fg_group_index=group_index, fg_funs=[], fg_groups=[],fg_bimap_functions=bimap_functions}
#! (funs_and_groups, gs)
= foldArraySt build_generic_representation com_gencase_defs (funs_and_groups, gs)
# (funs_and_groups, gs) = build_generic_representations_for_derived_instances 0 com_instance_defs funs_and_groups gs
# {fg_funs=new_funs,fg_groups=new_groups,fg_bimap_functions} = funs_and_groups
# {gs_funs, gs_groups} = gs
#! gs_funs = arrayPlusRevList gs_funs new_funs
#! gs_groups = arrayPlusRevList gs_groups new_groups
# {fg_funs=new_funs,fg_groups=new_groups,fg_bimap_functions,fg_group_index} = funs_and_groups
# gs & gs_funs = arrayPlusRevList gs.gs_funs new_funs
= (fg_bimap_functions, {gs & gs_funs = gs_funs, gs_groups = gs_groups})
= (fg_bimap_functions,new_groups,fg_group_index,gs)
where
build_generic_representation
{gc_type_cons=TypeConsSymb {type_index={glob_module,glob_object}, type_ident},gc_gcf,gc_pos}
......@@ -2156,9 +2183,9 @@ add_instance_calls_to_GenTypeStruct GTSUnit member_symb_ident
add_instance_calls_to_GenTypeStruct _ member_symb_ident
= GTSMemberCall member_symb_ident
convertGenericCases :: !BimapFunctions !*DclMacros !*GenericState -> (!*DclMacros, !*GenericState)
convertGenericCases bimap_functions dcl_macros
gs=:{gs_main_module, gs_used_modules, gs_predefs, gs_funs, gs_groups, gs_modules, gs_dcl_modules, gs_td_infos,
convertGenericCases :: !BimapFunctions ![Group] !Int !*DclMacros !*GenericState -> (![Group], !Int, !*DclMacros, !*GenericState)
convertGenericCases bimap_functions new_groups group_index dcl_macros
gs=:{gs_main_module, gs_used_modules, gs_predefs, gs_funs, gs_modules, gs_dcl_modules, gs_td_infos,
gs_avarh, gs_tvarh, gs_varh, gs_genh, gs_exprh, gs_symtab, gs_error}
# heaps =
......@@ -2169,8 +2196,7 @@ convertGenericCases bimap_functions dcl_macros
}
#! (first_fun_index, gs_funs) = usize gs_funs
#! first_group_index = size gs_groups
#! fun_info = {fg_fun_index=first_fun_index, fg_group_index=first_group_index, fg_funs=[], fg_groups=[], fg_bimap_functions=bimap_functions}
#! fun_info = {fg_fun_index=first_fun_index, fg_group_index=group_index, fg_funs=[], fg_groups=new_groups, fg_bimap_functions=bimap_functions}
#! (main_common_defs, gs_modules) = gs_modules ! [gs_main_module]
#! main_module_instances = main_common_defs.com_instance_defs
......@@ -2191,9 +2217,8 @@ convertGenericCases bimap_functions dcl_macros
#! (gs_modules, gs_dcl_modules, (fun_info, instance_info, heaps, gs_error))
= build_shorthand_instances_in_modules 0 gs_modules gs_dcl_modules (fun_info, instance_info, heaps, gs_error)
#! {fg_fun_index, fg_funs=new_funs, fg_groups=new_groups} = fun_info
#! {fg_fun_index, fg_funs=new_funs, fg_groups=new_groups,fg_group_index} = fun_info
#! gs_funs = arrayPlusRevList gs_funs new_funs
#! gs_groups = arrayPlusRevList gs_groups new_groups
#! (instance_index, new_instances) = instance_info
#! com_instance_defs = arrayPlusRevList main_module_instances new_instances
......@@ -2202,10 +2227,10 @@ convertGenericCases bimap_functions dcl_macros
#! gs_modules = {gs_modules & [gs_main_module] = main_common_defs}
# {hp_expression_heap, hp_var_heap, hp_generic_heap, hp_type_heaps={th_vars, th_attrs}} = heaps
# gs & gs_modules = gs_modules, gs_dcl_modules = gs_dcl_modules, gs_td_infos = gs_td_infos, gs_funs = gs_funs, gs_groups = gs_groups,
# gs & gs_modules = gs_modules, gs_dcl_modules = gs_dcl_modules, gs_td_infos = gs_td_infos, gs_funs = gs_funs,
gs_avarh = th_attrs, gs_tvarh = th_vars, gs_varh = hp_var_heap, gs_genh = hp_generic_heap, gs_exprh = hp_expression_heap,
gs_error = gs_error, gs_symtab = gs_symtab
= (dcl_macros, gs)
= (new_groups, fg_group_index, dcl_macros, gs)
where
build_exported_main_instances_in_modules :: !Index
!*{#CommonDefs} !*{#DclModule} !(!(!Index, ![ClassInstance]), !*Heaps, !*ErrorAdmin)
......
......@@ -10,8 +10,9 @@ partitionateDclMacros :: !IndexRange !Index !PredefSymbolsForTransform !*{#*{#Fu
partitionateIclMacros :: !IndexRange !Index !PredefSymbolsForTransform !*{#FunDef} !*{#*{#FunDef}} !*VarHeap !*ExpressionHeap !*SymbolTable !*ErrorAdmin
-> (!*{#FunDef},!*{#*{#FunDef}},!*VarHeap,!*ExpressionHeap,!*SymbolTable,!*ErrorAdmin )
partitionateAndLiftFunctions :: ![IndexRange] !Index !PredefSymbolsForTransform !*{#FunDef} !*{#*{#FunDef}} !*VarHeap !*ExpressionHeap !*SymbolTable !*ErrorAdmin
-> (!*{!Group}, !*{#FunDef},!*{#*{#FunDef}},!*VarHeap,!*ExpressionHeap,!*SymbolTable,!*ErrorAdmin)
partitionateAndLiftFunctions :: ![IndexRange] ![IndexRange] !Index !PredefSymbolsForTransform
!*{#FunDef} !*{#*{#FunDef}} !*VarHeap !*ExpressionHeap !*SymbolTable !*ErrorAdmin
-> (!*{!Group},!*{#FunDef},!*{#*{#FunDef}},!*VarHeap,!*ExpressionHeap,!*SymbolTable,!*ErrorAdmin)
:: UnexpandedDclMacros:==[(Int,Int,FunDef)]
......
......@@ -1218,22 +1218,31 @@ combine_consecutive_ranges [range]
combine_consecutive_ranges []
= [!!]
partitionateAndLiftFunctions :: ![IndexRange] !Index !PredefSymbolsForTransform !*{#FunDef} !*{#*{#FunDef}} !*VarHeap !*ExpressionHeap !*SymbolTable !*ErrorAdmin
-> (!*{!Group}, !*{#FunDef},!*{#*{#FunDef}},!*VarHeap,!*ExpressionHeap,!*SymbolTable,!*ErrorAdmin)
partitionateAndLiftFunctions ranges main_dcl_module_n predef_symbols_for_transform fun_defs macro_defs var_heap symbol_heap symbol_table error
# ranges = [range\\range<-ranges | range.ir_from<>range.ir_to]
# combined_ranges = combine_consecutive_ranges (sortBy (\ {ir_from=f1} {ir_from=f2} = f1<f2) ranges)
#! max_fun_nr = cMAXINT
# partitioning_info = { ps_var_heap = var_heap, ps_symbol_heap = symbol_heap, ps_symbol_table = symbol_table, ps_fun_defs=fun_defs, ps_macro_defs=macro_defs,
partitionateAndLiftFunctions :: ![IndexRange] ![IndexRange] !Index !PredefSymbolsForTransform
!*{#FunDef} !*{#*{#FunDef}} !*VarHeap !*ExpressionHeap !*SymbolTable !*ErrorAdmin
-> (!*{!Group},!*{#FunDef},!*{#*{#FunDef}},!*VarHeap,!*ExpressionHeap,!*SymbolTable,!*ErrorAdmin)
partitionateAndLiftFunctions ranges1 ranges2 main_dcl_module_n predef_symbols_for_transform fun_defs macro_defs var_heap symbol_heap symbol_table error
# ranges1 = remove_empty_ranges ranges1
ranges2 = remove_empty_ranges ranges2
combined_ranges = combine_consecutive_ranges (sortBy (\ {ir_from=f1} {ir_from=f2} = f1<f2) (ranges1++ranges2))
max_fun_nr = cMAXINT
partitioning_info = { ps_var_heap = var_heap, ps_symbol_heap = symbol_heap, ps_symbol_table = symbol_table, ps_fun_defs=fun_defs, ps_macro_defs=macro_defs,
ps_error = error, ps_deps = [], ps_next_num = 0, ps_next_group = 0, ps_groups = [],
ps_unexpanded_dcl_macros=[] }
{ps_groups, ps_symbol_table, ps_var_heap, ps_symbol_heap, ps_fun_defs, ps_macro_defs, ps_error,ps_unexpanded_dcl_macros}
= foldSt (partitionate_functions main_dcl_module_n max_fun_nr combined_ranges) ranges partitioning_info
# (reversed_ps_groups,fun_defs) = remove_macros_from_groups_and_reverse ps_groups ps_fun_defs []
# groups = { {group_members = group} \\ group <- reversed_ps_groups }
# macro_defs = restore_unexpanded_dcl_macros ps_unexpanded_dcl_macros ps_macro_defs
partitioning_info = partitionate_functions_in_ranges main_dcl_module_n max_fun_nr combined_ranges ranges1 partitioning_info
partitioning_info & ps_next_group = 1000000000
partitioning_info = partitionate_functions_in_ranges main_dcl_module_n max_fun_nr combined_ranges ranges2 partitioning_info
{ps_groups,ps_symbol_table,ps_var_heap,ps_symbol_heap,ps_fun_defs,ps_macro_defs,ps_error,ps_unexpanded_dcl_macros} = partitioning_info
(reversed_ps_groups,fun_defs) = remove_macros_from_groups_and_reverse ps_groups ps_fun_defs []
groups = {{group_members = group} \\ group <- reversed_ps_groups}
macro_defs = restore_unexpanded_dcl_macros ps_unexpanded_dcl_macros ps_macro_defs
= (groups, fun_defs, macro_defs, ps_var_heap, ps_symbol_heap, ps_symbol_table, ps_error)
where
remove_empty_ranges ranges = [range\\range<-ranges | range.ir_from<>range.ir_to]
partitionate_functions_in_ranges main_dcl_module_n max_fun_nr combined_ranges ranges partitioning_info
= foldSt (partitionate_functions main_dcl_module_n max_fun_nr combined_ranges) ranges partitioning_info
partitionate_functions mod_index max_fun_nr combined_ranges {ir_from,ir_to} ps
= iFoldSt (partitionate_global_function mod_index max_fun_nr combined_ranges) ir_from ir_to ps
......@@ -1475,9 +1484,9 @@ where
remove_macros_from_groups_and_reverse :: ![[FunctionOrMacroIndex]] !*{#FunDef} [[Int]] -> (![[Int]],!*{#FunDef})
remove_macros_from_groups_and_reverse [group:groups] fun_defs result_groups
# (group,fun_defs) = remove_macros_from_group group fun_defs
= case group of
[] -> remove_macros_from_groups_and_reverse groups fun_defs result_groups
_ -> remove_macros_from_groups_and_reverse groups fun_defs [group:result_groups]
| group=:[]
= remove_macros_from_groups_and_reverse groups fun_defs result_groups
= remove_macros_from_groups_and_reverse groups fun_defs [group:result_groups]
where
remove_macros_from_group [FunctionOrIclMacroIndex fun:funs] fun_defs
# (funs,fun_defs)=remove_macros_from_group funs fun_defs
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment