cfad47cfa3/tads3/vmbiftad.h

4b825dc642cb6eb9a060e54bf8d69288fbee4904cfad47cfa334b206c65f22086bcc5d63e6f70944
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
 *   Random number generator configuration.  Define one of the following
29
 *   configuration variables to select a random number generation
30
 *   algorithm:
31
 *   
32
 *   VMBIFTADS_RNG_LCG - linear congruential generator
33
 *.  VMBIFTADS_RNG_ISAAC - ISAAC (cryptographic hash generator) 
34
 */
35
36
/* use ISAAC */
37
#define VMBIFTADS_RNG_ISAAC
38
39
40
/* ------------------------------------------------------------------------ */
41
/*
42
 *   TADS function set built-in functions 
43
 */
44
class CVmBifTADS: public CVmBif
45
{
46
public:
47
    /*
48
     *   General functions 
49
     */
50
    static void datatype(VMG_ uint argc);
51
    static void getarg(VMG_ uint argc);
52
    static void firstobj(VMG_ uint argc);
53
    static void nextobj(VMG_ uint argc);
54
    static void randomize(VMG_ uint argc);
55
    static void rand(VMG_ uint argc);
56
    static void cvtstr(VMG_ uint argc);
57
    static void cvtnum(VMG_ uint argc);
58
    static void gettime(VMG_ uint argc);
59
    static void re_match(VMG_ uint argc);
60
    static void re_search(VMG_ uint argc);
61
    static void re_group(VMG_ uint argc);
62
    static void re_replace(VMG_ uint argc);
63
    static void savepoint(VMG_ uint argc);
64
    static void undo(VMG_ uint argc);
65
    static void save(VMG_ uint argc);
66
    static void restore(VMG_ uint argc);
67
    static void restart(VMG_ uint argc);
68
    static void get_max(VMG_ uint argc);
69
    static void get_min(VMG_ uint argc);
70
    static void make_string(VMG_ uint argc);
71
    static void get_func_params(VMG_ uint argc);
72
73
protected:
74
    /* enumerate objects (common handler for firstobj and nextobj) */
75
    static void enum_objects(VMG_ uint argc, vm_obj_id_t start_obj);
76
};
77
78
79
/* ------------------------------------------------------------------------ */
80
/*
81
 *   Global information for the TADS intrinsics.  We allocate this
82
 *   structure with the VM global variables - G_bif_tads_globals contains
83
 *   the structure.  
84
 */
85
class CVmBifTADSGlobals
86
{
87
public:
88
    /* creation */
89
    CVmBifTADSGlobals(VMG0_);
90
91
    /* deletion */
92
    ~CVmBifTADSGlobals();
93
94
    /* regular expression parser and searcher */
95
    class CRegexParser *rex_parser;
96
    class CRegexSearcherSimple *rex_searcher;
97
98
    /* 
99
     *   global variable for the last regular expression search string (we
100
     *   need to hold onto this because we might need to extract group-match
101
     *   substrings from it) 
102
     */
103
    struct vm_globalvar_t *last_rex_str;
104
105
    /* -------------------------------------------------------------------- */
106
    /*
107
     *   Linear Congruential Random Number Generator state 
108
     */
109
#ifdef VMBIFTADS_RNG_LCG
110
111
    /* linear congruential generator seed value */
112
    long rand_seed;
113
114
#endif /* VMBIFTADS_RNG_LCG */
115
116
    /* -------------------------------------------------------------------- */
117
    /*
118
     *   ISAAC Random Number Generator state
119
     */
120
#ifdef VMBIFTADS_RNG_ISAAC
121
122
    /* ISAAC state structure */
123
    struct isaacctx *isaac_ctx;
124
    
125
#endif /* VMBIFTADS_RNG_ISAAC */
126
};
127
128
/* ------------------------------------------------------------------------ */
129
/*
130
 *   ISAAC Random Number Generator definitions
131
 */
132
#ifdef VMBIFTADS_RNG_ISAAC
133
134
#define ISAAC_RANDSIZL   (8)
135
#define ISAAC_RANDSIZ    (1<<ISAAC_RANDSIZL)
136
137
struct isaacctx
138
{
139
    ulong cnt;
140
    ulong rsl[ISAAC_RANDSIZ];
141
    ulong mem[ISAAC_RANDSIZ];
142
    ulong a;
143
    ulong b;
144
    ulong c;
145
};
146
#endif /* VMBIFTADS_RNG_ISAAC */
147
148
/* end of section protected against multiple inclusion */
149
#endif /* VMBIFTAD_H */
150
151
152
/* ------------------------------------------------------------------------ */
153
/*
154
 *   TADS function set vector.  Define this only if VMBIF_DEFINE_VECTOR has
155
 *   been defined, so that this file can be included for the prototypes alone
156
 *   without defining the function vector.
157
 *   
158
 *   Note that this vector is specifically defined outside of the section of
159
 *   the file protected against multiple inclusion.  
160
 */
161
#ifdef VMBIF_DEFINE_VECTOR
162
163
/* TADS general data manipulation functions */
164
void (*G_bif_tadsgen[])(VMG_ uint) =
165
{
166
    &CVmBifTADS::datatype,
167
    &CVmBifTADS::getarg,
168
    &CVmBifTADS::firstobj,
169
    &CVmBifTADS::nextobj,
170
    &CVmBifTADS::randomize,
171
    &CVmBifTADS::rand,
172
    &CVmBifTADS::cvtstr,
173
    &CVmBifTADS::cvtnum,
174
    &CVmBifTADS::gettime,
175
    &CVmBifTADS::re_match,
176
    &CVmBifTADS::re_search,
177
    &CVmBifTADS::re_group,
178
    &CVmBifTADS::re_replace,
179
    &CVmBifTADS::savepoint,
180
    &CVmBifTADS::undo,
181
    &CVmBifTADS::save,
182
    &CVmBifTADS::restore,
183
    &CVmBifTADS::restart,
184
    &CVmBifTADS::get_max,
185
    &CVmBifTADS::get_min,
186
    &CVmBifTADS::make_string,
187
    &CVmBifTADS::get_func_params
188
};
189
190
#endif /* VMBIF_DEFINE_VECTOR */