Flowlog CLI and REPL (flowlog.c)

This document describes the Flowlog command-line interface and REPL behavior for the binary built from flowlog.c.

The Flowlog binary is:

Code references (section markers in flowlog.c):

CLI usage

Show help (SUBSECTION 26.1):

./flowlog --help

Show version (SUBSECTION 26.1):

./flowlog --version

Interactive REPL (default)

Empty program:

./flowlog

Load a program and enter REPL:

./flowlog program.pl

Load multiple programs and enter REPL:

./flowlog program1.pl program2.pl
./flowlog -l program1.pl -l program2.pl

Explicit load flag(s):

./flowlog -l program.pl
./flowlog --load program1.pl

Fast startup (skip RC file):

./flowlog -f
./flowlog --fast

Run a one-shot query

./flowlog -g "goal." program.pl

Query against an empty program:

./flowlog -g "goal."

System args vs app args

Read application argv from Prolog:

?- current_prolog_flag(argv, Argv).

Flowlog returns Argv as a list of Prolog strings (for example ["-p","123","--help"]). When called from a predicate defined in a loaded file, argv resolves to that file segment’s args. At the top level (for example ?- current_prolog_flag(argv, A).), it resolves to the default segment (first positional file, or [] if none).

Examples:

./flowlog -g "run." file.pl -g localhost
# system query is: run.
# application argv for file.pl is: ["-g","localhost"]
./flowlog --engine tree proxy.pl --path=/tmp/proxy.conf https_proxy.pl --path=/tmp/https.conf
# argv for proxy.pl is: ["--path=/tmp/proxy.conf"]
# argv for https_proxy.pl is: ["--path=/tmp/https.conf"]

Thread count

Override the worker-thread count:

./flowlog --threads 12 -g "goal." program.pl

Aliases accepted by the binary:

Engine selection

Select the execution engine (SUBSECTION 26.1):

./flowlog --engine wamvm -g "goal." program.pl

Values:

If wam or wamvm is requested but Flowlog falls back to the interpreter, it prints a warning to stderr by default (SECTION 24). Disable this warning with:

To ensure the wamvm engine does not fall back to the WAM-lite solver for unsupported programs/queries, set (SECTION 24):

You can also introspect which engine actually ran a query (SECTIONS 22/23/24):

?- current_prolog_flag(flowlog_engine_active, Engine).

Parallel profile

Select a parallelism profile (equivalent to set_prolog_flag(flowlog_parallel_profile, ...)) (SUBSECTION 26.1 and SECTIONS 22/23/24):

./flowlog --parallel-profile fast -g "goal." program.pl

Values:

Defaults (unless your program overrides flags with :- set_prolog_flag/2 directives):

Tracing

Enable Prolog-style trace ports (CALL/EXIT/REDO/FAIL) on stderr (SUBSECTION 26.1):

./flowlog --trace -g "goal." program.pl

Enable internal (C/VM) tracing on stderr (SUBSECTION 26.1):

./flowlog --itrace -g "goal." program.pl

Only emit internal trace lines when C stack usage reaches a new peak (SUBSECTION 26.1 and SECTION 06):

./flowlog --itrace-watermark -g "goal." program.pl

Throw a catchable exception before a hard C-stack SIGSEGV overflow (SUBSECTION 26.1 and SECTION 06):

./flowlog --cstack-limit 32MB -g "goal." program.pl

--cstack-limit accepts raw bytes or a K/M/G suffix (optionally followed by B), for example 65536, 64K, 8MB.

If you still hit a SIGSEGV (for example due to a true C stack overflow), you can enable a best-effort crash dump of the last recorded trace frames (SUBSECTION 26.1 and SECTION 06):

./flowlog --segv-trace -g "goal." program.pl

Notes:

REPL behavior

Prompts and non-interactive mode

Meta-commands

The REPL supports a small set of meta-commands (single-line, no trailing . required):

And the ISO-style “regular” commands:

Loading code interactively

The REPL supports the common Prolog top-level convenience:

Use one of:

Output format

Flowlog prints output in a stable, test-friendly format (SECTION 17):

Environment variables

Tracing / stack debugging

Main stack sizing (Linux / small RLIMIT_STACK)

Some systems (notably Linux) default to a small main-thread stack (often 8 MiB). Deep interpreter recursion (for example when running quad tests in --engine tree) can exhaust this stack.

Flowlog can automatically run its main loop on a dedicated pthread with a larger stack:

Compile-time depth limits

Flowlog also supports compile-time depth-limit overrides in SECTION 01:

Example:

cc -O2 -Wall -Wextra -pthread \
  -DFLOWLOG_DEPTH_LIMIT=4096 \
  -DFLOWLOG_SOLVE_DEPTH_LIMIT=200000 \
  flowlog.c -lm -o flowlog

History

RC startup file

RC side-effect settings must be written as directives so they execute at load time, for example:

:- set_prolog_flag(flowlog_engine, wam).

Parallelism tuning

Debugging OR-par

Exit codes