texnesting.h /size: 3880 b    last modification: 2025-02-21 11:03
1/*
2    See license.txt in the root of this project.
3*/
4
5# ifndef LMT_NESTING_H
6# define LMT_NESTING_H
7
8/* 
9    Todo: make this record 6*4 smaller, not all are halfwords, although padding might then make us
10    end up with the same size. We also end up with plenty of casts elsewhere. 
11*/
12
13typedef struct list_state_record {
14    int      mode;                 // singleword 
15    halfword head;                 
16    halfword tail;                 
17    int      prev_graf;            
18    int      mode_line;            
19    halfword prev_depth;           // scaled
20    halfword space_factor;         
21    halfword direction_stack;      
22    int      math_dir;             // singleword 
23    int      math_style;           // singleword 
24    int      math_main_style;      // singleword 
25    int      math_parent_style;    // singleword 
26    int      math_scale;           
27    halfword math_flatten;         // singleword 
28    halfword math_begin;           // singleword 
29    halfword math_end;             // singleword 
30    halfword math_mode;            // singleword 
31    halfword delimiter;            // todo: get rid of these and use the stack 
32    halfword incomplete_noad;      // todo: get rid of these and use the stack 
33    int      options; 
34} list_state_record;
35
36typedef struct nest_state_info {
37    list_state_record *nest;
38    memory_data        nest_data;
39    int                shown_mode; // singleword
40    int                math_mode;  // singleword
41} nest_state_info;
42
43extern nest_state_info lmt_nest_state;
44
45# define cur_list lmt_nest_state.nest[lmt_nest_state.nest_data.ptr] /*tex The \quote {top} semantic state. */
46# define cur_mode (abs(cur_list.mode))
47
48extern void        tex_initialize_nest_state (void);
49/*     int         tex_room_on_nest_stack    (void); */
50extern void        tex_initialize_nesting    (void);
51extern void        tex_push_nest             (void);
52extern void        tex_pop_nest              (void);
53extern void        tex_tail_prepend          (halfword p);
54extern void        tex_tail_append           (halfword p);
55extern void        tex_tail_append_list      (halfword p);
56extern void        tex_tail_append_callback  (halfword p);
57extern halfword    tex_tail_fetch_callback   (void);
58extern halfword    tex_tail_apply_callback   (halfword p, halfword c);
59extern halfword    tex_pop_tail              (void);
60extern const char *tex_string_mode           (int m);
61extern void        tex_show_activities       (void);
62extern int         tex_vmode_nest_index      (void);
63
64/*tex
65    When we use a macro instead of a function we need to use an intermediate variable because |_p_|
66    can be a functioncall itself (something |new_*|). The gain is a little performance because this
67    one is called a lot. The loss is a bit larger binary. There are some more macros sensitive for
68    this, like the ones that couple nodes. Also, inlining a function can spoil this game!
69*/
70
71/*
72# define tail_append(_p_) do { \
73    halfword __p__ = _p_ ; \
74    tex_couple_nodes(cur_list.tail, __p__); \
75    cur_list.tail = __p__; \
76} while (0)
77*/
78
79/*
80# define tail_append tex_tail_append
81*/
82
83typedef enum mvl_options {
84    mvl_ignore_prev_depth = 0x0001,
85    mvl_no_prev_depth     = 0x0002,
86    mvl_discard_top       = 0x0004, 
87    mvl_discard_bottom    = 0x0008, 
88} mvl_options;
89
90typedef struct mvl_state_info {
91    list_state_record *mvl;
92    memory_data        mvl_data;
93    halfword           slot;
94} mvl_state_info;
95
96extern mvl_state_info  lmt_mvl_state;
97
98extern void     tex_initialize_mvl_state (void);
99extern void     tex_start_mvl            (void); /* includes scanning */
100extern void     tex_stop_mvl             (void);
101extern halfword tex_flush_mvl            (halfword n);
102extern int      tex_appended_mvl         (halfword context, halfword boundary);
103extern int      tex_current_mvl          (halfword *head, halfword *tail);
104
105# endif
106