1 /* primitive.h
2 
3    Copyright 2008-2009 Taco Hoekwater <taco@luatex.org>
4 
5    This file is part of LuaTeX.
6 
7    LuaTeX is free software; you can redistribute it and/or modify it under
8    the terms of the GNU General Public License as published by the Free
9    Software Foundation; either version 2 of the License, or (at your
10    option) any later version.
11 
12    LuaTeX is distributed in the hope that it will be useful, but WITHOUT
13    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
15    License for more details.
16 
17    You should have received a copy of the GNU General Public License along
18    with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
19 
20 
21 #ifndef LUATEX_PRIMITIVE_H
22 #  define LUATEX_PRIMITIVE_H 1
23 
24 /* This enum is a list of origins for primitive commands */
25 
26 typedef enum {
27     tex_command = 1,
28     etex_command = 2,
29     aleph_command = 4,
30     omega_command = 8,
31     pdftex_command = 16,
32     luatex_command = 32,
33     core_command = 64,
34     no_command = 128,
35     umath_command = 256,
36 } command_origin;
37 
38 #  define hash_size 65536       /* maximum number of control sequences; it should be at most about |(fix_mem_max-fix_mem_min)/10| */
39 
40 #  define hash_prime 55711      /* a prime number equal to about 85\pct! of |hash_size| */
41 
42 extern two_halves *hash;        /* the hash table */
43 extern halfword hash_used;      /* allocation pointer for |hash| */
44 extern int hash_extra;          /* |hash_extra=hash| above |eqtb_size| */
45 extern halfword hash_top;       /* maximum of the hash array */
46 extern halfword hash_high;      /* pointer to next high hash location */
47 extern boolean no_new_control_sequence; /* are new identifiers legal? */
48 extern int cs_count;            /* total number of known identifiers */
49 
50 #  define cs_next(a) hash[(a)].lhfield  /* link for coalesced lists */
51 #  define cs_text(a) hash[(a)].rh
52                                 /* string number for control sequence name */
53 
54 #  define undefined_primitive 0
55 #  define prim_size 2100        /* maximum number of primitives */
56 #  define prim_prime 1777       /* about 85\pct! of |primitive_size| */
57 
58 extern void init_primitives(void);
59 extern void ini_init_primitives(void);
60 
61 extern halfword compute_pool_hash(pool_pointer j, pool_pointer l,
62                                   halfword prime_number);
63 extern pointer prim_lookup(str_number s);
64 
65 extern boolean is_primitive(str_number csname);
66 
67 extern quarterword get_prim_eq_type(int p);
68 extern halfword get_prim_equiv(int p);
69 extern str_number get_prim_text(int p);
70 extern quarterword get_prim_origin(int p);
71 
72 extern void dump_primitives(void);
73 extern void undump_primitives(void);
74 
75 #  define primitive_tex(a,b,c,d)    primitive((a),(b),(c),(d),tex_command)
76 #  define primitive_etex(a,b,c,d)   primitive((a),(b),(c),(d),etex_command)
77 #  define primitive_aleph(a,b,c,d)  primitive((a),(b),(c),(d),aleph_command)
78 #  define primitive_omega(a,b,c,d)  primitive((a),(b),(c),(d),omega_command)
79 #  define primitive_pdftex(a,b,c,d) primitive((a),(b),(c),(d),pdftex_command)
80 #  define primitive_luatex(a,b,c,d) primitive((a),(b),(c),(d),luatex_command)
81 #  define primitive_umath(a,b,c,d)  primitive((a),(b),(c),(d),umath_command)
82 #  define primitive_core(a,b,c,d)   primitive((a),(b),(c),(d),core_command)
83 #  define primitive_no(a,b,c,d)     primitive((a),(b),(c),(d),no_command)
84 
85 extern void primitive(const char *ss, quarterword c, halfword o, halfword off,
86                       int cmd_origin);
87 extern void primitive_def(const char *s, size_t l, quarterword c, halfword o);
88 extern void print_cmd_chr(quarterword cmd, halfword chr_code);
89 
90 extern pointer string_lookup(const char *s, size_t l);
91 extern pointer id_lookup(int j, int l);
92 
93 #endif                          /* LUATEX_PRIMITIVE_H */
94