summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/expl3/test3.tex
blob: 8d3630839bb43b61c048a42efe93cbf1212dbea2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
\documentclass{article}

\usepackage{l3precom}

% let's dump what is known about the LaTeX internals so far.
% this will not be much as the very basic stuff doesn't get
% dumped and we haven't got anything else.
%
\dumpLaTeXstate{test1}

\CodeStart

% we need some variants of tlp_set which are not yet
% defined for use in the code below.
%
\exp_def_form:nnn{tlp_set}{Nn}{on}
\exp_def_form:nnn{tlp_gset}{Nn}{on}

% okay, here we either load a dump file (testdump.cmp)
% and then jump tp \cs_dump: or we compile one for next time.
% don't forget that if you change code below it will only have any
% affect if a new dump file is written so you may have to remove
% the existing one.
%
\cs_load_dump:n{testdump}

% two test definitions
%
\def_new:Npn\foo{some foo}
\def_new:Npn\baz{some baz}

% we say that \foo should be dumped in the compiled style.
% this is pretty useless as it is certainly not faster than defining
% it in the first place. but this is only done for showing that it
% works. just assume that \foo is actually a pretty difficult
% definition which does need a lot of static compilation due to
% parsing, comparing values, etc., so that it is much faster load the
% final version rather than do the compilation each time again.
%
% btw note that \baz is not dumped and will not be available in the
% production run (ie the one using the cmp file)
%
\cs_record_name:N\foo

% get our self a scratch register (again this will not be available in
% the production run)
%
\tlp_new:Nn\l_scratch_tlp{}

% now we generate a unique cs name and assign it the string "foo".
% again pretty useless example. but with this mechansim you can build
% complex graph structures etc using these names as pointers, etc. and
% in such a case you need to dump the state of your graph at some
% point to be able to load it very fast in production.
%
\cs_gen_sym:N\l_scratch_tlp{}
\tlp_set:on \l_scratch_tlp {foo}

% ditto for a global unique name
%
\cs_ggen_sym:N\l_scratch_tlp{}
\tlp_gset:on \l_scratch_tlp {bar}

% and now we dump the whole rubbish. In the current implementation
% only csnames can be precompiled, perhaps registers should be handled
% similarly.
%
\cs_dump:

% and some int register to show something in the second LaTeX state
% dump.
%
\int_new:N\l_my_int
\int_set:Nn\l_my_int{42}
%
% as the allocation routines are not distributed we have to do this
% manually.
%
\register_record_name:N\l_my_int

\dumpLaTeXstate{test2}

% and changing something ... what happens with the LaTeX state?
%
\int_set:Nn\l_my_int{0}
\def:Npn\file_not_found:nTF#1#2#3{}

\dumpLaTeXstate{test3}

\CodeStop

\begin{document}

\LaTeX\ still works!

\end{document}