GNU TeXmacsUser manualReferenceAboutEnglish
femtolisp: debugging, testing and common tasks

1.Environment variables

TEXMACS_FL_TRACE=1

An error which reaches the C++ code is reported with the error of femtolisp and its stack. With TEXMACS_FL_TRACE=catch, the errors caught by catch are reported too: many are expected, since TeXmacs tests things inside catch.

TEXMACS_FL_CHECK_ROOTS=1

Checks every tmscm of the list of roots at each collection. Use it when a crash looks like a value which moved.

TEXMACS_FL_PROFILE=1

Times the reading, the expansion and the compilation of the loaded files. (%profile-report) prints the totals and the hits of the cache, (%profile-heads-report) the expansion time by the first symbol of the forms, (%lazy-report) the number of stubs and of first calls.

TEXMACS_FL_NO_CACHE=1

Runs without the caches of compiled code.

TEXMACS_FL_EAGER=1

Expands and compiles the function bodies when a file is loaded, with the late calls and the deferred errors of macros.

TEXMACS_FL_HEAP=n

The size of each half of the heap at start, in MB.

Also (%gc-count), the number of collections so far, (%gc) and (%heap-size).

2.Reading an error

The stack printed with TEXMACS_FL_TRACE lists the calls with their arguments, the innermost first: at most 20 frames, with long arguments cut. A function which was left by a tail call does not appear. A frame (lambda …) is a function without a name, such as a function made by tm-define. A let has no frame: its variables are in the frame of its function (patch 0035), and do not appear. An argument which a closure captures and which is assigned shows as its box, a list of one element (patch 0034). A private function shows under its plain name f, not f@a/b: only the global variable which holds it is renamed. A frame (%lazy-compile (lambda …) …) means that the error came while a body was being compiled at its first call: the error is in that body, often a macro which failed to expand, and the function is the frame which follows, with its arguments in one list.

Unbound variable: f, for an f which is defined

The name may be private to another module, or defined later than its use at the top level of a file. Look for f@… in (environment).

A wrong number of arguments for a builtin (equal?: too many arguments)

Often the reader: an octal character of Guile, #\04, is read as two data.

A crash in the collector, or values which change

A raw fltm_value kept across an allocation, or a longjmp over a C++ function. Run with TEXMACS_FL_CHECK_ROOTS=1.

Something is defined although its condition is false

A macro at the top level of a file with an effect when it is expanded.

A change of a Scheme file seems ignored

It should not happen: the caches follow the expansion of each form. If it does, run with TEXMACS_FL_NO_CACHE=1 to tell whether the cache is the cause, and see whether %cache-format should have been increased.

3.Looking inside

;; the source of a function, called or not
(procedure-source f)
;; its bytecode (that of a stub before its first call)
(disassemble f)
;; a private function of the module (a b)
(top-level-value (symbol "f@a/b"))
;; the private names of a module
(module-symbols (resolve-module '(a b)))
;; the late calls, with TEXMACS_FL_TRACE and TEXMACS_FL_EAGER
(%late-calls)

write shows a function as #<procedure f>; bind *print-closures* to #t to see its code and constants.

4.Testing

TEXMACS_PATH=$PWD/TeXmacs TEXMACS_HOME_PATH=<a scratch directory> \
  TeXmacs/bin/texmacs.bin -headless -x '(exit (catch #t
    (lambda () (min 1 (run-all-tests)))
    (lambda args (display* "error: " args "\n") 2)))' -q

runs the regression suites of

progs/check

with the Vue interface, which needs -headless to run without a window (

tests/scheme/check.sh

does not pass it; with a Qt build, use that script with QT_QPA_PLATFORM=offscreen). The option -q must come after -x: the options are run in their order, and -q first would quit before the tests. (run-regression-suite "name") runs one suite. With femtolisp, two suites have failing checks (three in all, two of them in graphics-edit), which are not bugs of the interface:

Run the suites twice with the same scratch directory: the first run fills the caches of compiled code, the second one uses them. A change of

boot-femtolisp.scm

should be tested both ways, and with TEXMACS_FL_EAGER=1. The two suites boot-s7 and compat-s7 are for S7 and do not run with femtolisp.

The benchmarks are the scripts of

docs/s7/bench

and

docs/femtolisp/bench/ui.scm

, run on several builds by

docs/femtolisp/bench/run.sh

. Compare builds by alternating them on the same machine, and take the times without a profiler: sampling slows femtolisp more than S7.

5.Common tasks

Adding a function of Guile which is missing

Define it in

compat-femtolisp.scm

with define-public, after checking that the glue does not define it. If the name is a builtin of femtolisp with another meaning, use define-override in

r5rs-femtolisp.scm

.

Adding a primitive in C

For a function of TeXmacs, add it to the glue, as for the other interpreters. For a function which only femtolisp needs, write it in

fl_core.c

with the signature of the builtins of femtolisp and add it to fltm_builtin_info; there, an error is raised with the functions of femtolisp (type_error, bounds_error, argcount; lerrorf for the others), since no C++ is involved.

Holding a Scheme value in C++

Keep it in a tmscm (or an object), never in a fltm_value.

Writing a macro

Its expansion must not register anything: return code which does it. The expansion must not contain a call of the macro itself with the same arguments.

Changing how files are loaded or compiled

The code is in

boot-femtolisp.scm

. Increase %cache-format if the same expansion now compiles to other code, test with and without the caches, and measure a boot with TEXMACS_FL_PROFILE=1.

Changing femtolisp itself

See its sources and their patches.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".