Implementation notes
Back
Paragraphs and sections
There are two mechanisms of doing something (procedurally speaking) in
cobol:
- CALLs - normal procedural subroutines with RETURNs
- PERFORMs - do a paragraph or section and do an implicit return at the
end of the paragraph/section (weird, isnt'it?). The end of a paragraph is
marked by the beginning of another paragraph. (same with sections)
Our original implementation was to have a pair
(end-of-paragraph/beginning-of-paragraph) placed at the stack frame. Instead of
doing returns, we call a function to compute where we should go, by checking
the address limits of the stacked paragraph. Because we are going to generate C
code, we must be careful here, for the C compiler could do optimizations that
change those addresses.
The idea is better caught with an example:
DO_THIS.
<SOME COBOL STATEMENTS>
DO_THIS_OTHER.
<COBOL STATEMENTS>
PERFORM DO_THIS.
<MORE COBOL STATEMENTS>
The program will execute all statements after DO_THIS paragraph,
then follows to
DO_THIS_OTHER. When found PERFORM DO_THIS, it will do again
DO_THIS, but will return at the end of DO_THIS paragraph
(just before the beginning of DO_THIS_OTHER). The same applies with
sections, by grouping several paragraphs till the end of section.
Home