texprimitive.h /size: 4469 b    last modification: 2025-02-21 11:03
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    unsigned char destructors[number_tex_commands]; 
31} hash_state_info ;
32
33extern hash_state_info lmt_hash_state;
34
35/*tex
36
37    We use no defines as a |hash| macro will clash with lua hash. Most hash accessors are in a few
38    places where it makes sense to be explicit anyway.
39
40    The only reason why we have a dedicated primitive hash is because we can selectively enable 
41    them but at some point we might just always do that. There is never a runtiem lookup (asuming 
42    a format). It also gives is access to some primitive metadata. 
43
44*/
45
46# define cs_next(a) lmt_hash_state.hash[(a)].half0 /*tex link for coalesced lists */
47# define cs_text(a) lmt_hash_state.hash[(a)].half1 /*tex string number for control sequence name */
48
49# define undefined_primitive    0
50# define prim_size           2100 /*tex maximum number of primitives (quite a bit more than needed) */
51# define prim_prime          1777 /*tex about 85 percent of |primitive_size| */
52
53typedef struct primitive_info {
54    halfword   subids; /*tex number of name entries */
55    halfword   offset; /*tex offset to be used for |chr_code|s */
56    strnumber *names;  /*tex array of names */
57} prim_info;
58
59typedef struct primitive_state_info {
60    memoryword prim[prim_size + 1];
61    memoryword prim_eqtb[prim_size + 1];
62    prim_info  prim_data[last_cmd + 1];
63    halfword   prim_used;
64    /* alignment */
65    int        padding;
66} primitive_state_info;
67
68extern primitive_state_info lmt_primitive_state;
69
70# define prim_next(a)        lmt_primitive_state.prim[(a)].half0         /*tex Link for coalesced lists. */
71# define prim_text(a)        lmt_primitive_state.prim[(a)].half1         /*tex String number for control sequence name. */
72# define prim_origin(a)      lmt_primitive_state.prim_eqtb[(a)].quart01  /*tex Level of definition. */
73# define prim_eq_type(a)     lmt_primitive_state.prim_eqtb[(a)].quart00  /*tex Command code for equivalent. */
74# define prim_equiv(a)       lmt_primitive_state.prim_eqtb[(a)].half1    /*tex Equivalent value. */
75
76# define get_prim_eq_type(p) prim_eq_type(p)
77# define get_prim_equiv(p)   prim_equiv(p)
78# define get_prim_text(p)    prim_text(p)
79# define get_prim_origin(p)  prim_origin(p)
80
81extern void     tex_initialize_primitives (void);
82extern void     tex_initialize_hash_mem   (void);
83/*     int      tex_room_in_hash          (void); */
84extern halfword tex_prim_lookup           (strnumber s);
85/*     int      tex_cs_is_primitive       (strnumber csname); */
86extern void     tex_primitive             (int cmd_origin, const char *ss, singleword cmd, halfword chr, halfword offset);
87extern void     tex_primitive_def         (const char *str, size_t length, singleword cmd, halfword chr);
88extern void     tex_print_cmd_chr         (singleword cmd, halfword chr);
89extern void     tex_dump_primitives       (dumpstream f);
90extern void     tex_undump_primitives     (dumpstream f);
91extern void     tex_dump_hashtable        (dumpstream f);
92extern void     tex_undump_hashtable      (dumpstream f);
93/*     halfword tex_string_lookup         (const char *s, size_t l); */
94extern halfword tex_string_locate         (const char *s, size_t l, int create);
95extern halfword tex_string_locate_only    (const char *s, size_t l);
96extern halfword tex_located_string        (const char *s);
97/*     halfword tex_id_lookup             (int j, int l); */
98extern halfword tex_id_locate             (int j, int l, int create);
99extern halfword tex_id_locate_only        (int j, int l);
100extern int      tex_id_locate_steps       (const char *s);
101extern void     tex_print_cmd_flags       (halfword cs, halfword cmd, int flags, int escape);
102
103# endif
104