diff --git a/lang/m2/comp/code.c b/lang/m2/comp/code.c index 3ee7958e9..d2be27d0e 100644 --- a/lang/m2/comp/code.c +++ b/lang/m2/comp/code.c @@ -311,8 +311,8 @@ CodeCall(nd) and result is already done. */ register t_node *left = nd->nd_left; - register t_node *right = nd->nd_right; register t_type *result_tp; + int needs_fn; if (left->nd_type == std_type) { CodeStd(nd); @@ -321,8 +321,8 @@ CodeCall(nd) assert(IsProcCall(left)); - if (right) { - CodeParameters(ParamList(left->nd_type), right); + if (nd->nd_right) { + CodeParameters(ParamList(left->nd_type), nd->nd_right); } switch(left->nd_class) { @@ -333,11 +333,13 @@ CodeCall(nd) if (level > 0) { C_lxl((arith) (proclevel - level)); } + needs_fn = left->nd_def->df_scope->sc_defmodule; C_cal(NameOfProc(left->nd_def)); break; }} /* Fall through */ default: + needs_fn = 1; CodePExpr(left); C_cai(); } @@ -350,7 +352,7 @@ CodeCall(nd) } else C_lfr(sz); } - DoFilename(); + DoFilename(needs_fn); DoLineno(nd); } diff --git a/lang/m2/comp/defmodule.c b/lang/m2/comp/defmodule.c index 59a189afa..db3090f0f 100644 --- a/lang/m2/comp/defmodule.c +++ b/lang/m2/comp/defmodule.c @@ -93,7 +93,7 @@ GetDefinitionModule(id, incr) t_scopelist *vis; char *fn = FileName; int ln = LineNumber; - t_scope *newsc = CurrentScope; + t_scope *newsc; level += incr; df = lookup(id, GlobalScope, D_IMPORTED, 0); @@ -105,13 +105,14 @@ GetDefinitionModule(id, incr) ForeignFlag = 0; DefId = id; open_scope(CLOSEDSCOPE); + newsc = CurrentScope; vis = CurrVis; + newsc->sc_defmodule = incr; if (!strcmp(id->id_text, "SYSTEM")) { do_SYSTEM(); df = lookup(id, GlobalScope, D_IMPORTED, 0); } else { - newsc = CurrentScope; if (!is_anon_idf(id) && GetFile(id->id_text)) { DefModule(); diff --git a/lang/m2/comp/scope.h b/lang/m2/comp/scope.h index 03725dd28..4809dd220 100644 --- a/lang/m2/comp/scope.h +++ b/lang/m2/comp/scope.h @@ -28,6 +28,9 @@ struct scope { struct def *sc_def; /* list of definitions in this scope */ arith sc_off; /* offsets of variables in this scope */ char sc_scopeclosed; /* flag indicating closed or open scope */ + char sc_defmodule; /* flag set is this scope is from a separate + definition module + */ int sc_level; /* level of this scope */ struct def *sc_definedby; /* The def structure defining this scope */ struct node *sc_end; /* node to remember line number of end of scope */ diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index 1a429bebf..97e434902 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -117,12 +117,12 @@ DoLineno(nd) } } -DoFilename() +DoFilename(needed) { static label filename_label = 0; - oldlineno = 0; - if (! options['L']) { + oldlineno = 0; /* always invalidate remembered line number */ + if (needed && ! options['L']) { if (! filename_label) { filename_label = 1; @@ -185,7 +185,7 @@ WalkModule(module) for (; nd; nd = nd->nd_left) { C_cal(nd->nd_def->mod_vis->sc_scope->sc_name); } - DoFilename(); + DoFilename(1); } WalkDefList(sc->sc_def, MkCalls); proclevel++; @@ -230,7 +230,12 @@ WalkProcedure(procedure) C_ms_par(procedure->df_type->prc_nbpar); TmpOpen(procscope); DoPriority(); - DoFilename(); /* ??? only when this procedure is exported? */ + /* generate code for filename only when the procedure can be + exported, either directly or by taking the address. + This cannot be done if the level is not zero (because in + this case it is a nested procedure). + */ + DoFilename(! procscope->sc_level); func_type = tp = RemoveEqual(ResultType(procedure->df_type));