Commit b6a0c985 authored by Sjaak Smetsers's avatar Sjaak Smetsers
Browse files

Bug fix: Scopes in dynamics

parent 3c7f7399
......@@ -905,7 +905,7 @@ checkFunction fun_def=:{fun_symb,fun_pos,fun_body,fun_type,fun_kind} mod_index f
= check_function_type fun_type mod_index (fun_kind == FK_Caf) ef_type_defs ef_class_defs ef_modules hp_var_heap hp_type_heaps cs
e_info = { e_info & ef_type_defs = ef_type_defs, ef_class_defs = ef_class_defs, ef_modules = ef_modules }
e_state = { es_var_heap = hp_var_heap, es_expr_heap = hp_expression_heap, es_type_heaps = hp_type_heaps,
es_dynamics = [], es_calls = [], es_fun_defs = fun_defs, es_dynamic_expr_count = 0}
es_dynamics = [], es_calls = [], es_fun_defs = fun_defs }
e_input = { ei_expr_level = inc def_level, ei_fun_index = fun_index, ei_fun_level = inc def_level, ei_mod_index = mod_index, ei_local_functions_index_offset=local_functions_index_offset }
(fun_body, free_vars, e_state, e_info, cs) = checkFunctionBodies fun_body function_ident_for_errors e_input e_state e_info cs
......
......@@ -2,14 +2,15 @@ definition module checkFunctionBodies
import syntax, checksupport
:: Dynamics :== [ExprInfoPtr]
:: ExpressionState =
{ es_expr_heap :: !.ExpressionHeap
, es_var_heap :: !.VarHeap
, es_type_heaps :: !.TypeHeaps
, es_calls :: ![FunCall]
, es_dynamics :: ![ExprInfoPtr]
, es_fun_defs :: !.{# FunDef}
, es_dynamic_expr_count :: !Int // used to give each dynamic expr an unique id
, es_var_heap :: !.VarHeap
, es_type_heaps :: !.TypeHeaps
, es_calls :: ![FunCall]
, es_dynamics :: !Dynamics
, es_fun_defs :: !.{# FunDef}
}
:: ExpressionInput =
......@@ -21,4 +22,4 @@ import syntax, checksupport
}
checkFunctionBodies :: !FunctionBody !Ident !.ExpressionInput !*ExpressionState !*ExpressionInfo !*CheckState
-> (FunctionBody,[FreeVar],!.ExpressionState,.ExpressionInfo,!.CheckState);
-> (!FunctionBody, ![FreeVar], !*ExpressionState, !*ExpressionInfo, !*CheckState)
......@@ -10,14 +10,15 @@ cIsNotInExpressionList :== False
cEndWithUpdate :== True
cEndWithSelection :== False
:: Dynamics :== [ExprInfoPtr]
:: ExpressionState =
{ es_expr_heap :: !.ExpressionHeap
, es_var_heap :: !.VarHeap
, es_type_heaps :: !.TypeHeaps
, es_calls :: ![FunCall]
, es_dynamics :: ![ExprInfoPtr]
, es_fun_defs :: !.{# FunDef}
, es_dynamic_expr_count :: !Int // used to give each dynamic expr an unique id
, es_var_heap :: !.VarHeap
, es_type_heaps :: !.TypeHeaps
, es_calls :: ![FunCall]
, es_dynamics :: !Dynamics
, es_fun_defs :: !.{# FunDef}
}
:: ExpressionInput =
......@@ -120,7 +121,8 @@ make_case_guards cons_symbol type_symbol alg_patterns expr_heap cs
= (AlgebraicPatterns type_symbol alg_patterns,expr_heap,cs)
= (AlgebraicPatterns type_symbol alg_patterns,expr_heap,cs)
checkFunctionBodies :: !FunctionBody !Ident !.ExpressionInput !*ExpressionState !*ExpressionInfo !*CheckState -> (FunctionBody,[FreeVar],!.ExpressionState,.ExpressionInfo,!.CheckState);
checkFunctionBodies :: !FunctionBody !Ident !.ExpressionInput !*ExpressionState !*ExpressionInfo !*CheckState
-> (!FunctionBody, ![FreeVar], !*ExpressionState, !*ExpressionInfo, !*CheckState)
checkFunctionBodies (ParsedBody [{pb_args,pb_rhs={rhs_alts,rhs_locals}, pb_position} : bodies]) function_ident_for_errors e_input=:{ei_expr_level,ei_mod_index}
e_state=:{es_var_heap, es_fun_defs} e_info cs
# (aux_patterns, (var_env, array_patterns), {ps_var_heap,ps_fun_defs}, e_info, cs)
......@@ -129,9 +131,7 @@ checkFunctionBodies (ParsedBody [{pb_args,pb_rhs={rhs_alts,rhs_locals}, pb_posit
(rhs_expr, free_vars, e_state, e_info, cs)
= checkRhs [] rhs_alts rhs_locals e_input { e_state & es_var_heap = ps_var_heap, es_fun_defs = ps_fun_defs } e_info cs
(dynamics_in_rhs, e_state)
= e_state!es_dynamics
(expr_with_array_selections, free_vars, e_state=:{es_var_heap}, e_info, cs)
(expr_with_array_selections, free_vars, e_state=:{es_var_heap,es_dynamics=dynamics_in_rhs}, e_info, cs)
= addArraySelections array_patterns rhs_expr free_vars e_input e_state e_info cs
cs_symbol_table = removeLocalIdentsFromSymbolTable ei_expr_level var_env cs.cs_symbol_table
(cb_args, es_var_heap) = mapSt determine_function_arg aux_patterns es_var_heap
......@@ -614,7 +614,8 @@ checkExpression free_vars (PE_Let strict let_locals expr) e_input=:{ei_expr_leve
checkExpression free_vars (PE_Case case_ident expr alts) e_input e_state e_info cs
# (pattern_expr, free_vars, e_state, e_info, cs) = checkExpression free_vars expr e_input e_state e_info cs
(guards, _, pattern_variables, defaul, free_vars, e_state, e_info, cs) = check_guarded_expressions free_vars alts [] case_ident.id_name e_input e_state e_info cs
(guards, _, pattern_variables, defaul, free_vars, e_state, e_info, cs)
= check_guarded_expressions free_vars alts [] case_ident.id_name e_input e_state e_info cs
(pattern_expr, binds, es_expr_heap) = bind_pattern_variables pattern_variables pattern_expr e_state.es_expr_heap
(case_expr, es_var_heap, es_expr_heap, cs_error) = build_and_share_case guards defaul pattern_expr case_ident True e_state.es_var_heap es_expr_heap cs.cs_error
cs = {cs & cs_error = cs_error}
......@@ -632,25 +633,25 @@ where
= check_guarded_expression free_vars g gs pattern_scheme pattern_variables defaul case_name e_input e_state e_info cs
check_guarded_expression free_vars {calt_pattern,calt_rhs={rhs_alts,rhs_locals}} patterns pattern_scheme pattern_variables defaul case_name
e_input=:{ei_expr_level,ei_mod_index} e_state=:{es_fun_defs,es_var_heap} e_info cs
e_input=:{ei_expr_level,ei_mod_index} e_state=:{es_fun_defs,es_var_heap,es_dynamics=outer_dynamics} e_info cs
# (pattern, (var_env, array_patterns), {ps_fun_defs,ps_var_heap}, e_info, cs)
= checkPattern calt_pattern No { pi_def_level = ei_expr_level, pi_mod_index = ei_mod_index, pi_is_node_pattern = False } ([], [])
{ps_var_heap = es_var_heap,ps_fun_defs = es_fun_defs} e_info cs
e_state = { e_state & es_var_heap = ps_var_heap,es_fun_defs = ps_fun_defs }
e_state = { e_state & es_var_heap = ps_var_heap, es_fun_defs = ps_fun_defs, es_dynamics = [] }
(rhs_expr, free_vars, e_state, e_info, cs)
= checkRhs free_vars rhs_alts rhs_locals e_input e_state e_info cs
(expr_with_array_selections, free_vars, e_state=:{es_dynamics,es_expr_heap,es_var_heap}, e_info, cs)
(expr_with_array_selections, free_vars, e_state=:{es_dynamics = dynamics_in_rhs, es_expr_heap, es_var_heap}, e_info, cs)
= addArraySelections array_patterns rhs_expr free_vars e_input e_state e_info cs
cs_symbol_table = removeLocalIdentsFromSymbolTable ei_expr_level var_env cs.cs_symbol_table
(guarded_expr, pattern_scheme, pattern_variables, defaul, es_var_heap, es_expr_heap, dynamics_in_patterns, cs)
= transform_pattern pattern patterns pattern_scheme pattern_variables defaul expr_with_array_selections case_name
es_var_heap es_expr_heap es_dynamics { cs & cs_symbol_table = cs_symbol_table }
es_var_heap es_expr_heap dynamics_in_rhs { cs & cs_symbol_table = cs_symbol_table }
= (guarded_expr, pattern_scheme, pattern_variables, defaul, free_vars,
{ e_state & es_var_heap = es_var_heap, es_expr_heap = es_expr_heap, es_dynamics = dynamics_in_patterns },
{ e_state & es_var_heap = es_var_heap, es_expr_heap = es_expr_heap, es_dynamics = dynamics_in_patterns ++ outer_dynamics },
e_info, cs)
transform_pattern :: !AuxiliaryPattern !CasePatterns !CasePatterns !(Env Ident VarInfoPtr) !(Optional (!Optional FreeVar, !Expression)) !Expression
!String !*VarHeap !*ExpressionHeap ![DynamicPtr] !*CheckState
!String !*VarHeap !*ExpressionHeap !Dynamics !*CheckState
-> (!CasePatterns, !CasePatterns, !Env Ident VarInfoPtr, !Optional (!Optional FreeVar,!Expression), !*VarHeap, !*ExpressionHeap, ![DynamicPtr], !*CheckState)
transform_pattern (AP_Algebraic cons_symbol type_index args opt_var) patterns pattern_scheme pattern_variables defaul result_expr _ var_store expr_heap opt_dynamics cs
# (var_args, result_expr, _, var_store, expr_heap, opt_dynamics, cs) = convertSubPatterns args result_expr NoPos var_store expr_heap opt_dynamics cs
......@@ -1089,14 +1090,12 @@ where
get_field_var _
= ({ id_name = "** ERRONEOUS **", id_info = nilPtr }, nilPtr)
// MV ...
checkExpression free_vars (PE_Dynamic expr opt_type) e_input e_state=:{es_expr_heap,es_dynamics, es_dynamic_expr_count } e_info cs=:{cs_x}
# (dyn_info_ptr, es_expr_heap) = newPtr (EI_Dynamic opt_type es_dynamic_expr_count) es_expr_heap
(dyn_expr, free_vars, e_state, e_info, cs) = checkExpression free_vars expr e_input
{e_state & es_dynamics = [dyn_info_ptr : es_dynamics], es_expr_heap = es_expr_heap, es_dynamic_expr_count = inc es_dynamic_expr_count} e_info cs
= (DynamicExpr { dyn_expr = dyn_expr, dyn_opt_type = opt_type, dyn_info_ptr = dyn_info_ptr, dyn_type_code = TCE_Empty /*, dyn_uni_vars = [] */ },
free_vars, e_state, e_info, { cs & cs_x.x_needed_modules = cs_x.x_needed_modules bitor cNeedStdDynamic })
// ... MV
checkExpression free_vars (PE_Dynamic expr opt_type) e_input e_state=:{es_dynamics=outer_dynamics} e_info cs=:{cs_x}
# (dyn_expr, free_vars, e_state=:{es_dynamics, es_expr_heap}, e_info, cs) = checkExpression free_vars expr e_input {e_state & es_dynamics = []} e_info cs
(dyn_info_ptr, es_expr_heap) = newPtr (EI_UnmarkedDynamic opt_type es_dynamics) es_expr_heap
= (DynamicExpr { dyn_expr = dyn_expr, dyn_opt_type = opt_type, dyn_info_ptr = dyn_info_ptr, dyn_type_code = TCE_Empty},
free_vars, { e_state & es_expr_heap = es_expr_heap, es_dynamics = [dyn_info_ptr : outer_dynamics]},
e_info, { cs & cs_x.x_needed_modules = cs_x.x_needed_modules bitor cNeedStdDynamic })
checkExpression free_vars (PE_Basic basic_value) e_input e_state e_info cs
= (BasicExpr basic_value, free_vars, e_state, e_info, cs)
......
......@@ -877,12 +877,12 @@ where
remove_global_type_variables_in_dynamic dyn_info_ptr (expr_heap, symbol_table)
# (dyn_info, expr_heap) = readPtr dyn_info_ptr expr_heap
= case dyn_info of
EI_Dynamic (Yes {dt_global_vars}) _
-> (expr_heap, remove_global_type_variables dt_global_vars symbol_table)
EI_Dynamic No _
-> (expr_heap, symbol_table)
EI_DynamicTypeWithVars loc_type_vars {dt_global_vars} loc_dynamics
-> remove_global_type_variables_in_dynamics loc_dynamics (expr_heap, remove_global_type_variables dt_global_vars symbol_table)
EI_UnmarkedDynamic (Yes {dt_global_vars}) local_dynamics
-> remove_global_type_variables_in_dynamics local_dynamics (expr_heap, remove_global_type_variables dt_global_vars symbol_table)
EI_UnmarkedDynamic No local_dynamics
-> remove_global_type_variables_in_dynamics local_dynamics (expr_heap, symbol_table)
EI_DynamicTypeWithVars loc_type_vars {dt_global_vars} local_dynamics
-> remove_global_type_variables_in_dynamics local_dynamics (expr_heap, remove_global_type_variables dt_global_vars symbol_table)
remove_global_type_variables global_vars symbol_table
......@@ -916,10 +916,10 @@ where
check_global_type_variables_in_dynamic dyn_info_ptr (expr_heap, cs)
# (dyn_info, expr_heap) = readPtr dyn_info_ptr expr_heap
= case dyn_info of
EI_Dynamic (Yes {dt_global_vars}) _
-> (expr_heap, check_global_type_variables dt_global_vars cs)
EI_Dynamic No _
-> (expr_heap, cs)
EI_UnmarkedDynamic (Yes {dt_global_vars}) loc_dynamics
-> check_global_type_variables_in_dynamics loc_dynamics (expr_heap, check_global_type_variables dt_global_vars cs)
EI_UnmarkedDynamic No loc_dynamics
-> check_global_type_variables_in_dynamics loc_dynamics (expr_heap, cs)
EI_DynamicTypeWithVars loc_type_vars {dt_global_vars} loc_dynamics
-> check_global_type_variables_in_dynamics loc_dynamics (expr_heap, check_global_type_variables dt_global_vars cs)
......@@ -940,18 +940,19 @@ where
check_dynamic mod_index scope dyn_info_ptr (type_defs, modules, type_heaps, expr_heap, cs)
# (dyn_info, expr_heap) = readPtr dyn_info_ptr expr_heap
= case dyn_info of
EI_Dynamic opt_type ei_dynamic_id
EI_UnmarkedDynamic opt_type loc_dynamics
-> case opt_type of
Yes dyn_type
# (dyn_type, loc_type_vars, type_defs, modules, type_heaps, cs) = check_dynamic_type mod_index scope dyn_type type_defs modules type_heaps cs
| isEmpty loc_type_vars
-> (type_defs, modules, type_heaps, expr_heap <:= (dyn_info_ptr, EI_Dynamic (Yes dyn_type) ei_dynamic_id), cs)
# expr_heap = expr_heap <:= (dyn_info_ptr, EI_UnmarkedDynamic (Yes dyn_type) loc_dynamics)
-> check_local_dynamics mod_index scope loc_dynamics type_defs modules type_heaps expr_heap cs
# cs_symbol_table = removeVariablesFromSymbolTable scope loc_type_vars cs.cs_symbol_table
cs_error = checkError loc_type_vars "type variable(s) not defined" cs.cs_error
-> (type_defs, modules, type_heaps, expr_heap <:= (dyn_info_ptr, EI_Dynamic (Yes dyn_type) ei_dynamic_id),
-> (type_defs, modules, type_heaps, expr_heap <:= (dyn_info_ptr, EI_UnmarkedDynamic (Yes dyn_type) loc_dynamics),
{ cs & cs_error = cs_error, cs_symbol_table = cs_symbol_table })
No
-> (type_defs, modules, type_heaps, expr_heap, cs)
-> check_local_dynamics mod_index scope loc_dynamics type_defs modules type_heaps expr_heap cs
EI_DynamicType dyn_type loc_dynamics
# (dyn_type, loc_type_vars, type_defs, modules, type_heaps, cs) = check_dynamic_type mod_index scope dyn_type type_defs modules type_heaps cs
(type_defs, modules, type_heaps, expr_heap, cs) = check_local_dynamics mod_index scope loc_dynamics type_defs modules type_heaps expr_heap cs
......
......@@ -626,7 +626,7 @@ instance check_completeness ConsDef
instance check_completeness DynamicPattern where
check_completeness { dp_rhs, dp_type } cci ccs
= check_completeness dp_rhs cci
(check_completeness_of_dyn_expr_ptr dp_type cci ccs)
(check_completeness_of_dyn_expr_ptr cci dp_type ccs)
instance check_completeness DynamicExpr where
check_completeness { dyn_expr, dyn_opt_type } cci ccs
......@@ -689,7 +689,7 @@ instance check_completeness FunDef where
check_completeness {fun_type, fun_body, fun_info} cci ccs
= ( (check_completeness fun_type cci)
o (check_completeness fun_body cci)
o (foldSt (flipM check_completeness_of_dyn_expr_ptr cci) fun_info.fi_dynamics)
o (check_completeness_of_dyn_expr_ptrs cci fun_info.fi_dynamics)
) ccs
instance check_completeness FunType where
......@@ -847,24 +847,31 @@ instance check_completeness [a] | check_completeness a
= check_completeness h cci
(check_completeness t cci ccs)
check_completeness_of_dyn_expr_ptr :: !ExprInfoPtr !CheckCompletenessInputBox !*CheckCompletenessStateBox
check_completeness_of_dyn_expr_ptr :: !CheckCompletenessInputBox !ExprInfoPtr !*CheckCompletenessStateBox
-> *CheckCompletenessStateBox
check_completeness_of_dyn_expr_ptr dyn_expr_ptr cci ccs=:{box_ccs=box_ccs=:{ccs_expr_heap}}
check_completeness_of_dyn_expr_ptr cci dyn_expr_ptr ccs=:{box_ccs=box_ccs=:{ccs_expr_heap}}
#! (expr_info, ccs_expr_heap) = readPtr dyn_expr_ptr ccs_expr_heap
ccs = { ccs & box_ccs = { box_ccs & ccs_expr_heap = ccs_expr_heap }}
= case expr_info of
(EI_Dynamic No _)
-> ccs
(EI_Dynamic (Yes dynamic_type) _)
-> check_completeness dynamic_type cci ccs
(EI_UnmarkedDynamic No further_dynamic_ptrs)
-> (check_completeness_of_dyn_expr_ptrs cci further_dynamic_ptrs ccs)
(EI_UnmarkedDynamic (Yes dynamic_type) further_dynamic_ptrs)
-> check_completeness dynamic_type cci (check_completeness_of_dyn_expr_ptrs cci further_dynamic_ptrs ccs)
(EI_Dynamic No further_dynamic_ptrs)
-> (check_completeness_of_dyn_expr_ptrs cci further_dynamic_ptrs ccs)
(EI_Dynamic (Yes dynamic_type) further_dynamic_ptrs)
-> check_completeness dynamic_type cci (check_completeness_of_dyn_expr_ptrs cci further_dynamic_ptrs ccs)
(EI_DynamicType dynamic_type further_dynamic_ptrs)
-> check_completeness dynamic_type cci
(foldSt (flipM check_completeness_of_dyn_expr_ptr cci) further_dynamic_ptrs ccs)
-> check_completeness dynamic_type cci (check_completeness_of_dyn_expr_ptrs cci further_dynamic_ptrs ccs)
(EI_DynamicTypeWithVars _ dynamic_type further_dynamic_ptrs)
-> check_completeness dynamic_type cci
(foldSt (flipM check_completeness_of_dyn_expr_ptr cci) further_dynamic_ptrs ccs)
(check_completeness_of_dyn_expr_ptrs cci further_dynamic_ptrs ccs)
check_completeness_of_dyn_expr_ptrs :: !CheckCompletenessInputBox ![ExprInfoPtr] !*CheckCompletenessStateBox
-> *CheckCompletenessStateBox
check_completeness_of_dyn_expr_ptrs cci dynamic_ptrs ccs
= foldSt (check_completeness_of_dyn_expr_ptr cci) dynamic_ptrs ccs
flipM f a b :== f b a
// STE_Kinds just for comparision
ste_field =: STE_Field { id_name="", id_info=nilPtr }
......
......@@ -4118,7 +4118,6 @@ where
, cos_var_heap = hp_var_heap
, cos_symbol_heap = hp_expression_heap
, cos_predef_symbols_for_transform = { predef_alias_dummy=dummy_pds, predef_and=dummy_pds, predef_or=dummy_pds }
, cos_used_dynamics = {} //abort "error, please report to Martijn or Artem"
}
# (body_expr, fun_arg_vars, local_vars, {cos_symbol_heap, cos_var_heap}) =
determineVariablesAndRefCounts fun_arg_vars body_expr cs
......
......@@ -1128,7 +1128,7 @@ where
update_dynamic dyn_ptr (type_code_info, expr_heap, type_pattern_vars, var_heap, error)
# (dyn_info, expr_heap) = readPtr dyn_ptr expr_heap
= case dyn_info of
EI_TempDynamicType (Yes {dt_global_vars, dt_uni_vars, dt_type}) _ _ expr_ptr {symb_name}
EI_TempDynamicType (Yes {dt_global_vars, dt_uni_vars, dt_type}) loc_dynamics _ _ expr_ptr {symb_name}
# (expr_info, expr_heap) = readPtr expr_ptr expr_heap
-> case expr_info of
EI_TypeCodes type_codes
......@@ -1137,21 +1137,25 @@ where
(uni_vars, (type_var_heap, var_heap)) = newTypeVariables dt_uni_vars (type_var_heap, var_heap)
(type_code_expr, (type_code_info,var_heap,error)) = toTypeCodeExpression symb_name (add_universal_vars_to_type dt_uni_vars dt_type)
({ type_code_info & tci_type_var_heap = type_var_heap }, var_heap, error)
-> (type_code_info, expr_heap <:= (dyn_ptr, EI_TypeOfDynamic uni_vars type_code_expr), type_pattern_vars, var_heap, error)
expr_heap = expr_heap <:= (dyn_ptr, EI_TypeOfDynamic uni_vars type_code_expr)
-> convert_local_dynamics loc_dynamics (type_code_info, expr_heap, type_pattern_vars, var_heap, error)
EI_Empty
# (uni_vars, (type_var_heap, var_heap)) = newTypeVariables dt_uni_vars (type_code_info.tci_type_var_heap, var_heap)
(type_code_expr, (type_code_info,var_heap,error)) = toTypeCodeExpression symb_name (add_universal_vars_to_type dt_uni_vars dt_type)
({ type_code_info & tci_type_var_heap = type_var_heap }, var_heap, error)
-> (type_code_info, expr_heap <:= (dyn_ptr, EI_TypeOfDynamic uni_vars type_code_expr), type_pattern_vars, var_heap, error)
EI_TempDynamicType No _ _ expr_ptr {symb_name}
expr_heap = expr_heap <:= (dyn_ptr, EI_TypeOfDynamic uni_vars type_code_expr)
-> convert_local_dynamics loc_dynamics (type_code_info, expr_heap, type_pattern_vars, var_heap, error)
EI_TempDynamicType No loc_dynamics _ _ expr_ptr {symb_name}
# (expr_info, expr_heap) = readPtr expr_ptr expr_heap
-> case expr_info of
EI_TypeCode type_expr
# (type_expr, (var_heap, error)) = updateFreeVarsOfTCE symb_name type_expr (var_heap, error)
-> (type_code_info, expr_heap <:= (dyn_ptr, EI_TypeOfDynamic [] type_expr), type_pattern_vars, var_heap, error)
expr_heap = expr_heap <:= (dyn_ptr, EI_TypeOfDynamic [] type_expr)
-> convert_local_dynamics loc_dynamics (type_code_info, expr_heap, type_pattern_vars, var_heap, error)
EI_Selection selectors record_var _
# (_, var_info_ptr, var_heap, error) = getClassVariable symb_name record_var var_heap error
-> (type_code_info, expr_heap <:= (dyn_ptr, EI_TypeOfDynamic [] (convert_selectors selectors var_info_ptr)), type_pattern_vars, var_heap, error)
expr_heap = expr_heap <:= (dyn_ptr, EI_TypeOfDynamic [] (convert_selectors selectors var_info_ptr))
-> convert_local_dynamics loc_dynamics (type_code_info, expr_heap, type_pattern_vars, var_heap, error)
EI_TempDynamicPattern type_vars {dt_global_vars, dt_uni_vars, dt_type} loc_dynamics temp_local_vars _ _ expr_ptr {symb_name}
# (expr_info, expr_heap) = readPtr expr_ptr expr_heap
-> case expr_info of
......
......@@ -684,25 +684,22 @@ cNonRecursiveAppl :== False
| EI_Overloaded !OverloadedCall /* initial, set by the type checker */
| EI_Instance !(Global DefinedSymbol) ![Expression] /* intermedediate, used during resolving of overloading */
// | EI_Selection ![Selection] !BoundVar ![Expression] /* intermedediate, used during resolving of overloading */
| EI_Selection ![Selection] !VarInfoPtr ![Expression] /* intermedediate, used during resolving of overloading */
| EI_Context ![Expression] /* intermedediate, used during resolving of overloading */
/* For handling dynamics */
| EI_Dynamic !(Optional DynamicType) !Int
| EI_UnmarkedDynamic !(Optional DynamicType) ![DynamicPtr]
| EI_Dynamic !(Optional DynamicType) ![DynamicPtr]
| EI_DynamicType !DynamicType ![DynamicPtr]
// | EI_DynamicType !DynamicType !(Optional ExprInfoPtr)
/* Auxiliary, was EI_DynamicType before checking */
| EI_DynamicTypeWithVars ![TypeVar] !DynamicType ![DynamicPtr]
// | EI_DynamicTypeWithVars ![TypeVar] !DynamicType !(Optional ExprInfoPtr)
/* Auxiliary, used during type checking */
| EI_TempDynamicType !(Optional DynamicType) !AType ![TypeContext] !ExprInfoPtr !SymbIdent
// | EI_TempDynamicPattern ![TypeVar] !DynamicType !(Optional ExprInfoPtr) ![TempLocalVar] !AType ![TypeContext] !ExprInfoPtr !SymbIdent
| EI_TempDynamicType !(Optional DynamicType) ![DynamicPtr] !AType ![TypeContext] !ExprInfoPtr !SymbIdent
| EI_TempDynamicPattern ![TypeVar] !DynamicType ![DynamicPtr] ![TempLocalVar] !AType ![TypeContext] !ExprInfoPtr !SymbIdent
| EI_TypeOfDynamic ![VarInfoPtr] !TypeCodeExpression /* Final */
......
......@@ -674,7 +674,8 @@ cNotVarNumber :== -1
/* For handling dynamics */
| EI_Dynamic !(Optional DynamicType) !Int
| EI_UnmarkedDynamic !(Optional DynamicType) ![DynamicPtr]
| EI_Dynamic !(Optional DynamicType) ![DynamicPtr]
| EI_DynamicType !DynamicType ![DynamicPtr]
/* Auxiliary, was EI_DynamicType before checking */
......@@ -683,7 +684,7 @@ cNotVarNumber :== -1
/* Auxiliary, used during type checking */
| EI_TempDynamicType !(Optional DynamicType) !AType ![TypeContext] !ExprInfoPtr !SymbIdent
| EI_TempDynamicType !(Optional DynamicType) ![DynamicPtr] !AType ![TypeContext] !ExprInfoPtr !SymbIdent
| EI_TempDynamicPattern ![TypeVar] !DynamicType ![DynamicPtr] ![TempLocalVar] !AType ![TypeContext] !ExprInfoPtr !SymbIdent
| EI_TypeOfDynamic ![VarInfoPtr] !TypeCodeExpression /* Final */
......
......@@ -24,7 +24,6 @@ partitionateAndLiftFunctions :: ![IndexRange] !Index !PredefSymbolsForTransform
, cos_symbol_heap :: !.ExpressionHeap
, cos_error :: !.ErrorAdmin
, cos_predef_symbols_for_transform :: !PredefSymbolsForTransform
, cos_used_dynamics :: !.{#Bool}
}
determineVariablesAndRefCounts :: ![FreeVar] !Expression !*CollectState -> (!Expression , ![FreeVar], ![FreeVar], !*CollectState)
......
......@@ -1494,10 +1494,6 @@ where
expandMacrosInBody :: [.FunCall] CheckedBody ![ExprInfoPtr] PredefSymbolsForTransform *ExpandState -> ([FreeVar],Expression,[FreeVar],[FunCall],![ExprInfoPtr],.ExpandState);
expandMacrosInBody fi_calls {cb_args,cb_rhs} fi_dynamics predef_symbols_for_transform es=:{es_symbol_table,es_symbol_heap,es_fun_defs,es_macro_defs}
# (max_index,es_symbol_heap)
= determine_amount_of_dynamics 0 fi_dynamics es_symbol_heap
# cos_used_dynamics
= createArray (inc max_index) False // means not removed
# (prev_calls, fun_defs, macro_defs,es_symbol_table)
= addFunctionCallsToSymbolTable fi_calls es_fun_defs es_macro_defs es_symbol_table
([rhs:rhss], (all_calls, es) )
......@@ -1509,42 +1505,22 @@ expandMacrosInBody fi_calls {cb_args,cb_rhs} fi_dynamics predef_symbols_for_tran
(new_rhs, new_args, local_vars, {cos_error, cos_var_heap, cos_symbol_heap, cos_used_dynamics})
= determineVariablesAndRefCounts cb_args merged_rhs
{ cos_error = es_error, cos_var_heap = es_var_heap, cos_symbol_heap = es_symbol_heap,
cos_predef_symbols_for_transform = predef_symbols_for_transform, cos_used_dynamics = cos_used_dynamics }
# (changed,fi_dynamics,_,cos_symbol_heap)
= foldSt remove_fi_dynamic fi_dynamics (False,[],cos_used_dynamics,cos_symbol_heap)
= (new_args, new_rhs, local_vars, all_calls,fi_dynamics,
cos_predef_symbols_for_transform = predef_symbols_for_transform }
# (fi_dynamics, cos_symbol_heap)
= foldSt collect_used_dynmic fi_dynamics ([], cos_symbol_heap)
= (new_args, new_rhs, local_vars, all_calls, fi_dynamics,
{ es & es_error = cos_error, es_var_heap = cos_var_heap, es_symbol_heap = cos_symbol_heap, es_fun_defs=fun_defs, es_symbol_table = symbol_table })
// ---> ("expandMacrosInBody", (cb_args, ca_rhs, '\n'), ("merged_rhs", merged_rhs, '\n'), ("new_rhs", new_args, local_vars, (new_rhs, '\n')))
where
remove_fi_dynamic dyn_expr_ptr (changed,accu,cos_used_dynamics,cos_symbol_heap)
# (expr_info,cos_symbol_heap)
= readPtr dyn_expr_ptr cos_symbol_heap
| not (isEI_Dynamic expr_info)
= (changed,[dyn_expr_ptr:accu],cos_used_dynamics,cos_symbol_heap)
# (EI_Dynamic _ id)
= expr_info
| cos_used_dynamics.[id]
= (changed,[dyn_expr_ptr:accu],cos_used_dynamics,cos_symbol_heap)
// unused
= (True,accu,cos_used_dynamics,cos_symbol_heap)
where
isEI_Dynamic (EI_Dynamic _ _) = True
isEI_Dynamic _ = False
determine_amount_of_dynamics max_index [] es_symbol_table
= (max_index,es_symbol_table)
determine_amount_of_dynamics max_index [expr_info_ptr:expr_info_ptrs] es_symbol_table
# (expr_info,es_symbol_table)
= readPtr expr_info_ptr es_symbol_table
# (max_index,es_symbol_table)
= case expr_info of
EI_Dynamic _ id
-> (max max_index id,es_symbol_table)
EI_DynamicTypeWithVars _ _ expr_info_ptrs2
-> determine_amount_of_dynamics max_index expr_info_ptrs2 es_symbol_table
// EI_DynamicType _ expr_info_ptrs2
// -> determine_amount_of_dynamics max_index expr_info_ptrs2 es_symbol_table
= determine_amount_of_dynamics max_index expr_info_ptrs es_symbol_table
collect_used_dynmic dyn_expr_ptr (used_dynamics, symbol_heap)
# (expr_info, symbol_heap) = readPtr dyn_expr_ptr symbol_heap
= case expr_info of
EI_UnmarkedDynamic _ _
-> (used_dynamics, symbol_heap)
_
-> ([dyn_expr_ptr : used_dynamics], symbol_heap)
expandCheckedAlternative {ca_rhs, ca_position} ei
# (ca_rhs, ei) = expand ca_rhs ei
......@@ -1779,7 +1755,6 @@ where
, cos_symbol_heap :: !.ExpressionHeap
, cos_error :: !.ErrorAdmin
, cos_predef_symbols_for_transform :: !PredefSymbolsForTransform
, cos_used_dynamics :: !.{#Bool}
}
determineVariablesAndRefCounts :: ![FreeVar] !Expression !*CollectState -> (!Expression , ![FreeVar], ![FreeVar], !*CollectState)
......@@ -1990,19 +1965,16 @@ where
collectVariables (MatchExpr cons_symb expr) free_vars cos
# (expr, free_vars, cos) = collectVariables expr free_vars cos
= (MatchExpr cons_symb expr, free_vars, cos)
collectVariables (DynamicExpr dynamic_expr=:{dyn_expr /* MV ... */ , dyn_info_ptr /* ... MV */}) free_vars cos
#! (dyn_expr, free_vars, cos /* MV ... */ =:{cos_symbol_heap} /* ... MV */) = collectVariables dyn_expr free_vars cos
// MV ...
# (expr_info,cos_symbol_heap)
= readPtr dyn_info_ptr cos_symbol_heap
# cos
= { cos & cos_symbol_heap = cos_symbol_heap }
# cos
= case expr_info of
EI_Dynamic _ id -> { cos & cos_used_dynamics = { cos.cos_used_dynamics & [id] = True } }
_ -> cos
// ... MV
= (DynamicExpr {dynamic_expr & dyn_expr = dyn_expr}, free_vars, cos);
collectVariables (DynamicExpr dynamic_expr=:{dyn_expr, dyn_info_ptr}) free_vars cos
# (dyn_expr, free_vars, cos=:{cos_symbol_heap}) = collectVariables dyn_expr free_vars cos
cos_symbol_heap = mark_used_dynamic dyn_info_ptr (readPtr dyn_info_ptr cos_symbol_heap)
= (DynamicExpr {dynamic_expr & dyn_expr = dyn_expr}, free_vars, { cos & cos_symbol_heap = cos_symbol_heap });
where
mark_used_dynamic dyn_info_ptr (EI_UnmarkedDynamic opt_type loc_dynamics, symbol_heap)
= symbol_heap <:= (dyn_info_ptr, EI_Dynamic opt_type loc_dynamics)
mark_used_dynamic dyn_info_ptr (_, symbol_heap)
= symbol_heap
collectVariables expr free_vars cos
= (expr, free_vars, cos)
......
......@@ -1407,7 +1407,7 @@ where
instance requirements DynamicExpr
where
requirements ti {dyn_expr,dyn_info_ptr} (reqs, ts=:{ts_expr_heap})
# (EI_TempDynamicType _ dyn_type dyn_context dyn_expr_ptr type_code_symbol, ts_expr_heap) = readPtr dyn_info_ptr ts_expr_heap
# (EI_TempDynamicType _ _ dyn_type dyn_context dyn_expr_ptr type_code_symbol, ts_expr_heap) = readPtr dyn_info_ptr ts_expr_heap
(dyn_expr_type, opt_expr_ptr, (reqs, ts)) = requirements ti dyn_expr (reqs, { ts & ts_expr_heap = ts_expr_heap })
ts_expr_heap = storeAttribute opt_expr_ptr dyn_expr_type.at_attribute ts.ts_expr_heap
type_coercion = { tc_demanded = dyn_type, tc_offered = dyn_expr_type, tc_position = CP_Expression dyn_expr, tc_coercible = True }
......@@ -1774,15 +1774,15 @@ where
fresh_dynamic dyn_ptr (var_store, type_heaps, var_heap, expr_heap, predef_symbols)
# (dyn_info, expr_heap) = readPtr dyn_ptr expr_heap
= case dyn_info of
EI_Dynamic opt_dyn_type=:(Yes {dt_uni_vars,dt_type,dt_global_vars}) _
EI_Dynamic opt_dyn_type=:(Yes {dt_uni_vars,dt_type,dt_global_vars}) loc_dynamics
# (th_vars, var_store) = fresh_existential_attributed_variables dt_uni_vars (type_heaps.th_vars, var_store)
(th_vars, var_store) = fresh_type_variables dt_global_vars (th_vars, var_store)
(tdt_type, type_heaps) = freshCopy dt_type { type_heaps & th_vars = th_vars }
(contexts, expr_ptr, type_code_symbol, (var_heap, expr_heap, type_var_heap, predef_symbols))
= determine_context_and_expr_ptr dt_global_vars (var_heap, expr_heap, type_heaps.th_vars, predef_symbols)
-> (var_store, { type_heaps & th_vars = type_var_heap }, var_heap,
expr_heap <:= (dyn_ptr, EI_TempDynamicType opt_dyn_type tdt_type contexts expr_ptr type_code_symbol), predef_symbols)
EI_Dynamic No _
-> fresh_local_dynamics loc_dynamics (var_store, { type_heaps & th_vars = type_var_heap }, var_heap,
expr_heap <:= (dyn_ptr, EI_TempDynamicType opt_dyn_type loc_dynamics tdt_type contexts expr_ptr type_code_symbol), predef_symbols)
EI_Dynamic No loc_dynamics
# fresh_var = TempV var_store
tdt_type = { at_attribute = TA_Multi, at_annotation = AN_None, at_type = fresh_var }
......@@ -1795,18 +1795,20 @@ where
tc_member_symb = { symb_name = pds_ident, symb_kind = SK_OverloadedFunction {glob_module = pds_module, glob_object = pds_def }}
(new_var_ptr, var_heap) = newPtr VI_Empty var_heap
context = {tc_class = tc_class_symb, tc_types = [fresh_var], tc_var = new_var_ptr}
(expr_ptr, expr_heap) = newPtr EI_Empty expr_heap //---> ("^EI_Dynamic No=" +++ toString var_store)
-> (inc var_store, type_heaps, var_heap,
expr_heap <:= (dyn_ptr, EI_TempDynamicType No tdt_type [context] expr_ptr tc_member_symb), predef_symbols)
(expr_ptr, expr_heap) = newPtr EI_Empty expr_heap
-> fresh_local_dynamics loc_dynamics (inc var_store, type_heaps, var_heap,
expr_heap <:= (dyn_ptr, EI_TempDynamicType No loc_dynamics tdt_type [context] expr_ptr tc_member_symb), predef_symbols)
EI_DynamicTypeWithVars loc_type_vars dt=:{dt_uni_vars,dt_type,dt_global_vars} loc_dynamics
# (fresh_vars, (th_vars, var_store)) = fresh_existential_variables loc_type_vars (type_heaps.th_vars, var_store)
// ---> ("fresh_dynamic (EI_DynamicTypeWithVars)", dt_uni_vars)
(th_vars, var_store) = fresh_type_variables dt_global_vars (th_vars, var_store)
(tdt_type, type_heaps) = freshCopy (add_universal_vars_to_type dt_uni_vars dt_type) { type_heaps & th_vars = th_vars }
(contexts, expr_ptr, type_code_symbol, (var_heap, expr_heap, type_var_heap, predef_symbols))
= determine_context_and_expr_ptr dt_global_vars (var_heap, expr_heap, type_heaps.th_vars, predef_symbols)
-> fresh_local_dynamics loc_dynamics (var_store, { type_heaps & th_vars = type_var_heap }, var_heap,
expr_heap <:= (dyn_ptr, EI_TempDynamicPattern loc_type_vars dt loc_dynamics fresh_vars tdt_type contexts expr_ptr type_code_symbol), predef_symbols)
EI_UnmarkedDynamic _ _
-> (var_store, type_heaps, var_heap, expr_heap, predef_symbols)
// ---> ("fresh_dynamic : EI_UnmarkedDynamic")
fresh_local_dynamics loc_dynamics state
= foldSt fresh_dynamic loc_dynamics state
......@@ -1817,12 +1819,15 @@ where
clear_dynamic dyn_ptr (var_heap, expr_heap)
# (dyn_info, expr_heap) = readPtr dyn_ptr expr_heap
= case dyn_info of
EI_Dynamic (Yes {dt_global_vars}) _
-> (clear_type_vars dt_global_vars var_heap, expr_heap)
EI_Dynamic No _