feat(rtl): common.ch aliases — ISNIL/ISARRAY/ISNUMBER and friends
Harbour's common.ch exposes classic Clipper type-check shorthands
via #translate rules that map to HB_IS* RTL functions:
#translate ISNIL(<x>) => ((<x>) == NIL)
#translate ISARRAY(<x>) => HB_ISARRAY(<x>)
#translate ISCHARACTER(<x>) => HB_ISSTRING(<x>)
... etc.
Five's preprocessor currently supports #translate only for lines
whose FIRST word is the rule keyword, not for substring matches
inside expressions. Real usage like `IF ISNIL(x)` fails the keyword
check (first word is IF, not ISNIL) and the rule never fires.
Rather than rewrite the PP substring engine (A2 scope), register
the nine short names as direct RTL symbols in register.go, each
pointing at the same Go function as its HB_IS* twin. ISMEMO maps
to HB_ISSTRING as a reasonable approximation for Five (no distinct
memo type at the VM level).
common.ch becomes a short stub that just #defines TRUE/FALSE/YES/NO
and documents where the ISxxx aliases live. DEFAULT / UPDATE
#xcommand forms remain unsupported pending A2.
Verified with /tmp/test_common.prg — ISNUMBER(42), ISCHARACTER("x"),
ISNIL(nilVar) all dispatch correctly. Analyzer still emits
"undeclared variable" warnings for the short names (the static
checker doesn't see runtime-registered RTL symbols) but the
generated code links and runs.
FiveSql2 43/43, Harbour compat 56/56, Go test ALL PASS.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
26
include/common.ch
Normal file
26
include/common.ch
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* common.ch — Five compatibility shim for Harbour's common.ch
|
||||
*
|
||||
* Harbour ships #translate-based aliases for ISNIL / ISARRAY /
|
||||
* ISNUMBER / ISCHARACTER / ISLOGICAL / ISDATE / ISBLOCK / ISMEMO /
|
||||
* ISOBJECT. Five registers those as direct RTL symbols in
|
||||
* hbrtl/register.go (each points at the same Go function as its
|
||||
* HB_IS* twin), so they work without any preprocessor translation
|
||||
* and without this include.
|
||||
*
|
||||
* This header stays as a stub so `#include "common.ch"` in ported
|
||||
* Harbour code doesn't error. The DEFAULT / UPDATE #xcommand forms
|
||||
* from Harbour's common.ch are not yet supported — use explicit
|
||||
* `IF xVar == NIL ; xVar := default ; ENDIF` until the preprocessor's
|
||||
* #xcommand marker handling is extended.
|
||||
*/
|
||||
|
||||
#ifndef HB_COMMON_CH_
|
||||
#define HB_COMMON_CH_
|
||||
|
||||
#define TRUE .T.
|
||||
#define FALSE .F.
|
||||
#define YES .T.
|
||||
#define NO .F.
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user