![]() |
femtolisp in the browser | ![]() |
The browser version of TeXmacs (the Vue interface compiled to WebAssembly, see
docs/wasm/README.md
) can be built with femtolisp instead of S7. femtolisp compiles for 32-bit WebAssembly as it is: its fixnums have 30 bits there, and larger integers are boxed.
. misc/wasm/emenv.sh build-wasm
make -C build-wasm -f ../misc/wasm/Makefile -j8 SCHEME=femtolisp web |
With SCHEME=femtolisp,
misc/wasm/Makefile
replaces the sources of S7 by
fl_core.c
,
fl_llt.c
and
femtolisp_tm.cpp
, and defines USE_FEMTOLISP;
misc/wasm/config.h
then leaves USE_S7 out. The objects go to build-wasm/obj-femtolisp and the page to build-wasm/out-femtolisp/web, so a tree can hold both builds; without the option, the build is the one of S7, in build-wasm/obj and build-wasm/out. The target node makes the program for node, build-wasm/out-femtolisp/node/texmacs.js.
The files which TeXmacs reads before it starts are in the boot package of the page:
misc/wasm/boot-files.txt
lists the four files of femtolisp (
init-femtolisp.scm
and the three of
kernel/boot
) besides those of S7.
Without a cache, the first visit of the page would compile all the code it loads. So the build makes the caches of compiled code (see the lazy bodies and the caches) and ships them in the boot package, as /texmacs/cache/femtolisp, where
boot-femtolisp.scm
reads them: for each file of which the home of the page has no valid cache, and always for the function bodies, before those of the home.
The target femtolisp-cache of
misc/wasm/Makefile
, made at every build of the page with femtolisp, runs the program for node on
misc/wasm/femtolisp-cache.scm
: it loads what TeXmacs loads at its start and when all the menus are opened, in text and in math. The same compiler, in WebAssembly, makes the code which the page will run.
Its cache is copied to build-wasm/femtolisp-cache (the .flc and the .lazy files of the files of TeXmacs, whose names start with TM%).
misc/wasm/package.py
takes a fourth argument, <dir>:<prefix>, which adds the files of a directory to those of the page: here build-wasm/femtolisp-cache:cache/femtolisp. cache/ is one of the groups of the boot package.
The shipped cache makes the boot package about 0.9 MB larger (compressed with brotli), and the first visit about a second shorter (3.1 s instead of 4.2 s: without it, the first visit compiles the code and writes the cache). What the page compiles anyway goes to the cache of its home, in the storage of the browser.
web-javascript, web-files, web-open-pdf, web-open-external and web-paste-dialog are defined in
src/Plugins/Vue/vue_gui.cpp
on the interface of the interpreters (tmscm_install_procedure, TMSCM_ASSERT, string_to_tmscm): one definition for S7 and femtolisp. A new function of this kind must be written the same way, not with the functions of one interpreter.
Sets a variable of the environment of TeXmacs (
misc/wasm/web-pre.js
); it may be given several times. For instance ?env=TEXMACS_FL_TRACE=1, or ?env=TEXMACS_FL_NO_CACHE=1.
Evaluates Scheme code and returns its value as text (
misc/wasm/javascript.js
): TeXmacs.scheme ("%cache?") tells whether the caches are used.
misc/wasm/browser-run.mjs
Runs a page in a browser without a window, with a script of actions (wait, click, type, key, shot, eval). Its option --dir gives the page (build-wasm/out-femtolisp/web), --profile a profile of the browser kept between the runs (the home of the page), --query what follows the address, and --timeout the seconds an eval may take (180 by default).
The regression suites run in the page with the script
wait 8000
eval TeXmacs.scheme("(run-all-tests)") |
and --timeout 1800. A page cannot do all that the suites check: with S7 ten suites have failing checks there, and femtolisp fails the same ones, with its two own (htmltm, graphics-edit); one group of math-edit fails with other checks than with S7. Compare the failing checks of the two pages, not their number. A check on fonts may fail in a new profile, while the fonts are fetched.
When measuring, give each option of browser-run.mjs as words of its own (--query and its value are two arguments), and check in the page that an option which changes what is measured was taken: a comparison of the page with and without the caches once measured the same page twice.
The start of the page, as it reports it (the time of its first drawing): with femtolisp about 3.1 s at the first visit and 1.2 s at the later ones, with S7 about 2.8 s and 1.05 s. With the code of the caches removed, femtolisp would need 3.6 s and 1.55 s. The program is 0.7 MB smaller with femtolisp (23.5 MB against 24.2 MB). The measurements are in
docs/femtolisp/10-benchmarks.md
.