I found another method to achieve the final goal by checking if an argument is given when a program is called. This way if the program is run directly, no argument will be provided (routine depth=0). However, if the program is called from another program then an arbitrary argument can be provided to indicate a subcall (routine depth > 0).
Here is the argument checker program in Karel.
Code
PROGRAM argexists
%NOBUSYLAMP
%COMMENT = 'args checker'
%NOLOCKGROUP
%NOPAUSE = COMMAND + TPENABLE + ERROR
%include display.klt
%include registers.klt
CONST
ARG_FALG_NO = 74
ARG_DOES_NOT_EXIST = 17042
VAR
str_value : STRING[16]
real_value : REAL
param_no : INTEGER
data_type : INTEGER
int_value : INTEGER
status : INTEGER
%include strings.klh
%include registers.klh
BEGIN
-- check if arg exists in a program call
param_no = 1
data_type = 0
int_value = 0
real_value = 0.0
str_value = ''
status = 0
GET_TPE_PRM(param_no, data_type, int_value, real_value, str_value, status)
-- WRITE TPDISPLAY(str_parse('status: ' + i_to_s(status), MAX_DISPLAY_LENGTH), CR)
IF status = ARG_DOES_NOT_EXIST THEN
registers__set_io(io_flag, ARG_FALG_NO, FALSE)
ELSE
IF status = 0 THEN
registers__set_io(io_flag, ARG_FALG_NO, TRUE)
ENDIF
ENDIF
END argexists
Display More
This can be used as follows:
Code
/PROG TST
/ATTR
COMMENT = "XXX Rev A";
TCD: STACK_SIZE = 0,
TASK_PRIORITY = 50,
TIME_SLICE = 0,
BUSY_LAMP_OFF = 0,
ABORT_REQUEST = 0,
PAUSE_REQUEST = 0;
DEFAULT_GROUP = *,*,*,*,*;
/APPL
/MN
: ! check call depth ;
: CALL ARGEXISTS(AR[1]) ;
: IF (!F[74:arg_exists]) THEN ;
: R[64:tsk_label]=999 ;
: ENDIF ;
: JMP LBL[R[64]] ;
Display More