While the USING
phrase of PROCEDURE DIVISION
may only be used for CALL
ed programs, it would possible to add an extra layer which will only be activated if the program is the very first program of the run.
This layer should only be added upon explicit request (and would also allow to use -x
for those programs), get another internal funtion that would do the following before calling the actual "main" entry: for each given parameter (up to the maximum amount of parameters)
cob_field
defined within the function that matches the field in the LINKAGE USING
(not doing an ALLOCATE
of the LINKAGE
field as this would break recursive program calls) and also have a local data field for eachFUNCTION TRIM (argv[n] TRAILING)
or FUNCTION NUMVAL (argv[n])
- depending on the class of the target field "n"MOVE
from the temporary field to the local one
Discussion: CALLing main programs
Discussion: error: executable program requested but PROCEDURE/ENTRY has USING clause zOS compatibility ?
Wish List: #358
Wish List: #471
Attached is an initial patch for this. It effectively adds a wrapper for the program within
main
. The program is compiled as normal (with-x
) and, when executed, is passed the first argument from the command-line.To do:
cobcrun
.PARM
orCOB_PARM
instead?Related
Discussion: c352ac53b1
Last edit: Edward Hart 2020-07-02
Edward, it seems like you've mixed this FR with [feature-requests:#358].
They are very related and it would be useful to either implement or at least prepare them together, but they are still separate.
Related
Wish List: #358
I've rechecked the standard on this, the current draft says (unchanged) under 14.2 Procedure division structure, general rule 13:
And we do see that different COBOL environments handle this differently, starting with forbidding, ending with different set of "magic" rules.
Therefore this topic "main and linkage" (-fmain-linkage=enum) should be handled as dialect option with providing at least the values:
-x
, would be set in all "standard" COBOL dialects): common warning (which is raised because of likely portability issues), then go an as-if "mapping" was active-x
and is the current behaviour), if-x
was not used the code generation would stay as-isCHAINGING
(I'm not sure if we already do it that way):FUNCTION CONTENT-OF
or manuallyUNSTRING .. DELIMITED BY LOW-VALUE
In any case the check "am I the first program" and then the "trigger" to setup the parameters depending on the value of the main-linkage dialect option should be generated, the actual functions that handle this (in cases "mapping" and "chaining" passing the fields as vararg) should be found in libcob/call.c
Related
Wish List: #358
Last edit: Simon Sobisch 2020-07-09
Attached is a quick update.
main-linkage
option as above, but with "mapping" renamed to "parm" - I think the IBM terminology will be more familiar to users.COMMANDLINELINKAGE
directive.It remains to extract all the new codegen code to a new function in libcob/call.c.
The actual handling of the
parm
value and theCMDLINELINKAGE
directive is noted in [feature-requests:#358] - mapping is very different from this as this maps possibly multiple entries directly ´(similar toCHAINING
but the variables included inLINKAGE
and internallyMOVE
d to from intermediate fields, possibly with a numeric conversion).Please keeo those "mapping", what this FR was initialially about and "parm" logically separate (I'm also fine with a single commit implementing both FR at once, they are obviously very related).
The new config option (otherwise than the missing first entry "mapping") is fine, for acu.conf it seems it should be set to error, at least from its documentation. RM/COBOL and Realia looks fine, I've just dropped a quote from its doc in the other FR.
I've not checked any part of the codegen yet, but here's a test case for the
mapping
value:Related
Wish List: #358
Patch version 3:
Thanks for this! I hadn't seen the difference between #357 and #358 before you mentioned this. Well, I'll keep posting patches here for consistency's sake.
I think chaining is right - General Rule 6 describes how
CHAINING
works. Is that not what-fmain-linkage=chaining
should do?Related
Wish List: #358
I'm fine with the patch-posting here, as long as the differences are clear :-)
Yes,
CHAINING
behaviour is what should happen for-fmain-linkage=chaining
, which is (according to the MF docs) what MF does, but ACUCOBOL explicit specifies thatLINKAGE
may not be used for main programs andCHAINING
only for main programs, which is why I think it should be an error there)So... what are the thing you want to add to this patch and what rough time estimate do you have for this?
I think I've basically done [feature-requests:#358] now, so I would like to commit the patch as-is.
As for what to do next:
CHAIN
or (RM/COBOL)CALL PROGRAM
statementsRelated
Wish List: #358
Last edit: Edward Hart 2020-07-11
CHAIN
/CALL PROGRAM
would be nice but should be definitely kept out here. If we don't have a FR for this please create it. You're inbited to handle it, of course, but that's not mandatory.I think it would be something like:
STOP RUN
(we'd have to check if the file tear-down should be done or the file states have to be kept)For
-fmain-linkage=chaining
we'd have to condidtionally call the wrapper (= the default is the normalLINKAGE
handling but if it is the first module then the handling we normally only generate forCHAINING
gets activated).I think mapping should be relative easy and be possible in libcob/call.c:
PROCECDURE DIVISION USING
fields as vararg to the wrappercob_put_field_str
, if that returnsEINVAL
cob_move a zero to it.Patch version 4: cobcrun support added, with a new parameter
--param
. This is some ugliness:--param=parm-big-endian
or--param=parm-native
.EDIT: Forgot to attach the patch.
Last edit: Edward Hart 2020-07-17
Thank you for keeping working on this!
I need to inspect the patch to say something to this, so here only to your comments:
it should be completely supported to have PARM'd programs as modules, and you can actually CALL those on the mainframe, too.
The maximum size is whatever the maximum in the definitions from IBM I be copied here or in the related FR says.
The actual size passed to the program should be trimmed to the arguments size.
For the first iteration we should use the default endianness, and for a second one load the module only first (if we don't have a special entry point for that yet it should be added in any case) and then read a (possibly new) flag on the module structure specifying the expected endianness.
Rechecked with the patch: as noted before cobcrun should not get (nor need) a new param option - it will just do the initialization "as always" and the minimal difference in the codegen (according to the compile option) will recognize "I'm main" and ask libcob for the necessary setup, and could also specify the expected endianness for PARM.
Just wondering: Why did you change output_line to a manual output + line in the one codegen place?