aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--frontend/check.icl22
-rw-r--r--frontend/parse.icl33
-rw-r--r--frontend/predef.dcl72
-rw-r--r--frontend/predef.icl71
-rw-r--r--frontend/transform.icl27
5 files changed, 154 insertions, 71 deletions
diff --git a/frontend/check.icl b/frontend/check.icl
index c7427be..79aeb2c 100644
--- a/frontend/check.icl
+++ b/frontend/check.icl
@@ -1718,6 +1718,14 @@ check_module2 mod_name mod_imported_objects mod_imports mod_type icl_global_func
(dcls_import_list, dcl_modules, cs)
= addImportedSymbolsToSymbolTable nr_of_modules (Yes dcl_macros) modules_in_component_set
imports_ikh dcl_modules cs
+
+// MV ...
+ (x_main_dcl_module,cs)
+ = cs!cs_x.x_main_dcl_module_n
+ cs = cs
+// <=< adjust_predef_symbol PD_ModuleType x_main_dcl_module STE_Type
+ <=< adjust_predef_symbol PD_ModuleConsSymbol x_main_dcl_module STE_Constructor
+// .. MV
(dcl_modules, icl_functions, hp_expression_heap, cs)
= checkExplicitImportCompleteness imports.si_explicit
@@ -2677,6 +2685,20 @@ where
= getClassDef ins_class mod_index com_class_defs modules
= (size class_members + sum, com_class_defs, modules)
+// MV...
+adjust_predef_symbol predef_index mod_index symb_kind cs=:{cs_predef_symbols,cs_symbol_table,cs_error}
+ # (pre_symb, cs_predef_symbols) = cs_predef_symbols![predef_index]
+ # pre_id = pre_symb.pds_ident
+ #! pre_index = determine_index_of_symbol (sreadPtr pre_id.id_info cs_symbol_table) symb_kind
+ | pre_index <> NoIndex
+ = { cs & cs_predef_symbols = {cs_predef_symbols & [predef_index] = { pre_symb & pds_def = pre_index, pds_module = mod_index }}}
+ = { cs & cs_predef_symbols = cs_predef_symbols, cs_error = checkError pre_id " function not defined" cs_error }
+where
+ determine_index_of_symbol {ste_kind, ste_index} symb_kind
+ | ste_kind == symb_kind
+ = ste_index
+ = NoIndex
+// ... MV
NewEntry symbol_table symb_ptr def_kind def_index level previous :==
symbol_table <:= (symb_ptr,{ ste_kind = def_kind, ste_index = def_index, ste_def_level = level, ste_previous = previous })
diff --git a/frontend/parse.icl b/frontend/parse.icl
index 4bd1f96..23eb048 100644
--- a/frontend/parse.icl
+++ b/frontend/parse.icl
@@ -286,6 +286,9 @@ where
(mod_ident, pState) = stringToIdent mod_name IC_Module pState
pState = check_layout_rule pState
(defs, pState) = want_definitions (SetGlobalContext iclmodule) pState
+// MV ...
+ # (defs, pState) = add_module_id mod_name defs pState;
+// ... MV
{ps_scanState,ps_hash_table,ps_error,ps_pre_def_symbols}
= pState
defs = if (ParseOnly && id_name <> "StdOverloaded" && id_name <> "StdArray" && id_name <> "StdEnum" && id_name <> "StdBool" && id_name <> "StdDynamics" && id_name <> "StdGeneric")
@@ -303,6 +306,36 @@ where
mod = { mod_name = file_id, mod_type = mod_type, mod_imports = [], mod_imported_objects = [], mod_defs = [] }
= (False, mod, hash_table, error <<< "Error [" <<< file_name <<< ',' <<< fp_line <<< "]: incorrect module header",
pre_def_symbols, closeScanner scanState files)
+ where
+// MV...
+ add_module_id mod_name defs pState
+ | not iclmodule
+ = (defs,pState);
+
+ // It is essential that the type name denoted by ident is an unique type name within the application. Otherwise
+ // the static linker will choose one implementation (because the type names are equal) and map the other to the
+ // chosen implementation.
+ // The zero arity of the _Module constructor makes the code generator, pre-allocate _Module in .data section of
+ // the final executable. The module name needed by the dynamic run-time system can then be determined by looking
+ // at the descriptor. If however all implementations were mapped to a single one, the dynamic rts could not use
+ // the module name anymore because they are all the same.
+ # (ident, pState) = stringToIdent ("_" +++ mod_name +++ "_Module") IC_Type pState
+ # td = MakeTypeDef ident [] (ConsList []) TA_None [] NoPos
+
+ # (pc_cons_name, pState) = stringToIdent "_Module" IC_Expression pState
+ # cons
+ = {
+ pc_cons_name = pc_cons_name
+ , pc_arg_types = []
+ , pc_cons_arity = 0
+ , pc_cons_prio = NoPrio
+ , pc_exi_vars = []
+ , pc_cons_pos = NoPos
+ }
+ # td
+ = { td & td_rhs = ConsList [cons] }
+ = ([PD_Type td:defs],pState)
+// ...MV
try_module_header :: !Bool !ScanState -> (!Bool,!ModuleKind,!String,!ScanState)
try_module_header is_icl_mod scanState
diff --git a/frontend/predef.dcl b/frontend/predef.dcl
index d33e33b..66a5d97 100644
--- a/frontend/predef.dcl
+++ b/frontend/predef.dcl
@@ -14,7 +14,6 @@ import syntax, hashtable
/* identifiers not present the hastable */
-
PD_PredefinedModule :== 0
PD_StringType :== 1
@@ -69,7 +68,7 @@ PD_UnqArraySizeFun :== 119
/* Enum/Comprehension functions */
PD_SmallerFun :== 120
-PD_LessOrEqualFun:==121
+PD_LessOrEqualFun:== 121
PD_SubFun:==122
PD_IncFun :== 123
PD_From :== 124
@@ -90,44 +89,49 @@ PD_variablePlaceholder :== 133
PD_StdDynamics :== 134
PD_undo_indirections :== 135
+// MV ...
+//PD_ModuleType :== 136
+PD_ModuleConsSymbol :== 137
+// ... MV
+
/* Generics */
-PD_StdGeneric :== 136
-PD_TypeISO :== 137
-PD_ConsISO :== 138
-PD_iso_to :== 139
-PD_iso_from :== 140
-
-PD_TypeUNIT :== 141
-PD_ConsUNIT :== 142
-PD_TypeEITHER :== 143
-PD_ConsLEFT :== 144
-PD_ConsRIGHT :== 145
-PD_TypePAIR :== 146
-PD_ConsPAIR :== 147
-PD_TypeARROW :== 148
-PD_ConsARROW :== 149
-
-PD_TypeConsDefInfo :== 150
-PD_ConsConsDefInfo :== 151
-PD_TypeTypeDefInfo :== 152
-PD_ConsTypeDefInfo :== 153
-PD_cons_info :== 154
-PD_TypeCONS :== 155
-PD_ConsCONS :== 156
-
-PD_isomap_ARROW_ :== 157
-PD_isomap_ID :== 158
+PD_StdGeneric :== 138
+PD_TypeISO :== 139
+PD_ConsISO :== 140
+PD_iso_to :== 141
+PD_iso_from :== 142
+
+PD_TypeUNIT :== 143
+PD_ConsUNIT :== 144
+PD_TypeEITHER :== 145
+PD_ConsLEFT :== 146
+PD_ConsRIGHT :== 147
+PD_TypePAIR :== 148
+PD_ConsPAIR :== 149
+PD_TypeARROW :== 150
+PD_ConsARROW :== 151
+
+PD_TypeConsDefInfo :== 152
+PD_ConsConsDefInfo :== 153
+PD_TypeTypeDefInfo :== 154
+PD_ConsTypeDefInfo :== 155
+PD_cons_info :== 156
+PD_TypeCONS :== 157
+PD_ConsCONS :== 158
+
+PD_isomap_ARROW_ :== 159
+PD_isomap_ID :== 160
/* StdMisc */
-PD_StdMisc :== 159
-PD_abort :== 160
-PD_undef :== 161
+PD_StdMisc :== 161
+PD_abort :== 162
+PD_undef :== 163
-PD_Start :== 162
+PD_Start :== 164
-PD_DummyForStrictAliasFun :== 163
+PD_DummyForStrictAliasFun :== 165
-PD_NrOfPredefSymbols :== 164
+PD_NrOfPredefSymbols :== 166
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 1edb37a..847c279 100644
--- a/frontend/predef.icl
+++ b/frontend/predef.icl
@@ -88,44 +88,49 @@ PD_variablePlaceholder :== 133
PD_StdDynamics :== 134
PD_undo_indirections :== 135
+// MV ...
+//PD_ModuleType :== 136
+PD_ModuleConsSymbol :== 137
+// ... MV
+
/* Generics */
-PD_StdGeneric :== 136
-PD_TypeISO :== 137
-PD_ConsISO :== 138
-PD_iso_to :== 139
-PD_iso_from :== 140
-
-PD_TypeUNIT :== 141
-PD_ConsUNIT :== 142
-PD_TypeEITHER :== 143
-PD_ConsLEFT :== 144
-PD_ConsRIGHT :== 145
-PD_TypePAIR :== 146
-PD_ConsPAIR :== 147
-PD_TypeARROW :== 148
-PD_ConsARROW :== 149
-
-PD_TypeConsDefInfo :== 150
-PD_ConsConsDefInfo :== 151
-PD_TypeTypeDefInfo :== 152
-PD_ConsTypeDefInfo :== 153
-PD_cons_info :== 154
-PD_TypeCONS :== 155
-PD_ConsCONS :== 156
-
-PD_isomap_ARROW_ :== 157
-PD_isomap_ID :== 158
+PD_StdGeneric :== 138
+PD_TypeISO :== 139
+PD_ConsISO :== 140
+PD_iso_to :== 141
+PD_iso_from :== 142
+
+PD_TypeUNIT :== 143
+PD_ConsUNIT :== 144
+PD_TypeEITHER :== 145
+PD_ConsLEFT :== 146
+PD_ConsRIGHT :== 147
+PD_TypePAIR :== 148
+PD_ConsPAIR :== 149
+PD_TypeARROW :== 150
+PD_ConsARROW :== 151
+
+PD_TypeConsDefInfo :== 152
+PD_ConsConsDefInfo :== 153
+PD_TypeTypeDefInfo :== 154
+PD_ConsTypeDefInfo :== 155
+PD_cons_info :== 156
+PD_TypeCONS :== 157
+PD_ConsCONS :== 158
+
+PD_isomap_ARROW_ :== 159
+PD_isomap_ID :== 160
/* StdMisc */
-PD_StdMisc :== 159
-PD_abort :== 160
-PD_undef :== 161
+PD_StdMisc :== 161
+PD_abort :== 162
+PD_undef :== 163
-PD_Start :== 162
+PD_Start :== 164
-PD_DummyForStrictAliasFun :== 163
+PD_DummyForStrictAliasFun :== 165
-PD_NrOfPredefSymbols :== 164
+PD_NrOfPredefSymbols :== 166
(<<=) infixl
(<<=) state val
@@ -200,6 +205,8 @@ where
<<- ("_undo_indirections", IC_Expression, PD_undo_indirections)
// MV..
<<- ("DynamicTemp", IC_Type, PD_DynamicTemp)
+// <<- ("Module", IC_Type, PD_ModuleType)
+ <<- ("_Module", IC_Expression, PD_ModuleConsSymbol)
// ..MV
// AA..
diff --git a/frontend/transform.icl b/frontend/transform.icl
index eafbc34..a8550f3 100644
--- a/frontend/transform.icl
+++ b/frontend/transform.icl
@@ -1103,12 +1103,16 @@ where
-> (fun_defs, symbol_table)
expandMacrosInBody :: [.FunCall] CheckedBody PredefinedSymbol /* MV ... */ !Int /* ... MV */ *ExpandState -> ([FreeVar],Expression,[FreeVar],[FunCall],/* MV ... */ !FunInfo, /* ... MV */ .ExpandState);
-expandMacrosInBody fi_calls {cb_args,cb_rhs} alias_dummy /* MV ... */ es_current_fun_index /* ... MV */ es=:{es_symbol_table,es_fun_defs}
+expandMacrosInBody fi_calls {cb_args,cb_rhs} alias_dummy /* MV ... */ es_current_fun_index /* ... MV */ es=:{es_symbol_heap,es_fun_defs}
// MV ...
# (fun_def=:{fun_info},es_fun_defs)
= es_fun_defs![es_current_fun_index]
+ # (max_index,es_symbol_heap)
+ = determine_amount_of_dynamics 0 fun_info.fi_dynamics es_symbol_heap
+ # (es=:{es_symbol_table,es_fun_defs})
+ = { es & es_symbol_heap = es_symbol_heap, es_fun_defs = es_fun_defs }
# cos_used_dynamics
- = createArray (length fun_info.fi_dynamics) False // means not removed
+ = createArray (inc max_index) False // means not removed
// ... MV
# (prev_calls, fun_defs, es_symbol_table)
@@ -1144,15 +1148,28 @@ where
# (EI_Dynamic _ id)
= expr_info
| cos_used_dynamics.[id]
- // cos_removed_dynamic means cos_used_dynamic
= (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
// ... MV
expandCheckedAlternative {ca_rhs, ca_position} ei