aboutsummaryrefslogtreecommitdiff
path: root/frontend
diff options
context:
space:
mode:
authormartinw2000-06-21 13:53:24 +0000
committermartinw2000-06-21 13:53:24 +0000
commitd49a35b582b5ac2caa7dba1955a6e9cf522856eb (patch)
tree6dea032b4ba3ae8fa6aabbd98e04ea63cb18ced7 /frontend
parentbugfix: not only STE_Imported appears in dcls_explicit (and dcls_import?) but (diff)
solving the problem of strict aliases. Now a strict alias
#! x = y will be transformed into #! x = _dummyForStrictAlias y while checking. The new predefined symbol _dummyForStrictAlias has the type of the identity function. This application will be removed in the backend conversion phase. In this case x and y will simply get the same sequence number (see module backendpreprocess). Then the binding can be ignored. git-svn-id: https://svn.cs.ru.nl/repos/clean-compiler/trunk@177 1f8540f1-abd5-4d5b-9d24-4c5ce8603e2d
Diffstat (limited to 'frontend')
-rw-r--r--frontend/check.dcl3
-rw-r--r--frontend/check.icl42
-rw-r--r--frontend/predef.dcl8
-rw-r--r--frontend/predef.icl27
-rw-r--r--frontend/transform.dcl4
-rw-r--r--frontend/transform.icl73
6 files changed, 99 insertions, 58 deletions
diff --git a/frontend/check.dcl b/frontend/check.dcl
index 3c13324..e69603a 100644
--- a/frontend/check.dcl
+++ b/frontend/check.dcl
@@ -15,7 +15,6 @@ convertIndex :: !Index !Index !(Optional ConversionTable) -> !Index
determineTypeOfMemberInstance :: !SymbolType ![TypeVar] !InstanceType !Specials !*TypeHeaps -> (!SymbolType, !Specials, !*TypeHeaps)
-
-arrayFunOffsetToPD_IndexTable :: !{# MemberDef} !v:{# PredefinedSymbol} -> (!{# Index}, !{#MemberDef}, !v:{#PredefinedSymbol})
+arrayFunOffsetToPD_IndexTable :: !w:{# MemberDef} !v:{# PredefinedSymbol} -> (!{# Index}, !x:{#MemberDef}, !v:{#PredefinedSymbol}) , [w<=x]
makeElemTypeOfArrayFunctionStrict :: !SymbolType !Index !{# Index} -> SymbolType
diff --git a/frontend/check.icl b/frontend/check.icl
index c8cda08..975ebec 100644
--- a/frontend/check.icl
+++ b/frontend/check.icl
@@ -2197,14 +2197,14 @@ where
| bind_dst == fv_info_ptr
# (var_expr_ptr, expr_heap) = newPtr EI_Empty expr_heap
(let_expr_ptr, expr_heap) = newPtr EI_Empty expr_heap
- -> (Let { let_lazy_binds = [], let_strict_binds = [
+ -> (Let { let_strict_binds = [], let_lazy_binds= [
{ bind_src = Var { var_name = fv_name, var_info_ptr = fv_info_ptr, var_expr_ptr = var_expr_ptr },
bind_dst = { fv_name = name, fv_info_ptr = var_info, fv_def_level = NotALevel, fv_count = 0 }}],
let_expr = result_expr, let_info_ptr = let_expr_ptr}, var_store, expr_heap, opt_dynamics, cs)
# (var_expr_ptr1, expr_heap) = newPtr EI_Empty expr_heap
(var_expr_ptr2, expr_heap) = newPtr EI_Empty expr_heap
(let_expr_ptr, expr_heap) = newPtr EI_Empty expr_heap
- -> (Let { let_lazy_binds = [], let_strict_binds = [
+ -> (Let { let_strict_binds = [], let_lazy_binds= [
{ bind_src = Var { var_name = fv_name, var_info_ptr = fv_info_ptr, var_expr_ptr = var_expr_ptr1 },
bind_dst = { fv_name = name, fv_info_ptr = var_info, fv_def_level = NotALevel, fv_count = 0 }},
{ bind_src = Var { var_name = fv_name, var_info_ptr = fv_info_ptr, var_expr_ptr = var_expr_ptr2 },
@@ -2215,10 +2215,11 @@ where
-> (result_expr, var_store, expr_heap, opt_dynamics, cs)
# (var_expr_ptr, expr_heap) = newPtr EI_Empty expr_heap
(let_expr_ptr, expr_heap) = newPtr EI_Empty expr_heap
- -> (Let { let_lazy_binds = [], let_strict_binds =
+ -> (Let { let_strict_binds = [], let_lazy_binds=
[{ bind_src = Var { var_name = fv_name, var_info_ptr = fv_info_ptr, var_expr_ptr = var_expr_ptr },
bind_dst = { fv_name = name, fv_info_ptr = var_info, fv_def_level = NotALevel, fv_count = 0 }}],
let_expr = result_expr, let_info_ptr = let_expr_ptr}, var_store, expr_heap, opt_dynamics, cs)
+
transform_pattern_into_cases (AP_Algebraic cons_symbol type_index args opt_var) fun_arg result_expr var_store expr_heap opt_dynamics cs
# (var_args, result_expr, var_store, expr_heap, opt_dynamics, cs) = convertSubPatterns args result_expr var_store expr_heap opt_dynamics cs
type_symbol = {glob_module = cons_symbol.glob_module, glob_object = type_index}
@@ -2335,13 +2336,14 @@ checkFunctions mod_index level from_index to_index fun_defs e_info heaps cs
checkMacros :: !Index !IndexRange !*{#FunDef} !*ExpressionInfo !*Heaps !*CheckState
-> (!*{#FunDef}, !*ExpressionInfo, !*Heaps, !*CheckState);
checkMacros mod_index range fun_defs e_info=:{ef_is_macro_fun=ef_is_macro_fun_old} heaps cs
- # (fun_defs, e_info, heaps=:{hp_var_heap, hp_expression_heap}, cs=:{cs_symbol_table,cs_error})
+ # (fun_defs, e_info, heaps=:{hp_var_heap, hp_expression_heap}, cs=:{cs_symbol_table, cs_predef_symbols, cs_error})
= checkFunctions mod_index cGlobalScope range.ir_from range.ir_to fun_defs { e_info & ef_is_macro_fun=True } heaps cs
(e_info=:{ef_modules}) = { e_info & ef_is_macro_fun=ef_is_macro_fun_old }
+ (pds_alias_dummy, cs_predef_symbols) = cs_predef_symbols![PD_DummyForStrictAliasFun]
(fun_defs, ef_modules, hp_var_heap, hp_expression_heap, cs_symbol_table, cs_error)
- = partitionateMacros range mod_index fun_defs ef_modules hp_var_heap hp_expression_heap cs_symbol_table cs_error
+ = partitionateMacros range mod_index pds_alias_dummy fun_defs ef_modules hp_var_heap hp_expression_heap cs_symbol_table cs_error
= (fun_defs, { e_info & ef_modules = ef_modules }, {heaps & hp_var_heap = hp_var_heap, hp_expression_heap = hp_expression_heap},
- { cs & cs_symbol_table = cs_symbol_table, cs_error = cs_error })
+ { cs & cs_symbol_table = cs_symbol_table, cs_predef_symbols = cs_predef_symbols, cs_error = cs_error })
checkInstanceBodies :: !IndexRange !*{#FunDef} !*ExpressionInfo !*Heaps !*CheckState -> (!*{#FunDef},!*ExpressionInfo,!*Heaps, !*CheckState);
checkInstanceBodies {ir_from, ir_to} fun_defs e_info heaps cs
@@ -2670,8 +2672,9 @@ checkModule {mod_type,mod_name,mod_imports,mod_imported_objects,mod_defs = cdefs
= adjust_instance_types_of_array_functions_in_std_array_icl dcl_modules class_instances icl_functions cs_predef_symbols
(untransformed_fun_bodies, icl_functions) = copy_bodies icl_functions
+ (pds_alias_dummy, cs_predef_symbols) = cs_predef_symbols![PD_DummyForStrictAliasFun]
(groups, icl_functions, dcl_modules, var_heap, expr_heap, cs_symbol_table, cs_error)
- = partitionateAndLiftFunctions [icl_global_function_range, icl_instances] cIclModIndex icl_functions
+ = partitionateAndLiftFunctions [icl_global_function_range, icl_instances] cIclModIndex pds_alias_dummy icl_functions
dcl_modules var_heap expr_heap cs_symbol_table cs_error
icl_common = { icl_common & com_type_defs = e_info.ef_type_defs, com_selector_defs = e_info.ef_selector_defs, com_class_defs = e_info.ef_class_defs,
com_cons_defs = e_info.ef_cons_defs, com_member_defs = e_info.ef_member_defs, com_instance_defs = class_instances }
@@ -2930,9 +2933,9 @@ check_needed_modules_are_imported mod_name extension cs=:{cs_needed_modules}
cs_error = popErrorAdmin cs_error
-> { cs & cs_error = cs_error }
-arrayFunOffsetToPD_IndexTable :: !{# MemberDef} !v:{# PredefinedSymbol} -> (!{# Index}, !{#MemberDef}, !v:{#PredefinedSymbol})
+arrayFunOffsetToPD_IndexTable :: !w:{# MemberDef} !v:{# PredefinedSymbol} -> (!{# Index}, !x:{#MemberDef}, !v:{#PredefinedSymbol}) , [w<=x]
arrayFunOffsetToPD_IndexTable member_defs predef_symbols
- # nr_of_array_functions = size member_defs
+ #! nr_of_array_functions = size member_defs
= iFoldSt offset_to_PD_index PD_CreateArrayFun (PD_CreateArrayFun + nr_of_array_functions)
(createArray nr_of_array_functions NoIndex, member_defs, predef_symbols)
where
@@ -3063,26 +3066,26 @@ checkDclModule {mod_name,mod_imports,mod_defs} mod_index modules icl_functions h
mem_inst <- memb_inst_defs & spec_types <-: all_spec_types ] ++
reverse rev_special_defs) }
+ com_instance_defs = dcl_common.com_instance_defs
+ com_instance_defs = { inst_def \\ inst_def <- [ inst_def \\ inst_def <-: com_instance_defs ] ++ new_class_instances }
+
+ (com_member_defs, com_instance_defs, dcl_functions, cs)
+ = adjust_predefined_symbols mod_index dcl_common.com_member_defs com_instance_defs dcl_functions { cs & cs_error = cs_error }
+
e_info = { ef_type_defs = com_type_defs, ef_selector_defs = dcl_common.com_selector_defs, ef_class_defs = com_class_defs,
- ef_cons_defs = dcl_common.com_cons_defs, ef_member_defs = dcl_common.com_member_defs, ef_modules = modules,
+ ef_cons_defs = dcl_common.com_cons_defs, ef_member_defs = com_member_defs, ef_modules = modules,
ef_is_macro_fun = False }
(icl_functions, e_info, heaps, cs)
- = checkMacros mod_index dcl_macros icl_functions e_info heaps { cs & cs_error = cs_error }
+ = checkMacros mod_index dcl_macros icl_functions e_info heaps cs
cs = check_needed_modules_are_imported mod_name ".dcl" cs
- com_instance_defs = dcl_common.com_instance_defs
- com_instance_defs = { inst_def \\ inst_def <- [ inst_def \\ inst_def <-: com_instance_defs ] ++ new_class_instances }
-
- (ef_member_defs, com_instance_defs, dcl_functions, cs)
- = adjust_predefined_symbols mod_index e_info.ef_member_defs com_instance_defs dcl_functions cs
-
first_special_class_index = size com_instance_defs
last_special_class_index = first_special_class_index + length new_class_instances
dcl_common = { dcl_common & com_type_defs = e_info.ef_type_defs, com_selector_defs = e_info.ef_selector_defs, com_class_defs = e_info.ef_class_defs,
- com_instance_defs = com_instance_defs, com_cons_defs = e_info.ef_cons_defs, com_member_defs = ef_member_defs }
+ com_instance_defs = com_instance_defs, com_cons_defs = e_info.ef_cons_defs, com_member_defs = e_info.ef_member_defs }
(dcl_imported, cs_symbol_table) = retrieveAndRemoveImportsFromSymbolTable imports [] cs.cs_symbol_table
cs_symbol_table = removeDeclarationsFromSymbolTable dcl_defined cModuleScope cs_symbol_table
@@ -3147,7 +3150,8 @@ where
<=< adjust_predef_symbols PD_ListType PD_UnboxedArrayType mod_index STE_Type
<=< adjust_predef_symbols PD_ConsSymbol PD_Arity32TupleSymbol mod_index STE_Constructor
<=< adjust_predef_symbol PD_TypeCodeClass mod_index STE_Class
- <=< adjust_predef_symbol PD_TypeCodeMember mod_index STE_Member)
+ <=< adjust_predef_symbol PD_TypeCodeMember mod_index STE_Member
+ <=< adjust_predef_symbol PD_DummyForStrictAliasFun mod_index STE_DclFunction)
# (pre_mod, cs_predef_symbols) = cs_predef_symbols![PD_StdBool]
| pre_mod.pds_def == mod_index
= (class_members, class_instances, fun_types, { cs & cs_predef_symbols = cs_predef_symbols}
diff --git a/frontend/predef.dcl b/frontend/predef.dcl
index 5c2a42c..66f032c 100644
--- a/frontend/predef.dcl
+++ b/frontend/predef.dcl
@@ -75,7 +75,6 @@ PD_TypeCodeClass :== 122
PD_TypeObjectType :== 124
PD_TypeConsSymbol :== 125
PD_unify :== 126
-// MV ..
PD_coerce :== 127
PD_variablePlaceholder :== 128
PD_StdDynamics :== 129
@@ -83,8 +82,11 @@ PD_undo_indirections :== 130
PD_Start :== 131
-PD_NrOfPredefSymbols :== 132
-// .. MV
+// MW..
+PD_DummyForStrictAliasFun :== 132
+
+PD_NrOfPredefSymbols :== 133
+// ..MW
GetTupleConsIndex tup_arity :== PD_Arity2TupleSymbol + tup_arity - 2
GetTupleTypeIndex tup_arity :== PD_Arity2TupleType + tup_arity - 2
diff --git a/frontend/predef.icl b/frontend/predef.icl
index 277896a..c28aa2d 100644
--- a/frontend/predef.icl
+++ b/frontend/predef.icl
@@ -73,7 +73,6 @@ PD_TypeCodeClass :== 122
PD_TypeObjectType :== 124
PD_TypeConsSymbol :== 125
PD_unify :== 126
-// MV ..
PD_coerce :== 127
PD_variablePlaceholder :== 128
PD_StdDynamics :== 129
@@ -81,8 +80,11 @@ PD_undo_indirections :== 130
PD_Start :== 131
-PD_NrOfPredefSymbols :== 132
-// .. MV
+// MW..
+PD_DummyForStrictAliasFun :== 132
+
+PD_NrOfPredefSymbols :== 133
+// ..MW
(<<=) infixl
@@ -113,6 +115,7 @@ where
<<= ("_list", PD_ListType) <<= ("_cons", PD_ConsSymbol) <<= ("_nil", PD_NilSymbol)
<<= ("_array", PD_LazyArrayType) <<= ("_!array", PD_StrictArrayType) <<= ("_#array", PD_UnboxedArrayType)
<<= ("_type_code", PD_TypeCodeMember)
+ <<= ("_dummyForStrictAlias", PD_DummyForStrictAliasFun) // MW++
where
build_tuples tup_arity max_arity tables
@@ -198,6 +201,7 @@ buildPredefinedModule pre_def_symbols
(list_id, pre_def_symbols) = pre_def_symbols![PD_ListType]
(unb_array_id, pre_def_symbols) = pre_def_symbols![PD_UnboxedArrayType]
(pre_mod_symb, pre_def_symbols) = pre_def_symbols![PD_PredefinedModule]
+ (alias_dummy_symb, pre_def_symbols) = pre_def_symbols![PD_DummyForStrictAliasFun] // MW++
(cons_symb, pre_def_symbols) = new_defined_symbol PD_ConsSymbol 2 cConsSymbIndex pre_def_symbols
(nil_symb, pre_def_symbols) = new_defined_symbol PD_NilSymbol 0 cNilSymbIndex pre_def_symbols
pre_mod_id = pre_mod_symb.pds_ident
@@ -220,12 +224,14 @@ buildPredefinedModule pre_def_symbols
(unboxed_def, pre_def_symbols) = make_type_def PD_UnboxedArrayType [type_var] (AbstractType cIsHyperStrict) pre_def_symbols
(type_defs, cons_defs, pre_def_symbols) = add_tuple_defs pre_mod_id MaxTupleArity [array_def,strict_def,unboxed_def] [] pre_def_symbols
+ alias_dummy_type = make_identity_fun_type alias_dummy_symb.pds_ident type_var // MW++
(class_def, member_def, pre_def_symbols) = make_TC_class_def pre_def_symbols
= ({ mod_name = pre_mod_id, mod_type = MK_System, mod_imports = [], mod_imported_objects = [],
mod_defs = {
- def_types = [string_def, list_def : type_defs], def_constructors
- = [ParsedConstructorToConsDef cons_def, ParsedConstructorToConsDef nil_def : cons_defs], def_selectors = [], def_classes = [class_def],
- def_macros = { ir_from = 0, ir_to = 0 }, def_members = [member_def], def_funtypes = [], def_instances = [] }}, pre_def_symbols)
+ def_types = [string_def, list_def : type_defs],
+ def_constructors = [ParsedConstructorToConsDef cons_def, ParsedConstructorToConsDef nil_def : cons_defs],
+ def_selectors = [], def_classes = [class_def], def_macros = { ir_from = 0, ir_to = 0 }, def_members = [member_def],
+ def_funtypes = [alias_dummy_type], def_instances = [] }}, pre_def_symbols)
where
add_tuple_defs pre_mod_id tup_arity type_defs cons_defs pre_def_symbols
| tup_arity >= 2
@@ -276,7 +282,14 @@ where
= (class_def, member_def, pre_def_symbols)
-
+// MW..
+ make_identity_fun_type alias_dummy_id type_var
+ # a = { at_attribute = TA_Anonymous, at_annotation = AN_Strict, at_type = TV type_var }
+ id_symbol_type = { st_vars = [], st_args = [a], st_arity = 1, st_result = a, st_context = [],
+ st_attr_vars = [], st_attr_env = [] } // !.a -> .a
+ = { ft_symb = alias_dummy_id, ft_arity = 1, ft_priority = NoPrio, ft_type = id_symbol_type, ft_pos = NoPos,
+ ft_specials = SP_None, ft_type_ptr = nilPtr }
+// ..MW
diff --git a/frontend/transform.dcl b/frontend/transform.dcl
index 6d3a81c..43118c7 100644
--- a/frontend/transform.dcl
+++ b/frontend/transform.dcl
@@ -6,10 +6,10 @@ import syntax, checksupport
{ group_members :: ![Int]
}
-partitionateAndLiftFunctions :: ![IndexRange] !Index !*{# FunDef} !u:{# DclModule} !*VarHeap !*ExpressionHeap !*SymbolTable !*ErrorAdmin
+partitionateAndLiftFunctions :: ![IndexRange] !Index !PredefinedSymbol !*{# FunDef} !u:{# DclModule} !*VarHeap !*ExpressionHeap !*SymbolTable !*ErrorAdmin
-> (!*{! Group}, !*{# FunDef}, !u:{# DclModule}, !*VarHeap, !*ExpressionHeap, !*SymbolTable, !*ErrorAdmin )
-partitionateMacros :: !IndexRange !Index !*{# FunDef} !u:{# DclModule} !*VarHeap !*ExpressionHeap !*SymbolTable !*ErrorAdmin
+partitionateMacros :: !IndexRange !Index !PredefinedSymbol !*{# FunDef} !u:{# DclModule} !*VarHeap !*ExpressionHeap !*SymbolTable !*ErrorAdmin
-> (!*{# FunDef}, !u:{# DclModule}, !*VarHeap, !*ExpressionHeap, !*SymbolTable, !*ErrorAdmin )
:: UnfoldState =
diff --git a/frontend/transform.icl b/frontend/transform.icl
index abc067b..46caeb1 100644
--- a/frontend/transform.icl
+++ b/frontend/transform.icl
@@ -543,9 +543,9 @@ where
NotChecked :== -1
-partitionateMacros :: !IndexRange !Index !*{# FunDef} !u:{# DclModule} !*VarHeap !*ExpressionHeap !*SymbolTable !*ErrorAdmin
+partitionateMacros :: !IndexRange !Index !PredefinedSymbol !*{# FunDef} !u:{# DclModule} !*VarHeap !*ExpressionHeap !*SymbolTable !*ErrorAdmin
-> (!*{# FunDef}, !u:{# DclModule}, !*VarHeap, !*ExpressionHeap, !*SymbolTable, !*ErrorAdmin )
-partitionateMacros {ir_from,ir_to} mod_index fun_defs modules var_heap symbol_heap symbol_table error
+partitionateMacros {ir_from,ir_to} mod_index alias_dummy fun_defs modules var_heap symbol_heap symbol_table error
#! max_fun_nr = size fun_defs
# partitioning_info = { pi_var_heap = var_heap, pi_symbol_heap = symbol_heap,
pi_symbol_table = symbol_table,
@@ -588,7 +588,7 @@ where
es = { es_symbol_table = pi_symbol_table, es_var_heap = pi_var_heap,
es_symbol_heap = pi_symbol_heap, es_error = setErrorAdmin identPos pi_error }
(tb_args, tb_rhs, local_vars, fi_calls, macro_defs, modules, {es_symbol_table, es_var_heap, es_symbol_heap, es_error})
- = expandMacrosInBody [] body macro_defs mod_index modules es
+ = expandMacrosInBody [] body macro_defs mod_index alias_dummy modules es
macro = { macro & fun_body = TransformedBody { tb_args = tb_args, tb_rhs = tb_rhs},
fun_info = { fun_info & fi_calls = fi_calls, fi_local_vars = local_vars }}
= ({ macro_defs & [macro_index] = macro }, modules,
@@ -607,9 +607,9 @@ where
is_a_pattern_macro _ _
= False
-partitionateAndLiftFunctions :: ![IndexRange] !Index !*{# FunDef} !u:{# DclModule} !*VarHeap !*ExpressionHeap !*SymbolTable !*ErrorAdmin
+partitionateAndLiftFunctions :: ![IndexRange] !Index !PredefinedSymbol !*{# FunDef} !u:{# DclModule} !*VarHeap !*ExpressionHeap !*SymbolTable !*ErrorAdmin
-> (!*{! Group}, !*{# FunDef}, !u:{# DclModule}, !*VarHeap, !*ExpressionHeap, !*SymbolTable, !*ErrorAdmin )
-partitionateAndLiftFunctions ranges mod_index fun_defs modules var_heap symbol_heap symbol_table error
+partitionateAndLiftFunctions ranges mod_index alias_dummy fun_defs modules var_heap symbol_heap symbol_table error
#! max_fun_nr = size fun_defs
# partitioning_info = { pi_var_heap = var_heap, pi_symbol_heap = symbol_heap, pi_symbol_table = symbol_table,
pi_error = error, pi_deps = [], pi_next_num = 0, pi_next_group = 0, pi_groups = [] }
@@ -687,7 +687,8 @@ where
{fun_symb,fun_body = PartioningFunction body _, fun_info, fun_pos} = fun_def
identPos = newPosition fun_symb fun_pos
(tb_args, tb_rhs, fi_local_vars, fi_calls, fun_and_macro_defs, modules, es)
- = expandMacrosInBody fun_info.fi_calls body fun_and_macro_defs mod_index modules { es & es_error = setErrorAdmin identPos es.es_error }
+ = expandMacrosInBody fun_info.fi_calls body fun_and_macro_defs mod_index alias_dummy modules
+ { es & es_error = setErrorAdmin identPos es.es_error }
fun_def = { fun_def & fun_body = TransformedBody { tb_args = tb_args, tb_rhs = tb_rhs},
fun_info = { fun_info & fi_calls = fi_calls, fi_local_vars = fi_local_vars }}
= ({ fun_and_macro_defs & [fun_index] = fun_def }, modules, es)
@@ -732,13 +733,15 @@ where
-> (fun_defs, symbol_table)
-expandMacrosInBody fi_calls {cb_args,cb_rhs} fun_defs mod_index modules es=:{es_symbol_table}
+expandMacrosInBody fi_calls {cb_args,cb_rhs} fun_defs mod_index alias_dummy modules es=:{es_symbol_table}
# (prev_calls, fun_defs, es_symbol_table) = addFunctionCallsToSymbolTable fi_calls fun_defs es_symbol_table
([rhs:rhss], fun_defs, modules, (all_calls, es)) = expand cb_rhs fun_defs mod_index modules (prev_calls, { es & es_symbol_table = es_symbol_table })
(fun_defs, es_symbol_table) = removeFunctionCallsFromSymbolTable all_calls fun_defs es.es_symbol_table
(merged_rhs, es_var_heap, es_symbol_heap, es_error) = mergeCases rhs rhss es.es_var_heap es.es_symbol_heap es.es_error
- (new_rhs, new_args, local_vars, {cos_error, cos_var_heap, cos_symbol_heap}) = determineVariablesAndRefCounts cb_args merged_rhs
- { cos_error = es_error, cos_var_heap = es_var_heap, cos_symbol_heap = es_symbol_heap }
+ (new_rhs, new_args, local_vars, {cos_error, cos_var_heap, cos_symbol_heap})
+ = determineVariablesAndRefCounts cb_args merged_rhs
+ { cos_error = es_error, cos_var_heap = es_var_heap, cos_symbol_heap = es_symbol_heap,
+ cos_alias_dummy = alias_dummy }
= (new_args, new_rhs, local_vars, all_calls, fun_defs, modules,
{ es & es_error = cos_error, es_var_heap = cos_var_heap, es_symbol_heap = cos_symbol_heap,
es_symbol_table = es_symbol_table })
@@ -1142,6 +1145,7 @@ where
{ cos_var_heap :: !.VarHeap
, cos_symbol_heap :: !.ExpressionHeap
, cos_error :: !.ErrorAdmin
+ , cos_alias_dummy :: !PredefinedSymbol
}
determineVariablesAndRefCounts :: ![FreeVar] !Expression !*CollectState -> (!Expression , ![FreeVar], ![FreeVar], !*CollectState)
@@ -1206,15 +1210,17 @@ where
= (expr @ exprs, free_vars, cos)
collectVariables (Let lad=:{let_strict_binds, let_lazy_binds, let_expr}) free_vars cos=:{cos_var_heap}
# cos_var_heap = determine_aliases let_strict_binds cos_var_heap
-// XXX: # cos_var_heap = foldSt (\bind cos_var_heap->clearCount bind cIsALocalVar cos_var_heap) let_strict_binds cos_var_heap
- # cos_var_heap = determine_aliases let_lazy_binds cos_var_heap
- (is_cyclic_s, let_strict_binds, cos_var_heap) = detect_cycles_and_remove_alias_binds let_strict_binds cos_var_heap
- (is_cyclic_l, let_lazy_binds, cos_var_heap) = detect_cycles_and_remove_alias_binds let_lazy_binds cos_var_heap
+ cos_var_heap = determine_aliases let_lazy_binds cos_var_heap
+ (is_cyclic_s, let_strict_binds, cos)
+ = detect_cycles_and_handle_alias_binds True let_strict_binds
+ { cos & cos_var_heap = cos_var_heap }
+ (is_cyclic_l, let_lazy_binds, cos)
+ = detect_cycles_and_handle_alias_binds False let_lazy_binds cos
| is_cyclic_s || is_cyclic_l
= (Let {lad & let_strict_binds = let_strict_binds, let_lazy_binds = let_lazy_binds }, free_vars,
- { cos & cos_var_heap = cos_var_heap, cos_error = checkError "" "cyclic let definition" cos.cos_error})
+ { cos & cos_error = checkError "" "cyclic let definition" cos.cos_error})
// | otherwise
- # (let_expr, free_vars, cos) = collectVariables let_expr free_vars { cos & cos_var_heap = cos_var_heap }
+ # (let_expr, free_vars, cos) = collectVariables let_expr free_vars cos
all_binds = mapAppend (\sb->(True, sb)) let_strict_binds [(False, lb) \\ lb<-let_lazy_binds]
(collected_binds, free_vars, cos) = collect_variables_in_binds all_binds [] free_vars cos
(let_strict_binds, let_lazy_binds) = split collected_binds
@@ -1236,20 +1242,28 @@ where
= var_heap
- /* Remove all aliases from the list of 'let'-binds. Be careful with cycles! */
+ /* Remove all aliases from the list of lazy 'let'-binds. Add a _dummyForStrictAlias
+ function call for the strict aliases. Be careful with cycles! */
- detect_cycles_and_remove_alias_binds [] var_heap
- = (cContainsNoCycle, [], var_heap)
- detect_cycles_and_remove_alias_binds [bind=:{bind_dst={fv_info_ptr}} : binds] var_heap
- #! var_info = sreadPtr fv_info_ptr var_heap
+ detect_cycles_and_handle_alias_binds is_strict [] cos
+ = (cContainsNoCycle, [], cos)
+ detect_cycles_and_handle_alias_binds is_strict [bind=:{bind_dst={fv_info_ptr}} : binds] cos
+ #! var_info = sreadPtr fv_info_ptr cos.cos_var_heap
= case var_info of
VI_Alias {var_info_ptr}
- | is_cyclic fv_info_ptr var_info_ptr var_heap
- -> (cContainsACycle, binds, var_heap)
- -> detect_cycles_and_remove_alias_binds binds var_heap
+ | is_cyclic fv_info_ptr var_info_ptr cos.cos_var_heap
+ -> (cContainsACycle, binds, cos)
+ | is_strict
+ # cos_var_heap = writePtr fv_info_ptr (VI_Count 0 cIsALocalVar) cos.cos_var_heap
+ (new_bind_src, cos) = add_dummy_id_for_strict_alias bind.bind_src
+ { cos & cos_var_heap = cos_var_heap }
+ (is_cyclic, binds, cos)
+ = detect_cycles_and_handle_alias_binds is_strict binds cos
+ -> (is_cyclic, [{ bind & bind_src = new_bind_src } : binds], cos)
+ -> detect_cycles_and_handle_alias_binds is_strict binds cos
_
- # (is_cyclic, binds, var_heap) = detect_cycles_and_remove_alias_binds binds var_heap
- -> (is_cyclic, [bind : binds], var_heap)
+ # (is_cyclic, binds, cos) = detect_cycles_and_handle_alias_binds is_strict binds cos
+ -> (is_cyclic, [bind : binds], cos)
where
is_cyclic orig_info_ptr info_ptr var_heap
| orig_info_ptr == info_ptr
@@ -1260,6 +1274,15 @@ where
-> is_cyclic orig_info_ptr var_info_ptr var_heap
_
-> False
+
+ add_dummy_id_for_strict_alias bind_src cos=:{cos_symbol_heap, cos_alias_dummy}
+ # (new_app_info_ptr, cos_symbol_heap) = newPtr EI_Empty cos_symbol_heap
+ {pds_ident, pds_module, pds_def} = cos_alias_dummy
+ app_symb = { symb_name = pds_ident,
+ symb_kind = SK_Function {glob_module = pds_module, glob_object = pds_def},
+ symb_arity = 1 }
+ = (App { app_symb = app_symb, app_args = [bind_src], app_info_ptr = new_app_info_ptr },
+ { cos & cos_symbol_heap = cos_symbol_heap } )
/* Apply 'collectVariables' to the bound expressions (the 'bind_src' field of 'let'-bind) if
the corresponding bound variable (the 'bind_dst' field) has been used. This can be determined