rexxref lists BEEP, DIRECTORY and FILESPEC with the other built-in functions,
but the interpreter does not have them in its table of built-in functions:
they are routines of the internal REXX package
(interpreter/runtime/InternalPackage.cpp), and they are found by the external
function search, after the program's own ::ROUTINEs and the exits. This
shows in several ways (trunk r13513):
say length("abc") -- 3: the ::ROUTINE below is not called
say filespec("n", "/a/b.c") -- MY FILESPEC
::routine length; return "MY LENGTH"
::routine filespec; return "MY FILESPEC"
- A
::ROUTINE of the same name replaces them, which it cannot do for a
built-in function.
- Their argument errors are 88.9xx, with a "Compiled routine" line in the
traceback, instead of the 40.xxx of the built-in functions:
filespec("n") gives 88.901, left("abc") gives 40.3.
- They go through the CALL method of a security manager ([#1885]), and
through RXFNC exits and the macrospace.
RxFuncQuery("FILESPEC") returns 0, as for a registered external
function; RxFuncQuery("LENGTH") returns 1.
- They are about 500 times slower than a built-in function: a million
calls to FILESPEC take 40 seconds, against 0.08 for SUBSTR. Almost all of
it is a round trip to rxapi on every call, the macrospace query of the
external search.
The patch (on [r13513]; main, test and docs):
- BEEP, DIRECTORY and FILESPEC are added to the built-in function table,
at the end, since compiled programs store these codes. A compiled program
that uses them requires language level 6.07, so 5.2.0 refuses it with
3.903 instead of crashing.
- Their argument errors are now those of the other built-in functions
(40.3, 40.4, 40.5, 40.12; 40.904 is unchanged). There was no 40.xxx
message for a range with limits (40.903 says "0-99"), so the patch adds
40.927, "BEEP argument 1 must be in the range 37 to 32767; found "36"",
with the generated files and the copy of errnums.xml in rexxref.
- Programs compiled by older releases call these functions as external
routines, so the routines of the REXX package stay, but only as thin
wrappers: the work is done in one place (BuiltinFunctionSupport), for
both. The wrappers keep their old errors, so a program compiled by an
older release behaves exactly as before, and one that is interpreted or
compiled with the patch sees the new errors. The routines are hidden from
RxFuncQuery and RxFuncAdd, so that these answer for the three what they
answer for LENGTH. They can be removed when MinimumLanguageLevel goes
past 6.06.
- Tests: the BEEP and FILESPEC groups are updated to the new error codes;
new DIRECTORY.testGroup and BuiltinSearchOrder.testGroup (a ::ROUTINE
does not replace them, an internal label does, no security manager CALL,
RxFuncQuery); and a language level test in rexxc.testGroup.
With the patch, a million FILESPEC calls take 0.10 seconds. The test suite
gives the same results as without it, except for the new and changed tests,
on Ubuntu (24,503 tests, the 9 failures of running as root) and on Windows
(24,748 tests, the usual 7 failures, plus the SysSleep timing test once).
Filed that as a RFE by mistake, should have been a bug.
Committed:
functions. [r13532] adds interpreter/expression/BuiltinFunctionSupport.hpp,
which was missing from [r13531] ([r13531] alone does not build).
new DIRECTORY.testGroup and BuiltinSearchOrder.testGroup, and a
language-level test in rexxc.testGroup.
Full test suite: Linux 24,825 tests and Windows 25,062 tests, with the same
failures as trunk without the change.
Related
Commit: [r13531]
Commit: [r13532]
Commit: [r13533]
Commit: [r13534]