Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

open-axiom repository from github

24005 views
1
/*
2
Copyright (C) 2007-2014, Gabriel Dos Reis.
3
All rights reserved.
4
5
Redistribution and use in source and binary forms, with or without
6
modification, are permitted provided that the following conditions are
7
met:
8
9
- Redistributions of source code must retain the above copyright
10
notice, this list of conditions and the following disclaimer.
11
12
- Redistributions in binary form must reproduce the above copyright
13
notice, this list of conditions and the following disclaimer in
14
the documentation and/or other materials provided with the
15
distribution.
16
17
- Neither the name of The Numerical Algorithms Group Ltd. nor the
18
names of its contributors may be used to endorse or promote products
19
derived from this software without specific prior written permission.
20
21
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
25
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
*/
33
34
#ifndef OPENAXIOM_included
35
#define OPENAXIOM_included
36
37
#include <vector>
38
#include <string>
39
40
#include "openaxiom-c-macros.h"
41
42
/* Annotation to request C calling convention */
43
#ifdef __cplusplus
44
# define OPENAXIOM_C_CALL extern "C"
45
#else
46
# define OPENAXIOM_C_CALL
47
#endif
48
49
/* Cope with MS-platform oddities. */
50
#ifdef __WIN32__
51
# ifdef DLL_EXPORT
52
# define OPENAXIOM_EXPORT __declspec(dllexport)
53
# elif defined(DLL_IMPORT)
54
# define OPENAXIOM_EXPORT __declspec(dllimport)
55
# endif /* DLL_EXPORT */
56
# ifndef WIN32_LEAN_AND_MEAN
57
# define WIN32_LEAN_AND_MEAN
58
# endif
59
#endif /* __WIN32__ */
60
#ifndef OPENAXIOM_EXPORT
61
# define OPENAXIOM_EXPORT /* nothing */
62
#endif /* OPENAXIOM_EXPORT */
63
64
#define OPENAXIOM_C_EXPORT OPENAXIOM_C_CALL OPENAXIOM_EXPORT
65
66
#include <stdint.h>
67
68
#if defined(__WIN32__)
69
# include <windows.h>
70
#endif
71
#if defined(HAVE_UNISTD_H)
72
# include <unistd.h>
73
#endif
74
75
/* Do we have graphics support? */
76
#ifdef X_DISPLAY_MISSING
77
# define OPENAXIOM_HAVE_GRAPHICS 0
78
#else
79
# define OPENAXIOM_HAVE_GRAPHICS 1
80
#endif
81
82
namespace OpenAxiom {
83
// A name for the byte datatype.
84
typedef uint8_t Byte;
85
86
// An opaque datatype
87
#ifdef __WIN32__
88
typedef HANDLE Handle;
89
#else
90
typedef void* Handle;
91
#endif
92
93
// Data types for labeling positions and counting items.
94
using Ordinal = size_t;
95
using Cardinal = size_t;
96
97
// Byte order of machine word data.
98
enum class Byteorder {
99
unknown, little, big
100
};
101
102
// Datatype for packaging information necessary tolaunch a process.
103
struct Process {
104
int argc;
105
char** argv;
106
int id;
107
};
108
109
enum SpawnFlags {
110
search_path = 0x01,
111
replace = 0x02,
112
};
113
114
constexpr SpawnFlags
115
operator&(SpawnFlags x, SpawnFlags y) {
116
return SpawnFlags(int(x) & int(y));
117
}
118
119
constexpr SpawnFlags
120
operator|(SpawnFlags x, SpawnFlags y) {
121
return SpawnFlags(int(x) | int(y));
122
}
123
124
125
// Return the address of the byte array object representation of `t'.
126
template<typename T>
127
inline Byte* byte_address(T& t) {
128
return reinterpret_cast<Byte*>(&t);
129
}
130
131
/* Internal field separator character. */
132
#if defined(__WIN32__)
133
# define openaxiom_ifs ';'
134
#else
135
# define openaxiom_ifs ':'
136
#endif
137
138
/* Paths to LaTeX input support file directories.
139
These paths are relative to system directory. */
140
#define OPENAXIOM_TEXINPUTS_PATH "/share/texmf/tex"
141
#define OPENAXIOM_BIBINPUTS_PATH "/share/texmf/tex"
142
143
/* The function sleep() is not available under Windows. Instead, they
144
have Sleep(); with capital S, please. Furthermore, it does not
145
take argument in second, but in milliseconds, three order
146
of magnitude of difference when compared to the Unix world.
147
We abstract over that difference here. */
148
149
static inline void
150
openaxiom_sleep(int n)
151
{
152
#if defined(__WIN32__)
153
Sleep(n * 1000);
154
#else
155
sleep(n);
156
#endif
157
}
158
159
OPENAXIOM_C_EXPORT void oa_allocate_process_argv(Process*, int);
160
OPENAXIOM_C_EXPORT int oa_spawn(Process*, SpawnFlags);
161
OPENAXIOM_C_EXPORT const char* oa_concatenate_string(const char*, const char*);
162
163
// ------------
164
// -- Driver --
165
// ------------
166
// A list of drivers for OpenAxiom.
167
enum class Driver {
168
unknown, // unknown driver
169
null, // do nothing
170
config, // print out configuration information
171
sman, // start Superman as master process
172
gui, // start the GUI interface
173
core, // start the core system as master process
174
script, // start the core system in script mode.
175
compiler, // start the core system in compiler mode.
176
execute, // Execute a command.
177
translator, // Start the core system in translator mode.
178
linker // start the core system in linking mode.
179
};
180
181
// -------------
182
// -- Runtime --
183
// -------------
184
// A list of runtime support systems for OpenAxiom.
185
enum class Runtime {
186
unknown, // unknown runtime
187
gcl, // GCL-based runtime
188
sbcl, // SBCL-based runtime
189
clisp, // CLISP-based runtime
190
ecl, // ECL-based runtime
191
clozure, // Clozure CL-based runtime
192
bemol, // Bemol-based runtime
193
polyml // Poly/ML abstract machine-based runtime
194
};
195
196
// ---------------
197
// -- Arguments --
198
// ---------------
199
// Command line arguments.
200
// When non empty, this vector really is of length one more than
201
// what size() reports, as it is always null-terminated, to comply
202
// with POSIX-style operating system requirements.
203
struct Arguments : std::vector<char*> {
204
explicit Arguments(int n = 0);
205
int size() const;
206
void allocate(int);
207
char* const* data() const;
208
};
209
210
// -------------
211
// -- Command --
212
// -------------
213
// A description of external command to be executed.
214
struct Command {
215
Process core; // arguments for actual executable.
216
Arguments rt_args; // arguments to the base RT, if any.
217
const char* root_dir; // path to the OpenAxiom system.
218
const char* exec_path; // path to the program to execute.
219
Command();
220
};
221
222
// ----------------
223
// -- Filesystem --
224
// ----------------
225
// Basic interface to the OpenAxiom filesystem
226
struct Filesystem {
227
// Construct the basic filesystem from the OpenAxiom system
228
// directory. All other directories are derived from the root.
229
explicit Filesystem(const std::string&);
230
231
// The directory containing the core system
232
std::string sysdir() const;
233
234
// The directory containing algebra modules
235
std::string algdir() const;
236
237
// The directory containing database files.
238
std::string dbdir() const;
239
240
private:
241
const std::string root;
242
const std::string alg;
243
const std::string db;
244
};
245
246
// Return the path name the specified dabatase file.
247
std::string database_filepath(const Filesystem&, const std::string&);
248
249
250
const char* get_systemdir(int argc, char*[]);
251
const char* make_path_for(const char*, Driver);
252
253
// Return a pointer the string value associated with an option.
254
const char* option_value(const Command*, const char*);
255
256
int execute_core(const Command*, Driver);
257
void build_rts_options(Command*, Driver);
258
259
Driver preprocess_arguments(Command*, int, char**);
260
261
// Return the length of an array literal.
262
template<typename T, int N>
263
inline int length(T(&)[N]) {
264
return N;
265
}
266
}
267
268
#endif /* OPENAXIOM_included */
269
270
// Local Variables:
271
// mode: c++
272
// End:
273
274