texprimitive.h /size: 4351 b    last modification: 2024-01-16 10:22
1/*
2    See license.txt in the root of this project.
3*/
4
5# ifndef LMT_PRIMITIVE_H
6# define LMT_PRIMITIVE_H
7
8/*tex
9
10    This is a list of origins for primitive commands. The engine starts out with hardly anything
11    enabled so as a first step one should enable the \TEX\ primitives, and additional \ETEX\ and
12    \LUATEX\ primitives. Maybe at some moment we should just enable all by default.
13
14*/
15
16typedef enum command_origin {
17    tex_command    = 1,
18    etex_command   = 2,
19    luatex_command = 4,
20    no_command     = 8,
21} command_origin;
22
23typedef struct hash_state_info {
24    memoryword  *hash;       /*tex The hash table. */
25    memory_data  hash_data;
26    memoryword  *eqtb;       /*tex The equivalents table. */
27    memory_data  eqtb_data;
28    int          no_new_cs;  /*tex Are new identifiers legal? */
29    int          padding;
30} hash_state_info ;
31
32extern hash_state_info lmt_hash_state;
33
34/*tex
35
36    We use no defines as a |hash| macro will clash with lua hash. Most hash accessors are in a few
37    places where it makes sense to be explicit anyway.
38
39    The only reason why we have a dedicated primitive hash is because we can selectively enable 
40    them but at some point we might just always do that. There is never a runtiem lookup (asuming 
41    a format). It also gives is access to some primitive metadata. 
42
43*/
44
45# define cs_next(a) lmt_hash_state.hash[(a)].half0 /*tex link for coalesced lists */
46# define cs_text(a) lmt_hash_state.hash[(a)].half1 /*tex string number for control sequence name */
47
48# define undefined_primitive    0
49# define prim_size           2100 /*tex maximum number of primitives (quite a bit more than needed) */
50# define prim_prime          1777 /*tex about 85 percent of |primitive_size| */
51
52typedef struct primitive_info {
53    halfword   subids; /*tex number of name entries */
54    halfword   offset; /*tex offset to be used for |chr_code|s */
55    strnumber *names;  /*tex array of names */
56} prim_info;
57
58typedef struct primitive_state_info {
59    memoryword prim[prim_size + 1];
60    memoryword prim_eqtb[prim_size + 1];
61    prim_info  prim_data[last_cmd + 1];
62    halfword   prim_used;
63    /* alignment */
64    int        padding;
65} primitive_state_info;
66
67extern primitive_state_info lmt_primitive_state;
68
69# define prim_next(a)        lmt_primitive_state.prim[(a)].half0         /*tex Link for coalesced lists. */
70# define prim_text(a)        lmt_primitive_state.prim[(a)].half1         /*tex String number for control sequence name. */
71# define prim_origin(a)      lmt_primitive_state.prim_eqtb[(a)].quart01  /*tex Level of definition. */
72# define prim_eq_type(a)     lmt_primitive_state.prim_eqtb[(a)].quart00  /*tex Command code for equivalent. */
73# define prim_equiv(a)       lmt_primitive_state.prim_eqtb[(a)].half1    /*tex Equivalent value. */
74
75# define get_prim_eq_type(p) prim_eq_type(p)
76# define get_prim_equiv(p)   prim_equiv(p)
77# define get_prim_text(p)    prim_text(p)
78# define get_prim_origin(p)  prim_origin(p)
79
80extern void     tex_initialize_primitives (void);
81extern void     tex_initialize_hash_mem   (void);
82/*     int      tex_room_in_hash          (void); */
83extern halfword tex_prim_lookup           (strnumber s);
84/*     int      tex_cs_is_primitive       (strnumber csname); */
85extern void     tex_primitive             (int cmd_origin, const char *ss, singleword cmd, halfword chr, halfword offset);
86extern void     tex_primitive_def         (const char *str, size_t length, singleword cmd, halfword chr);
87extern void     tex_print_cmd_chr         (singleword cmd, halfword chr);
88extern void     tex_dump_primitives       (dumpstream f);
89extern void     tex_undump_primitives     (dumpstream f);
90extern void     tex_dump_hashtable        (dumpstream f);
91extern void     tex_undump_hashtable      (dumpstream f);
92/*     halfword tex_string_lookup         (const char *s, size_t l); */
93extern halfword tex_string_locate         (const char *s, size_t l, int create);
94extern halfword tex_string_locate_only    (const char *s, size_t l);
95extern halfword tex_located_string        (const char *s);
96/*     halfword tex_id_lookup             (int j, int l); */
97extern halfword tex_id_locate             (int j, int l, int create);
98extern halfword tex_id_locate_only        (int j, int l);
99extern void     tex_print_cmd_flags       (halfword cs, halfword cmd, int flags, int escape);
100
101# endif
102