mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-15 09:23:44 +00:00
Finalize tail recursion with loop control.
compiler/par_conj_gen.m:
Make the generated code for copying the stack frame conform to the
macros I've provided in the runtime system.
runtime/par_builtin.h:
Correct bugs in the runtime code for manipulating stack frames.
This commit is contained in:
@@ -457,24 +457,23 @@ copy_slots_to_child_stack(FrameSize, LCVarLocn, LCSVarLocn, StackSlots,
|
||||
unexpected($module, $pred, "cannot convert to string")
|
||||
),
|
||||
|
||||
BaseVarName = "BaseSp",
|
||||
FirstLine = "{\n",
|
||||
DeclLine = string.format("\tMR_Word *%s;\n", [s(BaseVarName)]),
|
||||
AssignLine = string.format("\t%s = MR_lc_child_stack_sp(%s, %s, %d);\n",
|
||||
[s(BaseVarName), s(LCVarName), s(LCSVarName), i(FrameSize)]),
|
||||
list.map(copy_one_slot_to_child_stack(BaseVarName),
|
||||
IncrLine = string.format("\tMR_lc_inc_worker_sp(%s, %s, %d);\n",
|
||||
[s(LCVarName), s(LCSVarName), i(FrameSize)]),
|
||||
list.map(copy_one_slot_to_child_stack(LCVarName, LCSVarName),
|
||||
StackSlots, CopyStrs),
|
||||
string.append_list(CopyStrs, CopyLines),
|
||||
LastLine = "\t}\n",
|
||||
CodeStr = FirstLine ++ DeclLine ++ AssignLine ++ CopyLines ++ LastLine.
|
||||
CodeStr = FirstLine ++ IncrLine ++ CopyLines ++ LastLine.
|
||||
|
||||
:- pred copy_one_slot_to_child_stack(string::in, lval::in, string::out) is det.
|
||||
:- pred copy_one_slot_to_child_stack(string::in, string::in, lval::in,
|
||||
string::out) is det.
|
||||
|
||||
copy_one_slot_to_child_stack(BaseVarName, StackSlot, CopyStr) :-
|
||||
copy_one_slot_to_child_stack(LCVarName, LCSVarName, StackSlot, CopyStr) :-
|
||||
( StackSlotName = lval_to_string(StackSlot) ->
|
||||
( StackSlot = stackvar(N) ->
|
||||
CopyStr = string.format("\tMR_based_stackvar(%s, %d) = %s;\n",
|
||||
[s(BaseVarName), i(N), s(StackSlotName)])
|
||||
CopyStr = string.format("\tMR_lc_worker_sv(%s, %s, %d) = %s;\n",
|
||||
[s(LCVarName), s(LCSVarName), i(N), s(StackSlotName)])
|
||||
;
|
||||
unexpected($module, $pred, "not stack slot")
|
||||
)
|
||||
|
||||
@@ -530,15 +530,16 @@ extern MR_Bool MR_lc_try_get_free_slot(MR_LoopControl *lc,
|
||||
do { \
|
||||
MR_Context *ctxt; \
|
||||
\
|
||||
ctxt = (lc)->MR_lc_slots[lcs_idx].MR_lcs_context; \
|
||||
MR_lcs_context->MR_ctxt_sp += N; \
|
||||
ctxt = ((MR_LoopControl*)lc)->MR_lc_slots[lcs_idx].MR_lcs_context; \
|
||||
ctxt->MR_ctxt_sp += N; \
|
||||
} while (0);
|
||||
|
||||
/*
|
||||
** Access a slot on the stack of the worker context in the loop control slot.
|
||||
*/
|
||||
#define MR_lc_worker_sv(lc, lcs_idx, N) \
|
||||
MR_based_stackvar((lc)->MR_lc_slots[lc_idx].MR_lcs_context->MR_ctxt_sp, (N))
|
||||
MR_based_stackvar(((MR_LoopControl*)lc)->MR_lc_slots[lcs_idx]. \
|
||||
MR_lcs_context->MR_ctxt_sp, (N))
|
||||
|
||||
/*
|
||||
** Try to spawn off this code using the free slot.
|
||||
|
||||
Reference in New Issue
Block a user