Menu

Commit [r13016]  Maximize  Restore  History

Make the P-code compiler and runner work; restore panel/form to the TUI link

P-code
------
P-code had never worked on a 64 bit build. bin/runner_fgl did not even get
built, and no 4GL module could be turned into p-code at all. It now compiles
and runs ordinary 4GL, and on the test programs used here its output is
byte-identical to the C backend.

The runner would not build: compilers/pcode/fgl_calls.h registered
&A4GLSTK_pushFunction, the v1 stack API, which was retired and is now a poison
macro in a4gl_4gl_callable.h. Updated to pushFunction_v2 / popFunction_nl - the
handlers for those shapes already existed. A4GL_swap_bind_stmt was also
declared char** in a4gl_sql.h and void** in a4gl_4gl_callable.h, so anything
including both headers could not compile; the implementation only saves and
restores an opaque struct BINDING *, so void** is correct.

Sizes and signs, all 64 bit issues:

* a4gl_htonl/a4gl_ntohl returned htonl()'s uint32_t as a long, which zero
extends on LP64, so every negative value written through the PACKED packer
came back positive - -1 read back as 4294967295. The x1element "no subscript"
marker was the first casualty. Fixed by sign extending through int32_t; the
bytes on disk are unchanged for values that fit in 32 bits, and readers only
look at the low 32 bits, so existing files still read correctly. The magic
numbers (0xa4fc2345 and friends) have their top bit set, so the two places
that compare them now do so at 32 bits.

* The p-code type model said a long and a pointer were 4 bytes while the runner
reads and writes both through a C long. Widening it alone was not enough:
get_var_ptr reported only a size, and the read/write dispatch keyed off it
with 4 meaning long and 8 meaning double - so an 8 byte slot looked like a
double and every variable read back as garbage. get_var_ptr now reports the
dtype as well, each width is read and written as itself, and DLONG/DDBL/DPTR
are sized from the real C types. This is what fixed accumulation across a
loop, char variables corrupting the heap, and the lost first element of an
array initialiser.

* A string literal's address was cast through (int) in common_eval.c, which
truncated it and crashed printf.

The p-code compiler skips every '#' line, so it never sees a #define. NULL,
LABEL_USED, fglvarchar, the 34 OP_* codes and the REPORT_* codes were all
unknown to it. The OP_* and REPORT_* values now come from the real macros via
compilers/pcode/op_lookup.c rather than being copied, so they cannot drift -
which is exactly what had happened to the predefined BINDING struct, six
members against the header's seven, and to REPORT_NOTHING.

A4GL_push_long and A4GL_push_int were still keyword-bound to constants, but
generated code pushes variables far more often. Retired the same way
A4GL_push_char and A4GL_push_variable already had been, so they resolve
through the runner's call table.

An unspecified array bound is held as -1, which was multiplied into a negative
total_size - and that is what the runner mallocs for a static, so loading any
module with a "char x[]=..." aborted. Sizes are now taken from the initialiser
where one is given.

On the generator side, several things emitted only for the C backend are not
parseable by p-code's cut down C grammar, and are now suppressed when
A4GL_doing_pcode(): forward declarations for functions, reports and MAIN;
the version helper (which lacks the A4GL_FUNCTION marker p-code requires);
and "(void) x;" between two declarations, which p-code's C89 grammar rejects.
_objData is emitted before the locals for the same reason. ERRCHK now passes
the module name as a string literal, which is what the grammar wants.
MARK_SCOPE_MODULE, which p-code switched on, prefixed declarations but not
uses, emitting "long L_total;" alongside "total=0;" in the same function.

Suppressing the MAIN prototype means an ordinary "MAIN ... END MAIN" program
now compiles to p-code, removing the constraint documented in
compilers/pcode/README.

TUI link
--------
m4/aubit_ui.m4 substituted CURSES_LIB_NAME="-lncurses". The old configure.in
set "-lform -lpanel -lncurses", and ui_curses/Makefile.in still expands
@CURSES_LIB_NAME@, so the rewrite alone dropped panel and form and left
libUI_TUI.so with an undefined update_panels - the TUI driver could not load,
which is why so much had to be run in CONSOLE mode. configure now detects
panel and form and lists them dependents-first.

Testing
-------
aubit4gltest, all 21 ranges, -esqli -tui, against a build of r12988 (the last
revision before the configure rewrite):

r12988 1098 run, 59 skipped, 35 failed
this 1098 run, 59 skipped, 33 failed

The two differences are tests 706 and 1413. Run individually, 706 passes on
both (it is flaky in batch), and 1413 - logical report layout - fails on
r12988 and passes here. No regressions.

For reference, with the TUI driver broken these runs managed 283 tests with
449 skipped and five ranges hanging on menu tests looping on EOF.

mikeaubury 2026-08-31

changed /aubit4glsrc/trunk/compilers/fcompile/decompile_extjs.c
changed /aubit4glsrc/trunk/compilers/pcode/Makefile
changed /aubit4glsrc/trunk/compilers/pcode/checker_read.c
changed /aubit4glsrc/trunk/compilers/pcode/common_eval.c
changed /aubit4glsrc/trunk/compilers/pcode/compiler_main.c
changed /aubit4glsrc/trunk/compilers/pcode/compiler_variables.c
changed /aubit4glsrc/trunk/compilers/pcode/fgl_calls.h
changed /aubit4glsrc/trunk/compilers/pcode/lex.pregen.c
changed /aubit4glsrc/trunk/compilers/pcode/link.c
changed /aubit4glsrc/trunk/compilers/pcode/npcode_defs.h
added /aubit4glsrc/trunk/compilers/pcode/op_lookup.c
changed /aubit4glsrc/trunk/compilers/pcode/runner_execute.c
changed /aubit4glsrc/trunk/compilers/pcode/runner_main.c
changed /aubit4glsrc/trunk/compilers/pcode/set_var.c
changed /aubit4glsrc/trunk/compilers/pcode/simple.lex
changed /aubit4glsrc/trunk/configure
changed /aubit4glsrc/trunk/incl/a4gl_sql.h
changed /aubit4glsrc/trunk/lib/libaubit4gl/ns.c
changed /aubit4glsrc/trunk/lib/libaubit4gl/sql_common.c
changed /aubit4glsrc/trunk/lib/liblex/lex_esqlc/class.c
changed /aubit4glsrc/trunk/lib/liblex/lex_esqlc/compile_c.c
changed /aubit4glsrc/trunk/lib/liblex/lex_esqlc/compile_c.h
changed /aubit4glsrc/trunk/lib/liblex/lex_esqlc/dump_report.c
changed /aubit4glsrc/trunk/lib/liblex/lex_esqlc/err_hand.c
changed /aubit4glsrc/trunk/m4/aubit_ui.m4
/aubit4glsrc/trunk/compilers/fcompile/decompile_extjs.c Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/compilers/pcode/Makefile Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/compilers/pcode/checker_read.c Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/compilers/pcode/common_eval.c Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/compilers/pcode/compiler_main.c Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/compilers/pcode/compiler_variables.c Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/compilers/pcode/fgl_calls.h Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/compilers/pcode/lex.pregen.c Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/compilers/pcode/link.c Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/compilers/pcode/npcode_defs.h Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/compilers/pcode/op_lookup.c Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/compilers/pcode/runner_execute.c Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/compilers/pcode/runner_main.c Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/compilers/pcode/set_var.c Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/compilers/pcode/simple.lex Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/configure Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/incl/a4gl_sql.h Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/lib/libaubit4gl/ns.c Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/lib/libaubit4gl/sql_common.c Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/lib/liblex/lex_esqlc/class.c Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/lib/liblex/lex_esqlc/compile_c.c Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/lib/liblex/lex_esqlc/compile_c.h Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/lib/liblex/lex_esqlc/dump_report.c Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/lib/liblex/lex_esqlc/err_hand.c Diff Switch to side-by-side view
Loading...
/aubit4glsrc/trunk/m4/aubit_ui.m4 Diff Switch to side-by-side view
Loading...