Debian Codegraph @

terps/tads/tads3/vmbiftad.h

raw symbols SCIP
1 /*
2 * Copyright (c) 1998, 2002 Michael J. Roberts. All Rights Reserved.
3 *
4 * Please see the accompanying license file, LICENSE.TXT, for information
5 * on using and copying this software.
6 */
7 /*
8 Name
9 vmbiftad.h - function set definition - TADS function set
10 Function
11
12 Notes
13
14 Modified
15 12/06/98 MJRoberts - Creation
16 */
17
18 #ifndef VMBIFTAD_H
19 #define VMBIFTAD_H
20
21 #include "os.h"
22 #include "vmbif.h"
23 #include "utf8.h"
24
25
26 /* ------------------------------------------------------------------------ */
27 /*
28 * Include headers for our selectable Random Number Generator algorithms.
29 */
30 #include "vmisaac.h"
31 #include "vmmersenne.h"
32
33
34
35 /* ------------------------------------------------------------------------ */
36 /*
37 * TADS function set built-in functions
38 */
39 class CVmBifTADS: public CVmBif
40 {
41 public:
42 /* function vector */
43 static vm_bif_desc bif_table[];
44
45 /*
46 * General functions
47 */
48 static void datatype(VMG_ uint argc);
49 static void getarg(VMG_ uint argc);
50 static void firstobj(VMG_ uint argc);
51 static void nextobj(VMG_ uint argc);
52 static void randomize(VMG_ uint argc);
53 static void rand(VMG_ uint argc);
54 static void toString(VMG_ uint argc);
55 static void toInteger(VMG_ uint argc);
56 static void toNumber(VMG_ uint argc);
57 static void gettime(VMG_ uint argc);
58 static void re_match(VMG_ uint argc);
59 static void re_search(VMG_ uint argc);
60 static void re_group(VMG_ uint argc);
61 static void re_replace(VMG_ uint argc);
62 static void savepoint(VMG_ uint argc);
63 static void undo(VMG_ uint argc);
64 static void save(VMG_ uint argc);
65 static void restore(VMG_ uint argc);
66 static void restart(VMG_ uint argc);
67 static void get_max(VMG_ uint argc);
68 static void get_min(VMG_ uint argc);
69 static void make_string(VMG_ uint argc);
70 static void get_func_params(VMG_ uint argc);
71 static void sprintf(VMG_ uint argc);
72 static void make_list(VMG_ uint argc);
73 static void get_abs(VMG_ uint argc);
74 static void get_sgn(VMG_ uint argc);
75 static void concat(VMG_ uint argc);
76 static void re_search_back(VMG_ uint argc);
77
78 /* internal toString interface */
79 static void toString(VMG_ vm_val_t *retval, const vm_val_t *srcval,
80 int radix, int flags);
81
82 /* format a date-and-time list per getTime(GetDateAndTime) */
83 static vm_obj_id_t format_datetime_list(VMG_ os_time_t timer);
84
85 protected:
86 /* common handler for re_search() and re_search_back() */
87 template<int dir> inline static void re_search_common(VMG_ uint argc);
88
89 /* enumerate objects (common handler for firstobj and nextobj) */
90 static void enum_objects(VMG_ uint argc, vm_obj_id_t start_obj);
91
92 /* common handler for toInteger and toNumber */
93 static void toIntOrNum(VMG_ uint argc, int int_only);
94 };
95
96
97 /* ------------------------------------------------------------------------ */
98 /*
99 * Random Number Generator ID values for randomize(id, ...)
100 */
101 #define VMBT_RNGID_ISAAC 1
102 #define VMBT_RNGID_LCG 2
103 #define VMBT_RNGID_MT19937 3
104 #define VMBT_RNGID_BITSHIFT 4
105
106
107 /* ------------------------------------------------------------------------ */
108 /*
109 * Global information for the TADS intrinsics. We allocate this
110 * structure with the VM global variables - G_bif_tads_globals contains
111 * the structure.
112 */
113 class CVmBifTADSGlobals
114 {
115 public:
116 /* creation */
117 CVmBifTADSGlobals(VMG0_);
118
119 /* deletion */
120 ~CVmBifTADSGlobals();
121
122 /* regular expression parser and searcher */
123 class CRegexParser *rex_parser;
124 class CRegexSearcherSimple *rex_searcher;
125
126 /*
127 * global variable for the last regular expression search string (we
128 * need to hold onto this because we might need to extract group-match
129 * substrings from it)
130 */
131 struct vm_globalvar_t *last_rex_str;
132
133 /* the currently active RNG ID (VMBT_RNGID_xxx) */
134 int rng_id;
135
136 /* -------------------------------------------------------------------- */
137 /*
138 * Linear Congruential Random Number Generator state - this is just a
139 * 32-bit seed value.
140 */
141 int32_t lcg_rand_seed;
142
143 /* -------------------------------------------------------------------- */
144 /*
145 * Bit-Shift Random Number Generator state
146 */
147 #ifdef VMBIFTADS_RNG_BITSHIFT
148
149 /* bit-shift generator seed value */
150 int32_t bits_rand_seed;
151
152 #endif /* VMBIFTADS_RNG_BITSHIFT */
153
154 /* -------------------------------------------------------------------- */
155 /*
156 * ISAAC Random Number Generator state
157 */
158 struct isaacctx *isaac_ctx;
159
160
161 /* -------------------------------------------------------------------- */
162 /*
163 * Mersenne Twister MT19937 Random Number Generator state
164 */
165 class CVmMT19937 *mt_ctx;
166 };
167
168 /* end of section protected against multiple inclusion */
169 #endif /* VMBIFTAD_H */
170
171
172 /* ------------------------------------------------------------------------ */
173 /*
174 * TADS function set vector. Define this only if VMBIF_DEFINE_VECTOR has
175 * been defined, so that this file can be included for the prototypes alone
176 * without defining the function vector.
177 *
178 * Note that this vector is specifically defined outside of the section of
179 * the file protected against multiple inclusion.
180 */
181 #ifdef VMBIF_DEFINE_VECTOR
182
183 /* TADS general data manipulation functions */
184 vm_bif_desc CVmBifTADS::bif_table[] =
185 {
186 { &CVmBifTADS::datatype, 1, 0, FALSE }, /* 0 */
187 { &CVmBifTADS::getarg, 1, 0, FALSE }, /* 1 */
188 { &CVmBifTADS::firstobj, 0, 2, FALSE }, /* 2 */
189 { &CVmBifTADS::nextobj, 1, 2, FALSE }, /* 3 */
190 { &CVmBifTADS::randomize, 0, 0, FALSE }, /* 4 */
191 { &CVmBifTADS::rand, 0, 0, TRUE }, /* 5 */
192 { &CVmBifTADS::toString, 1, 2, FALSE }, /* 6 */
193 { &CVmBifTADS::toInteger, 1, 1, FALSE }, /* 7 */
194 { &CVmBifTADS::gettime, 0, 1, FALSE }, /* 8 */
195 { &CVmBifTADS::re_match, 2, 1, FALSE }, /* 9 */
196 { &CVmBifTADS::re_search, 2, 1, FALSE }, /* 10 */
197 { &CVmBifTADS::re_group, 1, 0, FALSE }, /* 11 */
198 { &CVmBifTADS::re_replace, 3, 2, FALSE }, /* 12 */
199 { &CVmBifTADS::savepoint, 0, 0, FALSE }, /* 13 */
200 { &CVmBifTADS::undo, 0, 0, FALSE }, /* 14 */
201 { &CVmBifTADS::save, 1, 0, FALSE }, /* 15 */
202 { &CVmBifTADS::restore, 1, 0, FALSE }, /* 16 */
203 { &CVmBifTADS::restart, 0, 0, FALSE }, /* 17 */
204 { &CVmBifTADS::get_max, 1, 0, TRUE }, /* 18 */
205 { &CVmBifTADS::get_min, 1, 0, TRUE }, /* 19 */
206 { &CVmBifTADS::make_string, 1, 1, FALSE }, /* 20 */
207 { &CVmBifTADS::get_func_params, 1, 0, FALSE }, /* 21 */
208 { &CVmBifTADS::toNumber, 1, 1, FALSE }, /* 23 */
209 { &CVmBifTADS::sprintf, 1, 0, TRUE }, /* 24 */
210 { &CVmBifTADS::make_list, 1, 1, FALSE }, /* 25 */
211 { &CVmBifTADS::get_abs, 1, 0, FALSE }, /* 26 */
212 { &CVmBifTADS::get_sgn, 1, 0, FALSE }, /* 27 */
213 { &CVmBifTADS::concat, 0, 0, TRUE }, /* 28 */
214 { &CVmBifTADS::re_search_back, 2, 1, FALSE } /* 29 */
215 };
216
217 #endif /* VMBIF_DEFINE_VECTOR */